Skip to content

Commit

Permalink
log: consolidate raftLog initialization
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Kalinnikov <[email protected]>
  • Loading branch information
pav-kv committed Feb 1, 2024
1 parent d14e61b commit 6b24859
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ func newLogWithSize(storage Storage, logger Logger, maxApplyingEntsSize entryEnc
if storage == nil {
log.Panic("storage must not be nil")
}
log := &raftLog{
storage: storage,
logger: logger,
maxApplyingEntsSize: maxApplyingEntsSize,
}
firstIndex, err := storage.FirstIndex()
if err != nil {
panic(err) // TODO(bdarnell)
Expand All @@ -88,15 +83,22 @@ func newLogWithSize(storage Storage, logger Logger, maxApplyingEntsSize entryEnc
if err != nil {
panic(err) // TODO(bdarnell)
}
log.unstable.offset = lastIndex + 1
log.unstable.offsetInProgress = lastIndex + 1
log.unstable.logger = logger
// Initialize our committed and applied pointers to the time of the last compaction.
log.committed = firstIndex - 1
log.applying = firstIndex - 1
log.applied = firstIndex - 1
return &raftLog{
storage: storage,
unstable: unstable{
offset: lastIndex + 1,
offsetInProgress: lastIndex + 1,
logger: logger,
},
maxApplyingEntsSize: maxApplyingEntsSize,

return log
// Initialize our committed and applied pointers to the time of the last compaction.
committed: firstIndex - 1,
applying: firstIndex - 1,
applied: firstIndex - 1,

logger: logger,
}
}

func (l *raftLog) String() string {
Expand Down

0 comments on commit 6b24859

Please sign in to comment.