From 7b90ff6ab13d8b20e5811ffa64647feedb17b9bf Mon Sep 17 00:00:00 2001 From: Andrii Sultanov Date: Thu, 5 Dec 2024 08:37:27 +0000 Subject: [PATCH] fixup! CP-52226 - oxenstored: Implement partial directory call for dom0 with per-connection cache --- oxenstored/connection.ml | 7 +++++++ oxenstored/process.ml | 1 + oxenstored/transaction.ml | 20 ++++++++------------ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/oxenstored/connection.ml b/oxenstored/connection.ml index 71f4ee2..4ec2668 100644 --- a/oxenstored/connection.ml +++ b/oxenstored/connection.ml @@ -103,6 +103,9 @@ and t = { xb: Xenbus.Xb.t ; dom: Domain.t option ; transactions: (int, Transaction.t) Hashtbl.t + ; directory_cache_gen_count: int64 ref + (* Used to provide connection-unique generation counts in case a cache entry + was evicted and TODO *) ; directory_cache: (Store.Path.t, Store.Node.t * int64 * string * float) Hashtbl.t option (* Used for partial_directory calls, maps @@ -239,6 +242,10 @@ let create xbcon dom = xb= xbcon ; dom ; transactions= Hashtbl.create 5 + ; directory_cache_gen_count= + ref 1L + (* Start the generation count with 1, since 0 is a special + NULL value in CXenstored *) ; directory_cache ; next_tid= initial_next_tid ; watches= Hashtbl.create 8 diff --git a/oxenstored/process.ml b/oxenstored/process.ml index 53d4598..2b2c749 100644 --- a/oxenstored/process.ml +++ b/oxenstored/process.ml @@ -362,6 +362,7 @@ let do_directory_part con t _domains _cons data = let generation, children = Transaction.ls_partial t (Connection.get_perm con) path directory_cache + con.Connection.directory_cache_gen_count in let generation_s = Printf.sprintf "%Ld\000" generation in diff --git a/oxenstored/transaction.ml b/oxenstored/transaction.ml index 7fdbd33..1235287 100644 --- a/oxenstored/transaction.ml +++ b/oxenstored/transaction.ml @@ -222,7 +222,7 @@ let ls t perm path = let _node, r = Store.ls t.store perm path in set_read_lowpath t path ; r -let ls_partial t perm path directory_cache = +let ls_partial t perm path directory_cache max_gen_count = let configurable_cache_size = 8 in let check_hashtable_bounds ht = if Hashtbl.length ht >= configurable_cache_size then @@ -239,6 +239,12 @@ let ls_partial t perm path directory_cache = Hashtbl.remove ht (Option.get key) in + let inc_gen_count gen_cnt = + let r = !gen_cnt in + gen_cnt := Int64.add !gen_cnt 1L ; + r + in + (* Return the cached buffer if the node hasn't changed; otherwise create or refresh the cache *) let ( let* ) = Option.bind in @@ -268,17 +274,7 @@ let ls_partial t perm path directory_cache = else "" in - (* We need to increment the generation count if the cache existed - but needed to be refreshed *) - let generation_count = - match cache_opt with - | Some (_, generation_count, _, _) -> - Int64.add generation_count 1L - | None -> - 1L - (* Start the generation count with 1, since 0 is a special - NULL value in CXenstored *) - in + let generation_count = inc_gen_count max_gen_count in (* Check the bounds, evict something from the hashtable to keep its size bounded *) check_hashtable_bounds directory_cache ;