Skip to content

Commit

Permalink
Preserve persistedCallbacks of an unpersisted snapshot until needed
Browse files Browse the repository at this point in the history
The persistedCallbacks of a snapshot that failed persistance need
to be preserved until one of the two events have occurred:
- a new snapshot was introduced
- the retry-attempt of the exact same snapshot succeeded
  • Loading branch information
abhinavdangeti committed Jul 1, 2019
1 parent 0a3c176 commit a745001
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions index/scorch/persister.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ func (s *Scorch) persisterLoop() {
var persistWatchers []*epochWatcher
var lastPersistedEpoch, lastMergedEpoch uint64
var ew *epochWatcher

var lastUnpersistedEpoch uint64
var unpersistedCallbacks []index.BatchCallback

po, err := s.parsePersisterOptions()
if err != nil {
s.fireAsyncError(fmt.Errorf("persisterOptions json parsing err: %v", err))
Expand Down Expand Up @@ -149,11 +153,28 @@ OUTER:
_ = ourSnapshot.DecRef()
break OUTER
}

// save this current snapshot's epoch and persistedCallbacks, for
// a possible retry attempt in persisting the same snapshot again.
lastUnpersistedEpoch = ourSnapshot.epoch
unpersistedCallbacks = ourPersistedCallbacks

s.fireAsyncError(fmt.Errorf("got err persisting snapshot: %v", err))
_ = ourSnapshot.DecRef()
atomic.AddUint64(&s.stats.TotPersistLoopErr, 1)
continue OUTER
}

if ourPersistedCallbacks == nil &&
lastUnpersistedEpoch == ourSnapshot.epoch {
// in the event of this being a retry attempt for persisting a snapshot
// that had earlier failed, retrieve the persistedCallbacks associated
// with that snapshot.
ourPersistedCallbacks = unpersistedCallbacks
lastUnpersistedEpoch = 0
unpersistedCallbacks = nil
}

for i := range ourPersistedCallbacks {
ourPersistedCallbacks[i](err)
}
Expand Down

0 comments on commit a745001

Please sign in to comment.