Skip to content

Commit

Permalink
fix(general): add epoch.Manager.MaybeAdvanceWriteEpoch helper
Browse files Browse the repository at this point in the history
  • Loading branch information
julio-lopez committed Mar 7, 2024
1 parent 9a689d4 commit e27c7fc
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions internal/epoch/epoch_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,25 @@ func (e *Manager) refreshAttemptLocked(ctx context.Context) error {
return nil
}

// MaybeAdvanceWriteEpoch writes a new write epoch marker when a new write
// epoch should be started, otherwise it does not do anything.
func (e *Manager) MaybeAdvanceWriteEpoch(ctx context.Context) error {
p, err := e.getParameters(ctx)
if err != nil {
return err
}

e.mu.Lock()
cs := e.lastKnownState
e.mu.Unlock()

if shouldAdvance(cs.UncompactedEpochSets[cs.WriteEpoch], p.MinEpochDuration, p.EpochAdvanceOnCountThreshold, p.EpochAdvanceOnTotalSizeBytesThreshold) {
return errors.Wrap(e.advanceEpochMarker(ctx, cs), "error advancing epoch")
}

return nil
}

func (e *Manager) advanceEpochMarker(ctx context.Context, cs CurrentSnapshot) error {
blobID := blob.ID(fmt.Sprintf("%v%v", string(EpochMarkerIndexBlobPrefix), cs.WriteEpoch+1))

Expand Down

0 comments on commit e27c7fc

Please sign in to comment.