Skip to content

feat(indexer): workers claim messages from Postgres on all replicas - #1636

Open
carte7000 wants to merge 2 commits into
feat/indexer/replica/work-statefrom
feat/indexer/replica/claim-work
Open

carte7000 wants to merge 2 commits into
feat/indexer/replica/work-statefrom
feat/indexer/replica/claim-work

Conversation

@carte7000

Copy link
Copy Markdown
Contributor

Run the worker pool on every replica. Each replica claims due PROCESSING rows from indexer.messages, runs the task and settles the row with the claim token. A retry waits for the backoff delay in the database, and the database sets TIMEOUT when the next attempt starts after the deadline. The leader times out expired rows in its own loop and records indexer_worker_queue_size.

Discovery no longer sends verifications on a channel. It writes the messages with their trace parent, and the commit wakes the local pool. The worker span is a child of the discovery span.

Remove the in-memory scheduler, the heap, the hydrate, WithOnElected and GetProcessingMessages. Add [Pool] PollInterval. Deprecate TickerInterval, MaxHeapSize, HydrationBatchSize and the discovery channel size gauge.

A crash or a leader change no longer loses the retry state, and two replicas no longer work on the same message at the same time.

@carte7000
carte7000 added this pull request to stack #1633 November 23, 2026 19:42
@carte7000
carte7000 force-pushed the feat/indexer/replica/claim-work branch from 674c403 to 26b90e7 Compare November 23, 2026 19:53
@carte7000
carte7000 force-pushed the feat/indexer/replica/claim-work branch from 26b90e7 to 23a1e9a Compare November 23, 2026 20:00
@carte7000
carte7000 marked this pull request as ready for review November 23, 2026 20:56
@carte7000
carte7000 requested review from a team as code owners November 23, 2026 20:56
tt-cll
tt-cll previously approved these changes Nov 23, 2026
return false, err
}

if len(messages) > 0 || len(persistedVerifications) > 0 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously a late verification for a TIMEOUT message re-entered the worker via the discovery channel, and SUCCESS could overwrite TIMEOUT. Now the insert is ON CONFLICT DO NOTHING and nothing requeues, so it can never be retried?. Is that intended?

@carte7000 carte7000 Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously a late verification for a TIMEOUT message re-entered the worker via the discovery channel

I am not sure if this is something we counted on for retry. The discovery channel use multiple source but they are all supposed to give the same messages for the same ccv and within a very short window (way shorter than the actual timeout of a message). In practice I don't think this would have ever retried a worker round.

Let me know if you agree I might be misunderstand the comment

Run the worker pool on every replica. Each replica claims due PROCESSING
rows from indexer.messages, runs the task and settles the row with the
claim token. A retry waits for the backoff delay in the database, and
the database sets TIMEOUT when the next attempt starts after the
deadline. The leader times out expired rows in its own loop and records
indexer_worker_queue_size.

Discovery no longer sends verifications on a channel. It writes the
messages with their trace parent, and the commit wakes the local pool.
The worker span is a child of the discovery span.

Remove the in-memory scheduler, the heap, the hydrate, WithOnElected
and GetProcessingMessages. Add [Pool] PollInterval. Deprecate
TickerInterval, MaxHeapSize, HydrationBatchSize and the discovery
channel size gauge.

A crash or a leader change no longer loses the retry state, and two
replicas no longer work on the same message at the same time.
@carte7000
carte7000 force-pushed the feat/indexer/replica/claim-work branch from 5473790 to 69a9034 Compare November 24, 2026 19:41
@github-actions

Copy link
Copy Markdown
Contributor

Code coverage report:

Package main feat/indexer/replica/claim-work Diff
github.com/smartcontractkit/chainlink-ccv/aggregator 46.21% 46.20% -0.01%
github.com/smartcontractkit/chainlink-ccv/bootstrap 67.91% 67.91% +0.00%
github.com/smartcontractkit/chainlink-ccv/cli 53.78% 53.78% +0.00%
github.com/smartcontractkit/chainlink-ccv/cmd 52.74% 52.74% +0.00%
github.com/smartcontractkit/chainlink-ccv/common 47.59% 47.59% +0.00%
github.com/smartcontractkit/chainlink-ccv/docs 0.00% 0.00% +0.00%
github.com/smartcontractkit/chainlink-ccv/executor 44.92% 44.92% +0.00%
github.com/smartcontractkit/chainlink-ccv/indexer 33.39% 34.19% +0.80%
github.com/smartcontractkit/chainlink-ccv/integration 70.90% 70.90% +0.00%
github.com/smartcontractkit/chainlink-ccv/internal 0.00% 0.00% +0.00%
github.com/smartcontractkit/chainlink-ccv/migration 78.70% 78.70% +0.00%
github.com/smartcontractkit/chainlink-ccv/pkg 84.62% 84.62% +0.00%
github.com/smartcontractkit/chainlink-ccv/pricer 18.67% 18.67% +0.00%
github.com/smartcontractkit/chainlink-ccv/protocol 61.72% 61.72% +0.00%
github.com/smartcontractkit/chainlink-ccv/tools 50.86% 53.56% +2.70%
github.com/smartcontractkit/chainlink-ccv/verifier 45.22% 45.22% +0.00%
Total 48.70% 48.80% +0.10%

Files removed (from main):

  • github.com/smartcontractkit/chainlink-ccv/indexer/pkg/worker/heap.go
  • github.com/smartcontractkit/chainlink-ccv/indexer/pkg/worker/scheduler.go

Files added (in feat/indexer/replica/claim-work):

  • github.com/smartcontractkit/chainlink-ccv/indexer/pkg/storage/work_state.go

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants