From 3a98db69f784978a6c43cbfae95938d1e98f9ed2 Mon Sep 17 00:00:00 2001 From: Akshay Aggarwal <71980293+infiloop2@users.noreply.github.com> Date: Wed, 6 Sep 2023 22:12:02 +0100 Subject: [PATCH] Add batch size backoff in log poller insert logs (#10525) * Add batch size backoff in log poller insert logs * update --- core/chains/evm/logpoller/orm.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/chains/evm/logpoller/orm.go b/core/chains/evm/logpoller/orm.go index e8ced08a1e7..08a4d558fbf 100644 --- a/core/chains/evm/logpoller/orm.go +++ b/core/chains/evm/logpoller/orm.go @@ -1,6 +1,7 @@ package logpoller import ( + "context" "database/sql" "math/big" "time" @@ -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 } }