Skip to content

Commit

Permalink
Merge branch 'main' into store/fix-store-head
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed Jul 31, 2024
2 parents da710eb + 8f53979 commit cdb5de9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions header.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Header[H any] interface {
// Time returns time when header was created.
Time() time.Time
// Verify validates given untrusted Header against trusted Header.
// Verify should be able to validate both adjacent and non-adjacent headers.
Verify(H) error
// Validate performs stateless validation to check for missed/incorrect fields.
Validate() error
Expand Down
17 changes: 12 additions & 5 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,20 @@ 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.tryAdvanceHead(toFlush...)
Expand Down

0 comments on commit cdb5de9

Please sign in to comment.