Skip to content

Commit 4a7e6fb

Browse files
Merge pull request #1255 from abhinavdangeti/scorch-persister-cb
Preserve persistedCallbacks of an unpersisted snapshot until needed
2 parents f9e4034 + 732150d commit 4a7e6fb

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

index/scorch/persister.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ func (s *Scorch) persisterLoop() {
9090
var persistWatchers []*epochWatcher
9191
var lastPersistedEpoch, lastMergedEpoch uint64
9292
var ew *epochWatcher
93+
94+
var unpersistedCallbacks []index.BatchCallback
95+
9396
po, err := s.parsePersisterOptions()
9497
if err != nil {
9598
s.fireAsyncError(fmt.Errorf("persisterOptions json parsing err: %v", err))
@@ -149,11 +152,25 @@ OUTER:
149152
_ = ourSnapshot.DecRef()
150153
break OUTER
151154
}
155+
156+
// save this current snapshot's persistedCallbacks, to invoke during
157+
// the retry attempt
158+
unpersistedCallbacks = append(unpersistedCallbacks, ourPersistedCallbacks...)
159+
152160
s.fireAsyncError(fmt.Errorf("got err persisting snapshot: %v", err))
153161
_ = ourSnapshot.DecRef()
154162
atomic.AddUint64(&s.stats.TotPersistLoopErr, 1)
155163
continue OUTER
156164
}
165+
166+
if unpersistedCallbacks != nil {
167+
// in the event of this being a retry attempt for persisting a snapshot
168+
// that had earlier failed, prepend the persistedCallbacks associated
169+
// with earlier segment(s) to the latest persistedCallbacks
170+
ourPersistedCallbacks = append(unpersistedCallbacks, ourPersistedCallbacks...)
171+
unpersistedCallbacks = nil
172+
}
173+
157174
for i := range ourPersistedCallbacks {
158175
ourPersistedCallbacks[i](err)
159176
}

0 commit comments

Comments
 (0)