453
453
-record (seg_info ,
454
454
{file :: file :filename_all (),
455
455
size = 0 :: non_neg_integer (),
456
+ chunks = 0 :: non_neg_integer (),
456
457
index :: file :filename_all (),
457
458
first :: undefined | # chunk_info {},
458
459
last :: undefined | # chunk_info {}}).
@@ -570,6 +571,7 @@ init(#{dir := Dir,
570
571
timestamp = FstTs }},
571
572
last := #{file := Filename ,
572
573
size := Size ,
574
+ chunks := NumChunks ,
573
575
last := # chunk_info {epoch = LastEpoch ,
574
576
timestamp = LastTs ,
575
577
id = LastChId ,
@@ -603,7 +605,6 @@ init(#{dir := Dir,
603
605
ok = file :truncate (SegFd ),
604
606
Event = {segment_opened , undefined , Filename },
605
607
Manifest = ManifestMod :handle_event (Event , Manifest0 ),
606
- NumChunks = LastChId - FstChId ,
607
608
#? MODULE {cfg = Cfg ,
608
609
mode =
609
610
# write {type = WriterType ,
@@ -655,18 +656,22 @@ writer_manifest(#{dir := Dir} = Config) ->
655
656
{SegmentOffsets ,
656
657
# seg_info {file = FirstFile ,
657
658
size = FirstSize ,
659
+ chunks = FirstNumChunks ,
658
660
first = FirstFirstChunk ,
659
661
last = FirstLastChunk },
660
662
# seg_info {file = LastFile ,
661
663
size = LastSize ,
664
+ chunks = LastNumChunks ,
662
665
first = LastFirstChunk ,
663
666
last = # chunk_info {} = LastLastChunk }} ->
664
667
First = #{file => FirstFile ,
665
668
size => FirstSize ,
669
+ chunks => FirstNumChunks ,
666
670
first => FirstFirstChunk ,
667
671
last => FirstLastChunk },
668
672
Last = #{file => LastFile ,
669
673
size => LastSize ,
674
+ chunks => LastNumChunks ,
670
675
first => LastFirstChunk ,
671
676
last => LastLastChunk },
672
677
#{num_segments => length (SegmentOffsets ),
@@ -2131,6 +2136,7 @@ build_segment_info(SegFile, LastChunkPos, IdxFile) ->
2131
2136
{ok , # seg_info {file = SegFile ,
2132
2137
index = IdxFile ,
2133
2138
size = Size ,
2139
+ chunks = chunks_in_idx (IdxFile ),
2134
2140
first = FstChInfo ,
2135
2141
last = LastChInfo }};
2136
2142
_ ->
@@ -2150,6 +2156,9 @@ build_segment_info(SegFile, LastChunkPos, IdxFile) ->
2150
2156
end
2151
2157
end .
2152
2158
2159
+ chunks_in_idx (IdxFile ) ->
2160
+ (file_size (IdxFile ) - ? IDX_HEADER_SIZE ) div ? INDEX_RECORD_SIZE_B .
2161
+
2153
2162
-spec overview (file :filename_all ()) ->
2154
2163
{range (), [{epoch (), offset ()}]}.
2155
2164
overview (Dir ) ->
0 commit comments