Skip to content

Commit

Permalink
irmin-pack: replace suffix with chunked suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
metanivek committed Oct 13, 2022
1 parent e6d083b commit a602ce2
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 26 deletions.
6 changes: 5 additions & 1 deletion src/irmin-pack/unix/ext.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ module Maker (Config : Conf.S) = struct
module Errs = Io_errors.Make (Io)
module Control = Control_file.Make (Io)
module Aof = Append_only_file.Make (Io) (Errs)
module File_manager = File_manager.Make (Control) (Aof) (Aof) (Index) (Errs)
module Suffix = Chunked_suffix.Make (Io) (Errs)

module File_manager =
File_manager.Make (Control) (Aof) (Suffix) (Index) (Errs)

module Dict = Dict.Make (File_manager)
module Dispatcher = Dispatcher.Make (File_manager)
module XKey = Pack_key.Make (H)
Expand Down
33 changes: 15 additions & 18 deletions src/irmin-pack/unix/file_manager.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let legacy_io_header_size = 16
module Make
(Control : Control_file.S with module Io = Io.Unix)
(Dict : Append_only_file.S with module Io = Control.Io)
(Suffix : Append_only_file.S with module Io = Control.Io)
(Suffix : Chunked_suffix.S with module Io = Control.Io)
(Index : Pack_index.S)
(Errs : Io_errors.S with module Io = Control.Io) =
struct
Expand Down Expand Up @@ -240,20 +240,21 @@ struct
"reopen_suffix gen:%d end_poff:%d" generation (Int63.to_int end_poff)];
let readonly = Suffix.readonly t.suffix in
let* suffix1 =
let path =
Irmin_pack.Layout.V4.suffix_chunk ~root:t.root ~chunk_idx:generation
in
[%log.debug "reload: generation changed, opening %s" path];
if readonly then Suffix.open_ro ~path ~end_poff ~dead_header_size
let root = t.root in
let start_idx = generation in
let chunk_num = 1 in
[%log.debug "reload: generation changed, opening suffix"];
if readonly then
Suffix.open_ro ~root ~end_poff ~dead_header_size ~start_idx ~chunk_num
else
let auto_flush_threshold =
match Suffix.auto_flush_threshold t.suffix with
| None -> assert false
| Some x -> x
in
let cb _ = suffix_requires_a_flush_exn t in
Suffix.open_rw ~path ~end_poff ~dead_header_size ~auto_flush_threshold
~auto_flush_procedure:(`External cb)
Suffix.open_rw ~root ~end_poff ~dead_header_size ~start_idx ~chunk_num
~auto_flush_threshold ~auto_flush_procedure:(`External cb)
in
let suffix0 = t.suffix in
t.suffix <- suffix1;
Expand Down Expand Up @@ -325,14 +326,11 @@ struct
in
(* 2. Open the other files *)
let* suffix =
let path =
Irmin_pack.Layout.V4.suffix_chunk ~root ~chunk_idx:generation
in
let auto_flush_threshold =
Irmin_pack.Conf.suffix_auto_flush_threshold config
in
let cb _ = suffix_requires_a_flush_exn (get_instance ()) in
make_suffix ~path ~auto_flush_threshold
make_suffix ~start_idx:generation ~auto_flush_threshold
~auto_flush_procedure:(`External cb)
in
let* prefix =
Expand Down Expand Up @@ -457,7 +455,7 @@ struct
create_control_file ~overwrite config pl
in
let make_dict = Dict.create_rw ~overwrite in
let make_suffix = Suffix.create_rw ~overwrite in
let make_suffix = Suffix.create_rw ~root ~overwrite in
let make_index ~flush_callback ~readonly ~throttle ~log_size root =
(* [overwrite] is ignored for index *)
Index.v ~fresh:true ~flush_callback ~readonly ~throttle ~log_size root
Expand Down Expand Up @@ -488,7 +486,8 @@ struct
in
let make_dict = Dict.open_rw ~end_poff:pl.dict_end_poff ~dead_header_size in
let make_suffix =
Suffix.open_rw ~end_poff:pl.suffix_end_poff ~dead_header_size
Suffix.open_rw ~root ~end_poff:pl.suffix_end_poff ~chunk_num:1
~dead_header_size
in
let make_index ~flush_callback ~readonly ~throttle ~log_size root =
Index.v ~fresh:false ~flush_callback ~readonly ~throttle ~log_size root
Expand Down Expand Up @@ -604,10 +603,8 @@ struct
let generation = generation pl.status in
(* 2. Open the other files *)
let* suffix =
let path =
Irmin_pack.Layout.V4.suffix_chunk ~root ~chunk_idx:generation
in
Suffix.open_ro ~path ~end_poff:pl.suffix_end_poff ~dead_header_size
Suffix.open_ro ~root ~end_poff:pl.suffix_end_poff ~start_idx:generation
~chunk_num:1 ~dead_header_size
in
let* prefix =
let path = Irmin_pack.Layout.V4.prefix ~root ~generation in
Expand Down
4 changes: 2 additions & 2 deletions src/irmin-pack/unix/file_manager_intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module type S = sig
module Io : Io.S
module Control : Control_file.S with module Io = Io
module Dict : Append_only_file.S with module Io = Io
module Suffix : Append_only_file.S with module Io = Io
module Suffix : Chunked_suffix.S with module Io = Io
module Index : Pack_index.S
module Errs : Io_errors.S with module Io = Io
module Mapping_file : Mapping_file.S with module Io = Io
Expand Down Expand Up @@ -260,7 +260,7 @@ module type Sigs = sig
module Make
(Control : Control_file.S with module Io = Io.Unix)
(Dict : Append_only_file.S with module Io = Control.Io)
(Suffix : Append_only_file.S with module Io = Control.Io)
(Suffix : Chunked_suffix.S with module Io = Control.Io)
(Index : Pack_index.S)
(Errs : Io_errors.S with module Io = Control.Io) :
S
Expand Down
1 change: 1 addition & 0 deletions src/irmin-pack/unix/irmin_pack_unix.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module Errors = Errors
module Io_errors = Io_errors
module Control_file = Control_file
module Append_only_file = Append_only_file
module Chunked_suffix = Chunked_suffix
module File_manager = File_manager
module Maker = Ext.Maker
module Mapping_file = Mapping_file
Expand Down
4 changes: 2 additions & 2 deletions src/irmin-tezos-utils/files.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ module Make (Conf : Irmin_pack.Conf.S) (Schema : Irmin.Schema.Extended) = struct
module Errs = Irmin_pack_unix.Io_errors.Make (Io)
module Control_file = Irmin_pack_unix.Control_file.Make (Io)
module Append_only_file = Irmin_pack_unix.Append_only_file.Make (Io) (Errs)
module Suffix = Irmin_pack_unix.Chunked_suffix.Make (Io) (Errs)
module Pack_index = Irmin_pack_unix.Index.Make (Hash)

module File_manager =
Irmin_pack_unix.File_manager.Make (Control_file) (Append_only_file)
(Append_only_file)
Irmin_pack_unix.File_manager.Make (Control_file) (Append_only_file) (Suffix)
(Pack_index)
(Errs)

Expand Down
3 changes: 2 additions & 1 deletion test/irmin-pack/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ module Io = Irmin_pack_unix.Io.Unix
module Errs = Irmin_pack_unix.Io_errors.Make (Io)
module Control = Irmin_pack_unix.Control_file.Make (Io)
module Aof = Irmin_pack_unix.Append_only_file.Make (Io) (Errs)
module Suffix = Irmin_pack_unix.Chunked_suffix.Make (Io) (Errs)

module File_manager =
Irmin_pack_unix.File_manager.Make (Control) (Aof) (Aof) (Index) (Errs)
Irmin_pack_unix.File_manager.Make (Control) (Aof) (Suffix) (Index) (Errs)

module Dict = Irmin_pack_unix.Dict.Make (File_manager)
module Dispatcher = Irmin_pack_unix.Dispatcher.Make (File_manager)
Expand Down
3 changes: 2 additions & 1 deletion test/irmin-pack/test_inode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ struct
module Errs = Irmin_pack_unix.Io_errors.Make (Io)
module Control = Irmin_pack_unix.Control_file.Make (Io)
module Aof = Irmin_pack_unix.Append_only_file.Make (Io) (Errs)
module Suffix = Irmin_pack_unix.Chunked_suffix.Make (Io) (Errs)

module File_manager =
Irmin_pack_unix.File_manager.Make (Control) (Aof) (Aof) (Index) (Errs)
Irmin_pack_unix.File_manager.Make (Control) (Aof) (Suffix) (Index) (Errs)

module Dict = Irmin_pack_unix.Dict.Make (File_manager)
module Dispatcher = Irmin_pack_unix.Dispatcher.Make (File_manager)
Expand Down
3 changes: 2 additions & 1 deletion test/irmin-pack/test_pack_version_bump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ module Private = struct
module Errs = Irmin_pack_unix.Io_errors.Make (Io)
module Control = Irmin_pack_unix.Control_file.Make (Io)
module Aof = Irmin_pack_unix.Append_only_file.Make (Io) (Errs)
module Suffix = Irmin_pack_unix.Chunked_suffix.Make (Io) (Errs)

module File_manager =
Irmin_pack_unix.File_manager.Make (Control) (Aof) (Aof) (Index) (Errs)
Irmin_pack_unix.File_manager.Make (Control) (Aof) (Suffix) (Index) (Errs)
end

module Util = struct
Expand Down

0 comments on commit a602ce2

Please sign in to comment.