Skip to content

Commit

Permalink
Prepend earlier segment's persisted callbacks to latest
Browse files Browse the repository at this point in the history
This is so that no persistedCallbacks of older segments are dropped
when persisting a snapshot of segments finally does succeed.
  • Loading branch information
abhinavdangeti committed Jul 2, 2019
1 parent a745001 commit 732150d
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions index/scorch/persister.go
Expand Up @@ -91,7 +91,6 @@ func (s *Scorch) persisterLoop() {
var lastPersistedEpoch, lastMergedEpoch uint64
var ew *epochWatcher

var lastUnpersistedEpoch uint64
var unpersistedCallbacks []index.BatchCallback

po, err := s.parsePersisterOptions()
Expand Down Expand Up @@ -154,24 +153,21 @@ OUTER:
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
// save this current snapshot's persistedCallbacks, to invoke during
// the retry attempt
unpersistedCallbacks = append(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 {
if unpersistedCallbacks != nil {
// 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
// that had earlier failed, prepend the persistedCallbacks associated
// with earlier segment(s) to the latest persistedCallbacks
ourPersistedCallbacks = append(unpersistedCallbacks, ourPersistedCallbacks...)
unpersistedCallbacks = nil
}

Expand Down

0 comments on commit 732150d

Please sign in to comment.