···4455type with_missing = {blocks: t; missing: Cid.t list}
6677-let empty = Cid_map.empty
77+let empty : t = Cid_map.empty
8899let add value m =
1010 let cid, bytes = Lex.to_cbor_block value in
+23
mist/lib/storage/blockstore.ml
···11+module type Readable = sig
22+ type t
33+44+ val get_bytes : t -> Cid.t -> bytes option Lwt.t
55+66+ val has : t -> Cid.t -> bool Lwt.t
77+88+ val get_blocks : t -> Cid.t list -> Block_map.with_missing Lwt.t
99+end
1010+1111+module type Writable = sig
1212+ type t
1313+1414+ include Readable with type t := t
1515+1616+ val put_block : t -> Cid.t -> bytes -> unit Lwt.t
1717+1818+ val put_many : t -> Block_map.t -> unit Lwt.t
1919+2020+ val delete_block : t -> Cid.t -> unit Lwt.t
2121+2222+ val delete_many : t -> Cid.t list -> unit Lwt.t
2323+end
+30
mist/lib/storage/memory_blockstore.ml
···11+module Make () = struct
22+ type t = {mutable blocks: Block_map.t}
33+44+ let create ?(blocks = Block_map.empty) () = {blocks}
55+66+ let get_bytes s cid = Lwt.return (Block_map.get cid s.blocks)
77+88+ let has s cid = Lwt.return (Block_map.has cid s.blocks)
99+1010+ let get_blocks s cids = Lwt.return (Block_map.get_many cids s.blocks)
1111+1212+ let put_block s cid bytes =
1313+ s.blocks <- Block_map.set cid bytes s.blocks ;
1414+ Lwt.return_unit
1515+1616+ let put_many s blocks =
1717+ s.blocks <- Block_map.merge s.blocks blocks ;
1818+ Lwt.return_unit
1919+2020+ let delete_block s cid =
2121+ s.blocks <- Block_map.remove cid s.blocks ;
2222+ Lwt.return_unit
2323+2424+ let delete_many s cids =
2525+ s.blocks <-
2626+ List.fold_left
2727+ (fun blocks cid -> Block_map.remove cid blocks)
2828+ s.blocks cids ;
2929+ Lwt.return_unit
3030+end
-45
mist/lib/storage/memory_store.ml
···11-module Make () = struct
22- type t =
33- { mutable blocks: Block_map.t
44- ; mutable root: Cid.t option
55- ; mutable rev: string option }
66-77- let create ?(blocks = Block_map.empty) () = {blocks; root= None; rev= None}
88-99- let get_root s =
1010- match s.root with
1111- | Some root ->
1212- Lwt.return_some root
1313- | None ->
1414- Lwt.return_none
1515-1616- let get_bytes s cid = Lwt.return (Block_map.get cid s.blocks)
1717-1818- let has s cid = Lwt.return (Block_map.has cid s.blocks)
1919-2020- let get_blocks s cids = Lwt.return (Block_map.get_many cids s.blocks)
2121-2222- let put_block s ?rev cid bytes =
2323- s.blocks <- Block_map.set cid bytes s.blocks ;
2424- s.rev <- rev ;
2525- Lwt.return_unit
2626-2727- let put_many s blocks =
2828- s.blocks <- Block_map.merge s.blocks blocks ;
2929- Lwt.return_unit
3030-3131- let update_root s ?rev cid =
3232- s.root <- Some cid ;
3333- s.rev <- rev ;
3434- Lwt.return_unit
3535-3636- let apply_commit s (c : Repo_store.commit_data) =
3737- let with_removed =
3838- Cid.Set.fold
3939- (fun cid blocks -> Block_map.remove cid blocks)
4040- c.removed_cids s.blocks
4141- in
4242- s.blocks <- Block_map.merge with_removed c.relevant_blocks ;
4343- s.root <- Some c.cid ;
4444- Lwt.return_unit
4545-end
···11-let ( let* ) = Lwt.bind
22-33-module Make (Top : Repo_store.Readable) (Bottom : Repo_store.Readable) : sig
44- include Repo_store.Readable
11+module Make (Top : Blockstore.Readable) (Bottom : Blockstore.Readable) : sig
22+ include Blockstore.Readable
5364 val create : Top.t -> Bottom.t -> t
75end = struct
···97108 let create top bottom = {top; bottom}
1191212- let get_root {top; bottom} =
1313- match%lwt Top.get_root top with
1414- | Some _ as res ->
1515- Lwt.return res
1616- | None ->
1717- Bottom.get_root bottom
1818-1910 let get_bytes {top; bottom} cid =
2011 match%lwt Top.get_bytes top cid with
2112 | Some _ as res ->
···3122 Bottom.has bottom cid
32233324 let get_blocks {top; bottom} cids =
3434- let* from_top = Top.get_blocks top cids in
3535- let* from_bottom = Bottom.get_blocks bottom from_top.missing in
2525+ let%lwt from_top = Top.get_blocks top cids in
2626+ let%lwt from_bottom = Bottom.get_blocks bottom from_top.missing in
3627 let merged_blocks = Block_map.merge from_top.blocks from_bottom.blocks in
3728 Lwt.return {Block_map.blocks= merged_blocks; missing= from_bottom.missing}
3829end
-33
mist/lib/storage/repo_store.ml
···11-type commit_data =
22- { cid: Cid.t
33- ; rev: string
44- ; since: string option
55- ; prev: Cid.t option
66- ; relevant_blocks: Block_map.t
77- ; removed_cids: Cid.Set.t }
88-99-module type Readable = sig
1010- type t
1111-1212- val get_root : t -> Cid.t option Lwt.t
1313-1414- val get_bytes : t -> Cid.t -> bytes option Lwt.t
1515-1616- val has : t -> Cid.t -> bool Lwt.t
1717-1818- val get_blocks : t -> Cid.t list -> Block_map.with_missing Lwt.t
1919-end
2020-2121-module type Writable = sig
2222- type t
2323-2424- include Readable with type t := t
2525-2626- val put_block : t -> ?rev:string -> Cid.t -> bytes -> unit Lwt.t
2727-2828- val put_many : t -> Block_map.t -> unit Lwt.t
2929-3030- val update_root : t -> ?rev:string -> Cid.t -> unit Lwt.t
3131-3232- val apply_commit : t -> commit_data -> unit Lwt.t
3333-end
+9-11
mist/lib/storage/storage.ml
···11module Block_map = Block_map
22module Blob_store = Blob_store
3344-module type Readable_blockstore = Repo_store.Readable
44+module type Readable_blockstore = Blockstore.Readable
5566-module type Writable_blockstore = Repo_store.Writable
66+module type Writable_blockstore = Blockstore.Writable
7788module Memory_blockstore = struct
99- module Impl = Memory_store.Make ()
99+ module Impl = Memory_blockstore.Make ()
1010 include Impl
11111212- module Readable : Repo_store.Readable with type t = Impl.t = Impl
1212+ module Readable : Blockstore.Readable with type t = Impl.t = Impl
13131414- module Writable : Repo_store.Writable with type t = Impl.t = Impl
1414+ module Writable : Blockstore.Writable with type t = Impl.t = Impl
1515end
16161717module Overlay_blockstore
1818- (Top : Repo_store.Readable)
1919- (Bottom : Repo_store.Readable) =
1818+ (Top : Blockstore.Readable)
1919+ (Bottom : Blockstore.Readable) =
2020struct
2121- module Impl = Overlay_store.Make (Top) (Bottom)
2121+ module Impl = Overlay_blockstore.Make (Top) (Bottom)
2222 include Impl
23232424- module Readable : Repo_store.Readable with type t = Impl.t = Impl
2424+ module Readable : Blockstore.Readable with type t = Impl.t = Impl
2525end
2626-2727-type commit_data = Repo_store.commit_data