-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New job queue: worker registration and leader election #3307
base: main
Are you sure you want to change the base?
Changes from all commits
c92692b
823174c
2801285
f4897ca
76afd6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
-- Copyright 2024 New Vector Ltd. | ||
-- | ||
-- SPDX-License-Identifier: AGPL-3.0-only | ||
-- Please see LICENSE in the repository root for full details. | ||
|
||
-- This table stores informations about worker, mostly to track their health | ||
CREATE TABLE queue_workers ( | ||
queue_worker_id UUID NOT NULL PRIMARY KEY, | ||
|
||
-- When the worker was registered | ||
registered_at TIMESTAMP WITH TIME ZONE NOT NULL, | ||
|
||
-- When the worker was last seen | ||
last_seen_at TIMESTAMP WITH TIME ZONE NOT NULL, | ||
|
||
-- When the worker was shut down | ||
shutdown_at TIMESTAMP WITH TIME ZONE | ||
); | ||
|
||
-- This single-row table stores the leader of the queue | ||
-- The leader is responsible for running maintenance tasks | ||
CREATE UNLOGGED TABLE queue_leader ( | ||
-- This makes the row unique | ||
active BOOLEAN NOT NULL DEFAULT TRUE UNIQUE, | ||
|
||
-- When the leader was elected | ||
elected_at TIMESTAMP WITH TIME ZONE NOT NULL, | ||
|
||
-- Until when the lease is valid | ||
expires_at TIMESTAMP WITH TIME ZONE NOT NULL, | ||
|
||
-- The worker ID of the leader | ||
queue_worker_id UUID NOT NULL REFERENCES queue_workers (queue_worker_id), | ||
|
||
-- This, combined with the unique constraint, makes sure we only ever have a single row | ||
CONSTRAINT queue_leader_active CHECK (active IS TRUE) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it sounds silly, but I'd make this a
PRIMARY KEY
— maybe this sounds dogmatic? But there a handful of tools are not happy with tables that don't have a primary key, e.g. logical replication in Postgres by default, I'd say it's worth always using it instead of UNIQUE etc.