Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(store): flush loop retries and backoff #211

Merged
merged 3 commits into from
Jul 26, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"os"
"sync/atomic"
"time"

Expand Down Expand Up @@ -397,14 +398,26 @@ func (s *Store[H]) flushLoop() {

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

const flushRetries = 3
for i := 0; i <= flushRetries; 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)
if i == flushRetries {
log.Errorw("writing header batch", "from", from, "to", to, "err", err)
os.Exit(1)
cristaloleg marked this conversation as resolved.
Show resolved Hide resolved
return
}
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
sleep := 10 * time.Duration(i+1) * time.Millisecond
time.Sleep(sleep)
cristaloleg marked this conversation as resolved.
Show resolved Hide resolved
}
cristaloleg marked this conversation as resolved.
Show resolved Hide resolved

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