From 2bf252c5a68b16269ff2135df7e09bc9df657355 Mon Sep 17 00:00:00 2001 From: Bert De Jonghe Date: Wed, 24 May 2017 15:28:05 +0200 Subject: [PATCH 1/2] fixes #690 --- ocaml/src/alba_eviction.ml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ocaml/src/alba_eviction.ml b/ocaml/src/alba_eviction.ml index 8a310fda..2941780d 100644 --- a/ocaml/src/alba_eviction.ml +++ b/ocaml/src/alba_eviction.ml @@ -233,5 +233,10 @@ let lru_collect_some_garbage alba_client redis_client key = >>= fun sizes -> - R.zrem redis_client key items >>= fun _ -> - Lwt.return (List.fold_left Int64.add 0L sizes) + (if List.length items > 0 + then + R.zrem redis_client key items + else + Lwt.return 0) + + >>= fun _ -> Lwt.return (List.fold_left Int64.add 0L sizes) From 6e5186dbcf3b52026e4a5183d537069d7133322a Mon Sep 17 00:00:00 2001 From: Bert De Jonghe Date: Fri, 26 May 2017 16:40:47 +0200 Subject: [PATCH 2/2] prevent spinning fast if no work found; fallback to random eviction if it takes too long --- ocaml/src/maintenance.ml | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/ocaml/src/maintenance.ml b/ocaml/src/maintenance.ml index 9f8f1f46..dbe5af1a 100644 --- a/ocaml/src/maintenance.ml +++ b/ocaml/src/maintenance.ml @@ -2091,7 +2091,7 @@ class client ?(retry_timeout = 60.) let percentage = percentage_from_fill_ratio fill_ratio in (* collect precentage of objects *) let target = Int64.div total_disk_size 100L |> Int64.mul percentage in - let rec inner acc = + let rec inner acc retrycnt = if acc > target then Lwt.return () else @@ -2100,10 +2100,29 @@ class client ?(retry_timeout = 60.) alba_client client key >>= fun size -> - inner (Int64.add acc size) + if size > 0L + then + (* part of the job done, try to do more *) + inner (Int64.add acc size) 0 + else + let retrycnt = retrycnt + 1 in + if retrycnt >= 5 + then + begin + Lwt_log.info + "redis based lru eviction has too many retries, fallback to random" + >>= fun () -> + do_random_eviction fill_ratio + end + else + begin + (* wait a little here to increase chance to have work *) + Lwt_unix.sleep 1. >>= fun () -> + inner (Int64.add acc size) retrycnt + end end in - inner 0L) + inner 0L 0) ) (fun exn -> Lwt_log.info_f