Skip to content

Commit

Permalink
irmin-pack: fix Dict usages
Browse files Browse the repository at this point in the history
  • Loading branch information
art-w committed Apr 7, 2023
1 parent 5147693 commit 73cc593
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 36 deletions.
10 changes: 2 additions & 8 deletions examples/irmin-pack/gc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ module Repo_config = struct
(** Must use minimal indexing strategy to use GC *)
let indexing_strategy = Irmin_pack.Indexing_strategy.minimal

(** Buffer size that triggers auto flushing to disk *)
let dict_auto_flush_threshold = 1_000_000

(** Buffer size that triggers auto flushing to disk *)
let suffix_auto_flush_threshold = 1_000_000

(** Location on disk to save the repository
Note: irmin-pack will not create the entire path, only the final directory *)
Expand All @@ -81,7 +75,7 @@ module Repo_config = struct
(** Create config for our repository *)
let config =
Irmin_pack.config ~fresh ~index_log_size ~merge_throttle ~indexing_strategy
~dict_auto_flush_threshold ~suffix_auto_flush_threshold root
root

(** We can add an optional lower layer to our repository. Data discarded by
the GC will be stored there and still be accessible instead of being
Expand All @@ -91,7 +85,7 @@ module Repo_config = struct
(** Create a copy of the previous configuration, now with a lower layer *)
let config_with_lower =
Irmin_pack.config ~fresh ~index_log_size ~merge_throttle ~indexing_strategy
~dict_auto_flush_threshold ~suffix_auto_flush_threshold ~lower_root root
~lower_root root
end

(** Utility for creating commit info *)
Expand Down
8 changes: 1 addition & 7 deletions examples/irmin-pack/kv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ module Repo_config = struct
(** Must use minimal indexing strategy to use GC *)
let indexing_strategy = Irmin_pack.Indexing_strategy.minimal

(** Buffer size that triggers auto flushing to disk *)
let dict_auto_flush_threshold = 1_000_000

(** Buffer size that triggers auto flushing to disk *)
let suffix_auto_flush_threshold = 1_000_000

(** Location on disk to save the repository
Note: irmin-pack will not create the entire path, only the final directory *)
Expand All @@ -71,7 +65,7 @@ module Repo_config = struct
(** Create config for our repository *)
let config =
Irmin_pack.config ~fresh ~index_log_size ~merge_throttle ~indexing_strategy
~dict_auto_flush_threshold ~suffix_auto_flush_threshold root
root
end

module StoreMaker = Irmin_pack_unix.KV (Conf)
Expand Down
18 changes: 0 additions & 18 deletions src/irmin-pack-tools/tezos_explorer/files.ml
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,4 @@ module Make (Conf : Irmin_pack.Conf.S) (Schema : Irmin.Schema.Extended) = struct
traverse next_off
in
traverse Int63.zero

let rec traverse_dict dict size buffer off acc =
if off < size then (
File_manager.Dict.read_exn dict buffer ~off ~len:4;
let len = Int32.to_int @@ Bytes.get_int32_be buffer 0 in
let off = Int63.(add off (of_int 4)) in
File_manager.Dict.read_exn dict buffer ~off ~len;
let str = Bytes.sub_string buffer 0 len in
let acc = str :: acc in
let off = Int63.(add off (of_int len)) in
traverse_dict dict size buffer off acc)
else acc

let load_dict (dict : File_manager.Dict.t) buffer =
let max_offset = File_manager.Dict.end_poff dict in
let off = Int63.zero in
let dict = traverse_dict dict max_offset buffer off [] in
List.rev dict
end
5 changes: 2 additions & 3 deletions src/irmin-pack-tools/tezos_explorer/show.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type context = {
idxs : idxs list;
fm : Files.File_manager.t;
dispatcher : Files.Dispatcher.t;
dict : string list;
dict : Files.File_manager.Dict.t;
max_entry : int;
max_offset : Int63.t;
history : history Ring.t;
Expand Down Expand Up @@ -546,7 +546,7 @@ let show_inode c (inode : Files.Inode.compress) =
let name (n : Files.Inode.Compress.name) =
match n with
| Indirect dict_key ->
let key = List.nth_opt c.dict dict_key in
let key = Files.File_manager.Dict.find c.dict dict_key in
strf
~attr:A.(fg lightwhite ++ st bold)
"Indirect key: \'%a\' (%#d)" (Fmt.option Fmt.string) key dict_key
Expand Down Expand Up @@ -860,7 +860,6 @@ let main store_path info_last_path info_next_path index_path =
let dispatcher = Files.Dispatcher.v fm |> Files.Errs.raise_if_error in
let max_offset = Files.Dispatcher.end_offset dispatcher in
let dict = Files.File_manager.dict fm in
let dict = Files.load_dict dict buffer in
let info_last_fd =
Unix.openfile info_last_path Unix.[ O_RDONLY; O_CLOEXEC ] 0o644
in
Expand Down

0 comments on commit 73cc593

Please sign in to comment.