[go: up one dir, main page]

DAL: add a read-only interface for KVS

What

Add a read-only mode for KVS

Why

For DAL snapshot feature, we want to access the store in read while a DAL node might be running, which is not possible with the current interface.

How

Move all the reading function in a separate submodule, include them in the interface and implementation.

The only addition is the Read.init function. The rest is just a matter of moving code in a submodule.

  let init ?lockfile ~lru_size root_dir =
    let open Lwt_result_syntax in
    let lockfile =
      match lockfile with
      | Some f -> f
      | None ->
          Filename.temp_file ((Unix.getpid () |> string_of_int) ^ ".") ".lock"
    in
    let*! () =
      if not (Sys.file_exists root_dir) then Lwt_utils_unix.create_dir root_dir
      else Lwt.return_unit
    in
    with_lockfile_lock lockfile @@ fun fd ->
    return {files = Files.init ~lru_size; root_dir; lockfile = fd}

Manually testing the MR

Try to call some write_ functions with a kvs opened with Read interface.

For instance:

diff --git a/src/lib_dal_node/single_value_store.ml b/src/lib_dal_node/single_value_store.ml
index a64122148e..a8658e03d6 100644
--- a/src/lib_dal_node/single_value_store.ml
+++ b/src/lib_dal_node/single_value_store.ml
@@ -31,9 +31,9 @@ module Make (Value : VALUE) : S with type value = Value.t = struct
 
   type value = Value.t
 
-  type nonrec t = (unit, unit, Value.t) KVS.t
+  type nonrec t = (unit, unit, Value.t) KVS.Read.t
 
-  let init ~root_dir : t tzresult Lwt.t = KVS.init ~lru_size:1 ~root_dir
+  let init ~root_dir : t tzresult Lwt.t = KVS.Read.init ~lru_size:1 root_dir
 
   let file_layout ~root_dir () =
     let filepath = Filename.concat root_dir Value.name in
@@ -47,11 +47,11 @@ module Make (Value : VALUE) : S with type value = Value.t = struct
 
   let load t =
     let open Lwt_result_syntax in
-    let* exists = KVS.value_exists t file_layout () () in
+    let* exists = KVS.Read.value_exists t file_layout () () in
     if exists then
-      let* res = KVS.read_value t file_layout () () in
+      let* res = KVS.Read.read_value t file_layout () () in
       return_some res
     else return_none
 
-  let save t value = KVS.write_value ~override:true t file_layout () () value
+  let save (t : t) value = KVS.write_value ~override:true t file_layout () () value
 end
$ make octez-dal-node
dune build   --profile=dev _build/install/default/bin/octez-dal-node
File "src/lib_dal_node/single_value_store.ml", line 56, characters 58-59:
56 |   let save (t : t) value = KVS.write_value ~override:true t file_layout () () value
                                                               ^
Error: The value t has type t = (unit, unit, value) KVS.Read.t
       but an expression was expected of type ('a, 'b, 'c) KVS.t
make: *** [Makefile:147: octez-dal-node] Error 1

Checklist

  • Document the interface of any function added or modified (see the coding guidelines)
  • Document any change to the user interface, including configuration parameters (see node configuration)
  • Provide automatic testing (see the testing guide).
  • For new features and bug fixes, add an item in the appropriate changelog (docs/protocols/alpha.rst for the protocol and the environment, CHANGES.rst at the root of the repository for everything else).
  • Select suitable reviewers using the Reviewers field below.
  • Select as Assignee the next person who should take action on that MR
Edited by Julien SAGOT

Merge request reports

Loading