Skip to content

fix(consumer): stop 2 pods reading Studio's requests at once - #841

Merged
MoonBoi9001 merged 6 commits into
mb9/keep-dipper-running-when-redpanda-is-down-at-startfrom
mb9/let-only-one-pod-read-studio-requests-at-a-time
Nov 17, 2026
Merged

MoonBoi9001 merged 6 commits into
mb9/keep-dipper-running-when-redpanda-is-down-at-startfrom
mb9/let-only-one-pod-read-studio-requests-at-a-time

Conversation

@MoonBoi9001

@MoonBoi9001 MoonBoi9001 commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

During a rolling deploy the old and new pods both read the Kafka topic, so the old one could apply an older request after a newer one. The consumer now holds a Postgres advisory lock while it reads, and a holder that goes quiet loses it after 30 seconds (Postgres 14 or later).

Important

The lock belongs to 1 database session, so dipper must connect to Postgres directly, not through a connection pooler in transaction mode.

Postgres can hand out a named lock that 1 connection holds until it closes or is lost. The
registry can now open a connection outside its pool, try such a lock on it, and check that the
connection still answers. Nothing uses it yet, and its test needs a database, so CI runs it.
During a rolling deploy 2 pods read the Kafka topic at once, and the outgoing pod could apply
an older request after the incoming pod had applied a newer one. The consumer now holds a
Postgres advisory lock to read, waits for it without delaying a stop, and stops if it loses it.
… into mb9/let-only-one-pod-read-studio-requests-at-a-time
@MoonBoi9001
MoonBoi9001 added this pull request to stack #842 November 17, 2026 19:01
… into mb9/let-only-one-pod-read-studio-requests-at-a-time

# Conflicts:
#	bin/dipper-service/src/network/service/indexing_request_consumer.rs
The consumer holds a Postgres lock on a connection of its own, and checked that connection
every 5 seconds only while reading. During a wait for the brokers, or for a request to finish
on a stop, it sat silent, so a lost lock was found out only at the end. Both now check it too.
A dipper that died without closing its lock connection left a session Postgres went on
believing in, for hours, and no other dipper could read. Postgres now ends that session once
idle for 30 seconds (14 or later; older only warns), it has a name, and the alert says so.
@MoonBoi9001
MoonBoi9001 marked this pull request as ready for review November 17, 2026 19:48
@MoonBoi9001
MoonBoi9001 removed this pull request from stack #842 November 17, 2026 20:26
@MoonBoi9001
MoonBoi9001 merged commit b34e758 into mb9/keep-dipper-running-when-redpanda-is-down-at-start Nov 17, 2026
13 checks passed
MoonBoi9001 added a commit that referenced this pull request Nov 17, 2026
PR 841 was merged into PR 839's branch after that branch had itself been merged, so its change
never reached this branch. This applies the same change: the consumer holds a Postgres advisory
lock while it reads, and a holder that goes quiet loses it after 30 seconds.
cjorge-thegraph added a commit that referenced this pull request Nov 19, 2026
A rollout with the Deployment's default `RollingUpdate` strategy runs the old and the new dipper side by side until the new pod is ready. Each pod keeps its own nonce for the one signer (`nonce: AtomicU64` under `submit_lock` in `chain_client/client.rs`) and its own in-process locks, the global reassess lock among them, while both pull jobs from the same queue. During that overlap the 2 can send transactions on the same nonce and offer or cancel the same agreement twice. testnet-v2 runs this way today (`maxSurge: 25%` rounds up to a second pod).

- `k8s/deployment.yaml` now sets `strategy: Recreate`, and `k8s/README.md` says to run exactly 1 replica and why. The price is a gap while the new pod starts.
- The example config asked for 10 database connections, which dipper's own startup check refuses (the default 8 worker loops need 3 × 8 + 2 = 26), so an unedited copy did not start. The check moves from `main` into `Config::validate_db_pool`, run with the other config checks before anything connects, so a test holds the example to it; the example now uses the default pool of 32.

A Postgres advisory lock (#841, on the Redpanda stack) keeps 2 pods from consuming Studio's requests at once. `Recreate` orders rollouts only: on an eviction, a node drain or a pod deletion, Kubernetes starts the replacement while the old pod is still terminating, so this does not rule out 2 signers on its own. That needs a lock dipper holds for as long as it runs, which is a follow-up.

**Tests:** `example_config_has_db_connections_for_its_worker_loops` failed on `main` ("needs at least 26 db connections … db.max_connections is 10") and passes now; 3 more pin the rule. `just fmt-check`, `just check` and `just test-unit` pass locally.

### Changes after review

- The manifest comment, the k8s README and this description no longer claim `Recreate` prevents 2 pods acting at once: it orders rollouts only. The README says to keep evictions and node drains to planned windows until dipper holds a lock of its own.
- `rollingUpdate: null` next to `type: Recreate`, so a client-side apply onto an existing Deployment drops the defaulted rolling-update settings the API refuses with `Recreate`.
- A pool too small for the worker loops is reported as an invalid config, not a db config.




Co-Authored-By: Claude Opus 5.5 <[email protected]>
@MoonBoi9001
MoonBoi9001 deleted the mb9/let-only-one-pod-read-studio-requests-at-a-time branch November 26, 2026 13:00
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.

1 participant