Skip to content

Commit

Permalink
Fix error handling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
reductionista committed Aug 24, 2024
1 parent 20b632b commit 707c330
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions core/chains/evm/logpoller/log_poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,17 +659,13 @@ func (lp *logPoller) backgroundWorkerRun() {
case <-logPruneTick:
lp.lggr.Infof("Pruning LogPoller logs...")
logPruneTick = time.After(utils.WithJitter(lp.pollPeriod * 2401)) // = 7^5 avoids common factors with 1000
allRemoved, err := lp.PruneExpiredLogs(ctx)
if allRemoved {
if lp.PruneExpiredLogs(ctx) {
lp.lggr.Infof("Finished pruning LogPoller logs. Next pruning in ~ %s", lp.pollPeriod*2401)
} else {
// Tick faster when cleanup can't keep up with the pace of new logs
logPruneTick = time.After(utils.WithJitter(lp.pollPeriod * 241))
lp.lggr.Warnf("Partially finished pruning LogPoller logs. Will resume in ~ %s", lp.pollPeriod*241)
}
if err != nil {
lp.lggr.Errorw("Unable to prune expired logs", "err", err)
}
}
}
}
Expand Down Expand Up @@ -1096,14 +1092,26 @@ func (lp *logPoller) PruneOldBlocks(ctx context.Context) (bool, error) {
}

// PruneExpiredLogs logs that are older than their retention period defined in Filter.
// Returns whether all logs eligible for pruning were removed. If logPrunePageSize is set to 0, it will always return true.
func (lp *logPoller) PruneExpiredLogs(ctx context.Context) (bool, error) {
// Returns whether all logs eligible for pruning were removed. If logPrunePageSize is set to 0, it can only
// return false if an actual error is encountered
func (lp *logPoller) PruneExpiredLogs(ctx context.Context) (done bool) {
done = true

rowsRemoved, err := lp.orm.DeleteExpiredLogs(ctx, lp.logPrunePageSize)
if err != nil || rowsRemoved < lp.logPrunePageSize {
return true, err
if err != nil {
lp.lggr.Errorw("Unable to prune expired logs", "err", err)
done = false
} else if lp.logPrunePageSize != 0 && rowsRemoved < lp.logPrunePageSize {
done = false
}

rowsRemoved, err = lp.orm.DeleteExcessLogs(ctx, lp.logPrunePageSize)
return lp.logPrunePageSize == 0 || err != nil || rowsRemoved < lp.logPrunePageSize, err
if err != nil {
lp.lggr.Errorw("Unable to prune excess logs", "err", err)
} else if lp.logPrunePageSize != 0 && rowsRemoved < lp.logPrunePageSize {
done = false
}
return done
}

// Logs returns logs matching topics and address (exactly) in the given block range,
Expand Down

0 comments on commit 707c330

Please sign in to comment.