mirror of
https://github.com/kopia/kopia.git
synced 2025-12-23 22:57:50 -05:00
refactor(general): lastSettledEpochNumber() helper (#4927)
This commit is contained in:
@@ -175,8 +175,12 @@ type CurrentSnapshot struct {
|
||||
DeletionWatermarkBlobs []blob.Metadata `json:"deletionWatermarkBlobs"` // list of deletion watermark blobs
|
||||
}
|
||||
|
||||
func (cs *CurrentSnapshot) lastSettledEpochNumber() int {
|
||||
return cs.WriteEpoch - numUnsettledEpochs
|
||||
}
|
||||
|
||||
func (cs *CurrentSnapshot) isSettledEpochNumber(epoch int) bool {
|
||||
return epoch <= cs.WriteEpoch-numUnsettledEpochs
|
||||
return epoch <= cs.lastSettledEpochNumber()
|
||||
}
|
||||
|
||||
// Manager manages repository epochs.
|
||||
@@ -620,7 +624,7 @@ func (e *Manager) MaybeGenerateRangeCheckpoint(ctx context.Context) (*maintenanc
|
||||
}
|
||||
|
||||
func getRangeToCompact(cs CurrentSnapshot, p Parameters) (low, high int, compactRange bool) {
|
||||
latestSettled := cs.WriteEpoch - numUnsettledEpochs
|
||||
latestSettled := cs.lastSettledEpochNumber()
|
||||
if latestSettled < 0 {
|
||||
return -1, -1, false
|
||||
}
|
||||
|
||||
@@ -996,7 +996,7 @@ func TestMaybeCompactSingleEpoch(t *testing.T) {
|
||||
require.Empty(t, cs.SingleEpochCompactionSets)
|
||||
|
||||
// perform single-epoch compaction for settled epochs
|
||||
newestEpochToCompact := cs.WriteEpoch - numUnsettledEpochs + 1
|
||||
newestEpochToCompact := cs.lastSettledEpochNumber() + 1
|
||||
for j := range newestEpochToCompact {
|
||||
err = te.mgr.MaybeCompactSingleEpoch(ctx)
|
||||
require.NoError(t, err)
|
||||
@@ -1213,7 +1213,7 @@ func TestMaybeGenerateRangeCheckpoint_FromCompactedEpochs(t *testing.T) {
|
||||
require.Equal(t, epochsToWrite, cs.WriteEpoch)
|
||||
|
||||
// perform single-epoch compaction for settled epochs
|
||||
newestEpochToCompact := cs.WriteEpoch - numUnsettledEpochs + 1
|
||||
newestEpochToCompact := cs.lastSettledEpochNumber() + 1
|
||||
for j := range newestEpochToCompact {
|
||||
err = te.mgr.MaybeCompactSingleEpoch(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user