Skip to content

Commit

Permalink
Add batch size backoff in log poller insert logs (#10525)
Browse files Browse the repository at this point in the history
* Add batch size backoff in log poller insert logs

* update
  • Loading branch information
infiloop2 authored Sep 6, 2023
1 parent 2c0cb9c commit 3a98db6
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/chains/evm/logpoller/orm.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package logpoller

import (
"context"
"database/sql"
"math/big"
"time"
Expand Down Expand Up @@ -189,6 +190,12 @@ func (o *ORM) InsertLogs(logs []Log, qopts ...pg.QOpt) error {
(:evm_chain_id, :log_index, :block_hash, :block_number, :block_timestamp, :address, :event_sig, :topics, :tx_hash, :data, NOW()) ON CONFLICT DO NOTHING`, logs[start:end])

if err != nil {
if errors.Is(err, context.DeadlineExceeded) && batchInsertSize > 500 {
// In case of DB timeouts, try to insert again with a smaller batch upto a limit
batchInsertSize /= 2
i -= batchInsertSize // counteract +=batchInsertSize on next loop iteration
continue
}
return err
}
}
Expand Down

0 comments on commit 3a98db6

Please sign in to comment.