Skip to content

[wip] Add schema changes for quiescing #8533

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions nexus/db-model/src/db_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub struct DbMetadata {
time_modified: DateTime<Utc>,
version: SemverVersion,
target_version: Option<SemverVersion>,
quiesce_started: bool,
quiesce_completed: bool,
}

impl DbMetadata {
Expand All @@ -32,4 +34,12 @@ impl DbMetadata {
pub fn version(&self) -> &SemverVersion {
&self.version
}

pub fn quiesce_started(&self) -> bool {
self.quiesce_started
}

pub fn quiesce_completed(&self) -> bool {
self.quiesce_completed
}
}
2 changes: 2 additions & 0 deletions nexus/db-schema/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2251,6 +2251,8 @@ table! {
time_modified -> Timestamptz,
version -> Text,
target_version -> Nullable<Text>,
quiesce_started -> Bool,
quiesce_completed -> Bool,
}
}

Expand Down
35 changes: 33 additions & 2 deletions schema/crdb/dbinit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5434,6 +5434,35 @@ CREATE TABLE IF NOT EXISTS omicron.public.db_metadata (
-- (Optional) Semver representation of the DB version to which we're upgrading
target_version STRING(64),

-- During the nexus boot process, it must check this table to understand the
-- state of the Schema.
--
-- There are a handful of states to consider:
--
-- - "db.version = version in binary" + "quiesce_started = true": An
-- upgrade is in-progress, and the underlying database should not be used.
-- This Nexus should coordinate with other Nexus instances at this version
-- (via internal DNS) to set "quiesce_completed" to true.
-- - "db.version = version in binary" + "quiesce_completed = true" OR
-- "db.version > version in binary"
-- This Nexus should avoid accessing the database, but has no need to coordinate
-- with other Nexuses.
-- - "db.version < version in binary":
-- This Nexus should upgrade to the new schema, but only once "quiesce_completed"
-- is set to true.
-- Once the upgrade is complete, "quiesce_started" and "quiesce_completed"
-- should both be set to false. Note that multiple Nexuses may be attempting this
-- schema upgrade operation concurrently.


-- Identifies that a schema migration has started.
-- Nexuses with "db.version = version in binary" should not access the database any longer.
quiesce_started BOOL NOT NULL,

-- Identifies that a schema migration is ready to hand-off from Old Nexus versions
-- to newer Nexus versions.
quiesce_completed BOOL NOT NULL,

CHECK (singleton = true)
);

Expand Down Expand Up @@ -6218,9 +6247,11 @@ INSERT INTO omicron.public.db_metadata (
time_created,
time_modified,
version,
target_version
target_version,
quiesce_started,
quiesce_completed
) VALUES
(TRUE, NOW(), NOW(), '157.0.0', NULL)
(TRUE, NOW(), NOW(), '158.0.0', NULL, FALSE, FALSE)
ON CONFLICT DO NOTHING;

COMMIT;
Loading