Skip to content

feat(indexer): keep the worker state on each message - #1635

Open
carte7000 wants to merge 3 commits into
feat/indexer/replica/unavailable-verifierfrom
feat/indexer/replica/work-state
Open

carte7000 wants to merge 3 commits into
feat/indexer/replica/unavailable-verifierfrom
feat/indexer/replica/work-state

Conversation

@carte7000

Copy link
Copy Markdown
Contributor

Add attempt_count, next_attempt_at, retry_deadline and trace_parent to indexer.messages, and a partial index on the due PROCESSING rows.

Add ClaimWork, SettleWork, ExpireWork and CountProcessingMessages to IndexerStorage. A claim leases due rows with FOR UPDATE SKIP LOCKED and increments attempt_count, which is the claim token. A settle changes the row only while the token matches. Postgres decides the deadline with its own clock.

The message insert writes trace_parent. PersistDiscoveryBatch calls an optional callback after a commit with messages. Add the indexer_worker_queue_size gauge.

Nothing calls the new methods yet, so the worker does not change. An EXPLAIN test writes the plan of each query to testdata.

The index build blocks writes to indexer.messages.

@carte7000
carte7000 added this pull request to stack #1633 November 23, 2026 19:34
@carte7000
carte7000 force-pushed the feat/indexer/replica/work-state branch from 8b82bce to 8db2592 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
Comment thread indexer/pkg/common/storage.go Outdated
Comment on lines +64 to +68
ClaimWork(ctx context.Context, limit int, lease, window time.Duration) ([]WorkClaim, error)
// SettleWork ends one attempt while the claim is held; it returns ErrClaimLost when it is not.
SettleWork(ctx context.Context, s WorkSettlement) (MessageStatus, error)
// ExpireWork times out up to limit PROCESSING messages that are not leased and are past their deadline.
ExpireWork(ctx context.Context, window time.Duration, limit int) (int64, error)

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.

Is applying a window change to in-flight messages a requirement? Why not also store each message's deadline in the table? If we stamp retry_deadline at insert it would avoid replicas/the replay CLI disagreeing during config rollouts and stop --force from moving deadlines.

Add attempt_count, next_attempt_at, retry_deadline and trace_parent to
indexer.messages, and a partial index on the due PROCESSING rows.

Add ClaimWork, SettleWork, ExpireWork and CountProcessingMessages to
IndexerStorage. A claim leases due rows with FOR UPDATE SKIP LOCKED and
increments attempt_count, which is the claim token. A settle changes
the row only while the token matches. Postgres decides the deadline
with its own clock.

The message insert writes trace_parent. PersistDiscoveryBatch calls an
optional callback after a commit with messages. Add the
indexer_worker_queue_size gauge.

Nothing calls the new methods yet, so the worker does not change. An
EXPLAIN test writes the plan of each query to testdata.

The index build blocks writes to indexer.messages.
@github-actions

Copy link
Copy Markdown
Contributor

Code coverage report:

Package main feat/indexer/replica/work-state Diff
github.com/smartcontractkit/chainlink-ccv/aggregator 46.21% 46.21% +0.00%
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 35.60% 35.57% -0.03%
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 53.56% 53.56% +0.00%
github.com/smartcontractkit/chainlink-ccv/verifier 45.22% 45.22% +0.00%
Total 48.80% 48.80% +0.00%

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

  • 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