Skip to content

Commit

Permalink
optimize network event notification retry at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
gerardsn committed Nov 4, 2024
1 parent 771b219 commit d72c2df
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions network/dag/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ func (p *notifier) Run() error {
}
// we're going to retry all events synchronously at startup. For the ones that fail we'll start the retry loop
failedAtStartup := make([]Event, 0)
readyToRetry := make([]Event, 0)
err := p.db.ReadShelf(p.ctx, p.shelfName(), func(reader stoabs.Reader) error {
return reader.Iterate(func(k stoabs.Key, v []byte) error {
event := Event{}
Expand All @@ -253,11 +254,7 @@ func (p *notifier) Run() error {
return nil
}

if err := p.notifyNow(event); err != nil {
if event.Retries < maxRetries {
failedAtStartup = append(failedAtStartup, event)
}
}
readyToRetry = append(readyToRetry, event)

return nil
}, stoabs.BytesKey{})
Expand All @@ -266,6 +263,15 @@ func (p *notifier) Run() error {
return err
}

// do outside of main loop to prevent long running read
for _, event := range readyToRetry {
if err := p.notifyNow(event); err != nil {
if event.Retries < maxRetries {
failedAtStartup = append(failedAtStartup, event)
}
}
}

// for all events from failedAtStartup, call retry
// this may still produce errors in the logs or even duplicate errors since notifyNow also failed
// but rather duplicate errors then errors produced from overloading the DB with transactions
Expand Down

0 comments on commit d72c2df

Please sign in to comment.