Skip to content

Commit

Permalink
fixup! CP-52226 - oxenstored: Implement partial directory call for do…
Browse files Browse the repository at this point in the history
…m0 with per-connection cache
  • Loading branch information
last-genius committed Dec 5, 2024
1 parent 43196e3 commit 7b90ff6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
7 changes: 7 additions & 0 deletions oxenstored/connection.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions oxenstored/process.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 8 additions & 12 deletions oxenstored/transaction.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 ;
Expand Down

0 comments on commit 7b90ff6

Please sign in to comment.