Skip to content

Commit

Permalink
feat(store): flush loop retries and backoff (#211)
Browse files Browse the repository at this point in the history
## Overview

Before this PR when we fail to write a batch we just ignore it. Adding
retries + backoff to try a few times.

Fixes #209
  • Loading branch information
cristaloleg authored Jul 26, 2024
1 parent e917cab commit 8f53979
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,14 +397,22 @@ func (s *Store[H]) flushLoop() {

startTime := time.Now()
toFlush := s.pending.GetAll()
err := s.flush(ctx, toFlush...)
if err != nil {

for i := 0; ; i++ {
err := s.flush(ctx, toFlush...)
if err == nil {
break
}

from, to := toFlush[0].Height(), toFlush[len(toFlush)-1].Height()
// TODO(@Wondertan): Should this be a fatal error case with os.Exit?
log.Errorw("writing header batch", "from", from, "to", to, "err", err)
log.Errorw("writing header batch", "try", i+1, "from", from, "to", to, "err", err)
s.metrics.flush(ctx, time.Since(startTime), s.pending.Len(), true)
continue

const maxRetrySleep = time.Second
sleep := min(10*time.Duration(i+1)*time.Millisecond, maxRetrySleep)
time.Sleep(sleep)
}

s.metrics.flush(ctx, time.Since(startTime), s.pending.Len(), false)
// reset pending
s.pending.Reset()
Expand Down

0 comments on commit 8f53979

Please sign in to comment.