@@ -77,15 +77,13 @@ struct
7777 let register_suffix_consumer t ~after_flush =
7878 t.suffix_consumers < - { after_flush } :: t.suffix_consumers
7979
80- let generation = function
81- | Payload. From_v1_v2_post_upgrade _ | Used_non_minimal_indexing_strategy
82- | No_gc_yet ->
83- 0
84- | T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9 | T10 | T11 | T12 | T13 | T14
85- | T15 ->
86- (* Unreachable *)
87- assert false
88- | Gced x -> x.generation
80+ let get_gced = function Payload. Gced x -> Some x | _ -> None
81+
82+ let generation payload =
83+ match get_gced payload with Some x -> x.generation | None -> 0
84+
85+ let mapping_size payload =
86+ match get_gced payload with Some x -> x.mapping_end_poff | None -> None
8987
9088 let notify_reload_consumers consumers =
9189 List. fold_left
@@ -215,20 +213,24 @@ struct
215213
216214 module Layout = Irmin_pack.Layout. V5
217215
218- let open_prefix ~root ~generation =
216+ let open_prefix ~root ~generation ~ mapping_size =
219217 let open Result_syntax in
220218 if generation = 0 then Ok None
221219 else
222220 let mapping = Layout. mapping ~generation ~root in
223221 let data = Layout. prefix ~root ~generation in
224- let * mapping_size = Io. size_of_path mapping in
222+ let * mapping_size =
223+ match mapping_size with
224+ | Some size -> Ok size
225+ | None -> Io. size_of_path mapping
226+ in
225227 let mapping_size = Int63. to_int mapping_size in
226228 let + prefix = Sparse. open_ro ~mapping_size ~mapping ~data in
227229 Some prefix
228230
229- let reopen_prefix t ~generation =
231+ let reopen_prefix t ~generation ~ mapping_size =
230232 let open Result_syntax in
231- let * some_prefix = open_prefix ~root: t.root ~generation in
233+ let * some_prefix = open_prefix ~root: t.root ~generation ~mapping_size in
232234 match some_prefix with
233235 | None -> Ok ()
234236 | Some _ ->
@@ -312,12 +314,12 @@ struct
312314 let use_fsync = Irmin_pack.Conf. use_fsync config in
313315 let indexing_strategy = Conf. indexing_strategy config in
314316 let pl : Payload.t = Control. payload control in
315- let generation =
317+ let generation, mapping_size =
316318 match pl.status with
317319 | From_v1_v2_post_upgrade _ | No_gc_yet
318320 | Used_non_minimal_indexing_strategy ->
319- 0
320- | Gced x -> x.generation
321+ ( 0 , None )
322+ | Gced x -> ( x.generation, x.mapping_end_poff)
321323 | T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9 | T10 | T11 | T12 | T13 | T14
322324 | T15 ->
323325 assert false
@@ -350,7 +352,7 @@ struct
350352 let cb _ = suffix_requires_a_flush_exn (get_instance () ) in
351353 make_suffix ~auto_flush_threshold ~auto_flush_procedure: (`External cb)
352354 in
353- let * prefix = open_prefix ~root ~generation in
355+ let * prefix = open_prefix ~root ~generation ~mapping_size in
354356 let * dict =
355357 let path = Layout. dict ~root in
356358 let auto_flush_threshold =
@@ -437,7 +439,10 @@ struct
437439 in
438440 (* Step 3.2. Potentially reload prefix *)
439441 let * () =
440- if gen0 = gen1 then Ok () else reopen_prefix t ~generation: gen1
442+ if gen0 = gen1 then Ok ()
443+ else
444+ reopen_prefix t ~generation: gen1
445+ ~mapping_size: (mapping_size pl1.status)
441446 in
442447 (* Step 3.3. Potentially reload lower *)
443448 if gen0 = gen1 && pl0.volume_num = pl1.volume_num then Ok ()
@@ -577,6 +582,7 @@ struct
577582 generation;
578583 latest_gc_target_offset = Int63. zero;
579584 suffix_dead_bytes = Int63. zero;
585+ mapping_end_poff = Some Int63. zero;
580586 };
581587 }
582588 in
@@ -768,7 +774,9 @@ struct
768774 Suffix. open_ro ~root ~appendable_chunk_poff ~start_idx ~chunk_num
769775 ~dead_header_size
770776 in
771- let * prefix = open_prefix ~root ~generation in
777+ let * prefix =
778+ open_prefix ~root ~generation ~mapping_size: (mapping_size status)
779+ in
772780 let * dict =
773781 let path = Layout. dict ~root in
774782 Dict. open_ro ~path ~end_poff: dict_end_poff ~dead_header_size
@@ -833,8 +841,8 @@ struct
833841 | `Unknown_major_pack_version _ ) as e ->
834842 e)
835843
836- let swap t ~generation ~suffix_start_offset ~ chunk_start_idx ~ chunk_num
837- ~suffix_dead_bytes ~latest_gc_target_offset ~volume =
844+ let swap t ~generation ~mapping_size ~ suffix_start_offset ~ chunk_start_idx
845+ ~chunk_num ~ suffix_dead_bytes ~latest_gc_target_offset ~volume =
838846 let open Result_syntax in
839847 [% log.debug
840848 " Gc in main: swap gen %d; suffix start %a; chunk start idx %d; chunk num \
@@ -845,7 +853,8 @@ struct
845853 let pl = Control. payload t.control in
846854
847855 (* Step 1. Reopen files *)
848- let * () = reopen_prefix t ~generation in
856+ let mapping_size = Some mapping_size in
857+ let * () = reopen_prefix t ~generation ~mapping_size in
849858 let * () =
850859 reopen_suffix t ~chunk_start_idx ~chunk_num
851860 ~appendable_chunk_poff: pl.appendable_chunk_poff
@@ -870,6 +879,7 @@ struct
870879 generation;
871880 latest_gc_target_offset;
872881 suffix_dead_bytes;
882+ mapping_end_poff = mapping_size;
873883 }
874884 in
875885
@@ -975,8 +985,7 @@ struct
975985 let lower = t.lower in
976986 cleanup ~root ~generation ~chunk_start_idx ~chunk_num ~lower
977987
978- let create_one_commit_store t config ~generation ~latest_gc_target_offset
979- ~suffix_start_offset commit_key =
988+ let create_one_commit_store t config gced commit_key =
980989 let open Result_syntax in
981990 let src_root = t.root in
982991 let dst_root = Irmin_pack.Conf. root config in
@@ -992,15 +1001,7 @@ struct
9921001 in
9931002 let * () = Suffix. close suffix in
9941003 (* Step 3. Create the control file and close it. *)
995- let status =
996- Payload. Gced
997- {
998- suffix_start_offset;
999- generation;
1000- latest_gc_target_offset;
1001- suffix_dead_bytes = Int63. zero;
1002- }
1003- in
1004+ let status = Payload. Gced gced in
10041005 let dict_end_poff = Io. size_of_path dst_dict |> Errs. raise_if_error in
10051006 let pl =
10061007 {
0 commit comments