aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/Storage.ml
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/kernel/Storage.ml36
-rw-r--r--lib/kernel/Storage.mli28
2 files changed, 39 insertions, 25 deletions
diff --git a/lib/kernel/Storage.ml b/lib/kernel/Storage.ml
index d50735c..da438d2 100644
--- a/lib/kernel/Storage.ml
+++ b/lib/kernel/Storage.ml
@@ -1,14 +1,13 @@
module Make (S : Abstract.Storage.STORAGE) = struct
module Pointer = struct
- type 'a t = {
- addr : S.address;
- loader : S.transaction -> S.address -> ('a, Concepts.Condition.condition) result
- }
-
- let make loader addr = { addr; loader }
- let address_of { addr; _ } = addr
- let swap { loader; _ } addr = make loader addr
- let deref tx { addr; loader } = loader tx addr
+ type 'a t =
+ { addr: S.address;
+ loader: S.transaction -> S.address -> ('a, Concepts.Condition.condition) result }
+
+ let make loader addr = {addr; loader}
+ let address_of {addr; _} = addr
+ let swap {loader; _} addr = make loader addr
+ let deref tx {addr; loader} = loader tx addr
end
let as_hash = function
@@ -16,25 +15,26 @@ module Make (S : Abstract.Storage.STORAGE) = struct
| _ -> failwith "A label was provided where a hash was expected."
let to_hum_string = function
- | S.Hash h -> "Hash " ^ (Concepts.Hash.to_hum_string h)
+ | S.Hash h -> "Hash " ^ Concepts.Hash.to_hum_string h
| S.Label l -> "Label " ^ l
module Error = struct
open Concepts.Condition
let missing_data addr =
- condition "missing-data" "An expected value was not found on the underlying storage. Is your database corrupted?"
+ condition "missing-data"
+ "An expected value was not found on the underlying storage. Is your database corrupted?"
("address" |=| Concepts.Value.String (to_hum_string addr))
end
let finish tx = function
| Ok value ->
- let open Utilities.Result in
- let* () = S.commit tx in
- Ok value
+ let open Utilities.Result in
+ let* () = S.commit tx in
+ Ok value
| Error condition ->
- let _ = S.abort tx in
- Error condition
+ let _ = S.abort tx in
+ Error condition
let within start connection body =
let open Utilities.Result in
@@ -51,7 +51,5 @@ module Make (S : Abstract.Storage.STORAGE) = struct
Ok address
let get_req tx addr =
- S.get tx addr
- |> Utilities.Result.fmap (Option.to_result ~none:(Error.missing_data addr))
-
+ S.get tx addr |> Utilities.Result.fmap (Option.to_result ~none:(Error.missing_data addr))
end
diff --git a/lib/kernel/Storage.mli b/lib/kernel/Storage.mli
index 53bb666..92f602d 100644
--- a/lib/kernel/Storage.mli
+++ b/lib/kernel/Storage.mli
@@ -2,7 +2,9 @@ module Make : functor (S : Abstract.Storage.STORAGE) -> sig
module Pointer : sig
type 'a t
- val make : (S.transaction -> S.address -> ('a, Concepts.Condition.condition) result) -> S.address -> 'a t
+ val make :
+ (S.transaction -> S.address -> ('a, Concepts.Condition.condition) result) -> S.address -> 'a t
+
val address_of : 'a t -> S.address
val swap : 'a t -> S.address -> 'a t
val deref : S.transaction -> 'a t -> ('a, Concepts.Condition.condition) result
@@ -10,9 +12,23 @@ module Make : functor (S : Abstract.Storage.STORAGE) -> sig
val as_hash : S.address -> Concepts.Hash.hash
- val finish : S.transaction -> ('a, Concepts.Condition.condition) result -> ('a, Concepts.Condition.condition) result
- val with_transaction : S.connection -> (S.transaction -> ('a, Concepts.Condition.condition) result) -> ('a, Concepts.Condition.condition) result
- val with_read : S.connection -> (S.transaction -> ('a, Concepts.Condition.condition) result) -> ('a, Concepts.Condition.condition) result
- val store_blob : S.transaction -> Concepts.Blob.t -> (Concepts.Hash.hash, Concepts.Condition.condition) result
- val get_req: S.transaction -> S.address -> (Concepts.Blob.t, Concepts.Condition.condition) result
+ val finish :
+ S.transaction ->
+ ('a, Concepts.Condition.condition) result ->
+ ('a, Concepts.Condition.condition) result
+
+ val with_transaction :
+ S.connection ->
+ (S.transaction -> ('a, Concepts.Condition.condition) result) ->
+ ('a, Concepts.Condition.condition) result
+
+ val with_read :
+ S.connection ->
+ (S.transaction -> ('a, Concepts.Condition.condition) result) ->
+ ('a, Concepts.Condition.condition) result
+
+ val store_blob :
+ S.transaction -> Concepts.Blob.t -> (Concepts.Hash.hash, Concepts.Condition.condition) result
+
+ val get_req : S.transaction -> S.address -> (Concepts.Blob.t, Concepts.Condition.condition) result
end