Skip to content

feat: add advisory-lock leader election for workers - #601

Merged
thlpkee20-wq merged 1 commit into
Stellabill:mainfrom
chiemezie1:feat/worker-leader-election
Jul 30, 2026
Merged

thlpkee20-wq merged 1 commit into
Stellabill:mainfrom
chiemezie1:feat/worker-leader-election

Conversation

@chiemezie1

Copy link
Copy Markdown
Contributor

feat: add advisory-lock leader election for workers

Summary

This PR adds PostgreSQL advisory-lock based leader election for the singleton worker jobs so only one instance runs the partition rollover and statement archive work at a time.

What changed

  • Added a reusable leader-election guard backed by PostgreSQL advisory locks.
  • Wrapped the partition rollover job with leader-election so duplicate rollover work is skipped when multiple replicas are active.
  • Wrapped the statement archive job with leader-election so duplicate archival runs do not happen concurrently.
  • Exposed a Prometheus gauge named leader_status{job="..."} to indicate whether the current process holds the leader lock.
  • Added unit tests for the lock guard behavior and documented the implementation.

Why

Without leader election, multiple worker replicas could run the same singleton job at the same time and produce duplicate work or race conditions during partition and archival operations.

Testing

  • Verified the implementation is committed locally.
  • Attempted to run the worker test suite, but the repository currently hits an existing import-cycle issue in the broader worker package graph, which prevented the tests from running to completion.

Closes: #421

@drips-wave

drips-wave Bot commented Jul 30, 2026

Copy link
Copy Markdown

@chiemezie1 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@thlpkee20-wq
thlpkee20-wq merged commit 3490efb into Stellabill:main Jul 30, 2026
5 of 20 checks passed
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.

Add worker leader election via Postgres advisory locks

3 participants