Skip to content

Commit 2da75b6

Browse files
committed
Include chunk count in seg-info
1 parent f5316e7 commit 2da75b6

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/osiris_log.erl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@
453453
-record(seg_info,
454454
{file :: file:filename_all(),
455455
size = 0 :: non_neg_integer(),
456+
chunks = 0 :: non_neg_integer(),
456457
index :: file:filename_all(),
457458
first :: undefined | #chunk_info{},
458459
last :: undefined | #chunk_info{}}).
@@ -570,6 +571,7 @@ init(#{dir := Dir,
570571
timestamp = FstTs}},
571572
last := #{file := Filename,
572573
size := Size,
574+
chunks := NumChunks,
573575
last := #chunk_info{epoch = LastEpoch,
574576
timestamp = LastTs,
575577
id = LastChId,
@@ -603,7 +605,6 @@ init(#{dir := Dir,
603605
ok = file:truncate(SegFd),
604606
Event = {segment_opened, undefined, Filename},
605607
Manifest = ManifestMod:handle_event(Event, Manifest0),
606-
NumChunks = LastChId - FstChId,
607608
#?MODULE{cfg = Cfg,
608609
mode =
609610
#write{type = WriterType,
@@ -655,18 +656,22 @@ writer_manifest(#{dir := Dir} = Config) ->
655656
{SegmentOffsets,
656657
#seg_info{file = FirstFile,
657658
size = FirstSize,
659+
chunks = FirstNumChunks,
658660
first = FirstFirstChunk,
659661
last = FirstLastChunk},
660662
#seg_info{file = LastFile,
661663
size = LastSize,
664+
chunks = LastNumChunks,
662665
first = LastFirstChunk,
663666
last = #chunk_info{} = LastLastChunk}} ->
664667
First = #{file => FirstFile,
665668
size => FirstSize,
669+
chunks => FirstNumChunks,
666670
first => FirstFirstChunk,
667671
last => FirstLastChunk},
668672
Last = #{file => LastFile,
669673
size => LastSize,
674+
chunks => LastNumChunks,
670675
first => LastFirstChunk,
671676
last => LastLastChunk},
672677
#{num_segments => length(SegmentOffsets),
@@ -2131,6 +2136,7 @@ build_segment_info(SegFile, LastChunkPos, IdxFile) ->
21312136
{ok, #seg_info{file = SegFile,
21322137
index = IdxFile,
21332138
size = Size,
2139+
chunks = chunks_in_idx(IdxFile),
21342140
first = FstChInfo,
21352141
last = LastChInfo}};
21362142
_ ->
@@ -2150,6 +2156,9 @@ build_segment_info(SegFile, LastChunkPos, IdxFile) ->
21502156
end
21512157
end.
21522158

2159+
chunks_in_idx(IdxFile) ->
2160+
(file_size(IdxFile) - ?IDX_HEADER_SIZE) div ?INDEX_RECORD_SIZE_B.
2161+
21532162
-spec overview(file:filename_all()) ->
21542163
{range(), [{epoch(), offset()}]}.
21552164
overview(Dir) ->

src/osiris_log_manifest.erl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
-type segment_info() ::
88
#{file := file:filename_all(),
99
size := non_neg_integer(),
10+
chunks := non_neg_integer(),
1011
first => #chunk_info{},
1112
last => #chunk_info{}
1213
}.

0 commit comments

Comments
 (0)