Skip to content

Commit

Permalink
server/storage: update currentRev if scheduledCompact > currentRev
Browse files Browse the repository at this point in the history
Signed-off-by: Wei Fu <fuweid89@gmail.com>
  • Loading branch information
fuweid committed Apr 18, 2024
1 parent 3d89ba5 commit 75f1df6
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions server/storage/mvcc/kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,19 +388,30 @@ func (s *store) restore() error {
}
}

// NOTE: Last compaction could delete all the related revisions but it
// didn't have chance to update it finished state. When revisions in
// [N, `scheduledCompact`] are tombstone, the `currentRev` will be less
// than scheduledCompact. The next following `compactLockfree` call
// will return ErrFutureRev. Since we force-commit scheduledCompact
// rev, it's trusted value. We should update `currentRev` to align with
// `scheduledCompact` just in case that the revision is decreased.
if scheduledCompact != 0 && s.currentRev < scheduledCompact {
s.currentRev = scheduledCompact
}

tx.RUnlock()

s.lg.Info("kvstore restored", zap.Int64("current-rev", s.currentRev))

if scheduledCompact != 0 {
if _, err := s.compactLockfree(scheduledCompact); err != nil {
s.lg.Warn("compaction encountered error", zap.Error(err))
} else {
s.lg.Info(
"resume scheduled compaction",
zap.Int64("scheduled-compact-revision", scheduledCompact),
)
}

s.lg.Info(
"resume scheduled compaction",
zap.Int64("scheduled-compact-revision", scheduledCompact),
)
}

return nil
Expand Down

0 comments on commit 75f1df6

Please sign in to comment.