Skip to content

Commit 17ca05f

Browse files
committed
Add schema changes for quiescing
1 parent 17b9d55 commit 17ca05f

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

nexus/db-model/src/db_metadata.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ pub struct DbMetadata {
1818
time_modified: DateTime<Utc>,
1919
version: SemverVersion,
2020
target_version: Option<SemverVersion>,
21+
quiesce_started: bool,
22+
quiesce_completed: bool,
2123
}
2224

2325
impl DbMetadata {
@@ -32,4 +34,12 @@ impl DbMetadata {
3234
pub fn version(&self) -> &SemverVersion {
3335
&self.version
3436
}
37+
38+
pub fn quiesce_started(&self) -> bool {
39+
self.quiesce_started
40+
}
41+
42+
pub fn quiesce_completed(&self) -> bool {
43+
self.quiesce_completed
44+
}
3545
}

nexus/db-schema/src/schema.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,6 +2251,8 @@ table! {
22512251
time_modified -> Timestamptz,
22522252
version -> Text,
22532253
target_version -> Nullable<Text>,
2254+
quiesce_started -> Bool,
2255+
quiesce_completed -> Bool,
22542256
}
22552257
}
22562258

schema/crdb/dbinit.sql

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5434,6 +5434,35 @@ CREATE TABLE IF NOT EXISTS omicron.public.db_metadata (
54345434
-- (Optional) Semver representation of the DB version to which we're upgrading
54355435
target_version STRING(64),
54365436

5437+
-- During the nexus boot process, it must check this table to understand the
5438+
-- state of the Schema.
5439+
--
5440+
-- There are a handful of states to consider:
5441+
--
5442+
-- - "db.version = version in binary" + "quiesce_started = true": An
5443+
-- upgrade is in-progress, and the underlying database should not be used.
5444+
-- This Nexus should coordinate with other Nexus instances at this version
5445+
-- (via internal DNS) to set "quiesce_completed" to true.
5446+
-- - "db.version = version in binary" + "quiesce_completed = true" OR
5447+
-- "db.version > version in binary"
5448+
-- This Nexus should avoid accessing the database, but has no need to coordinate
5449+
-- with other Nexuses.
5450+
-- - "db.version < version in binary":
5451+
-- This Nexus should upgrade to the new schema, but only once "quiesce_completed"
5452+
-- is set to true.
5453+
-- Once the upgrade is complete, "quiesce_started" and "quiesce_completed"
5454+
-- should both be set to false. Note that multiple Nexuses may be attempting this
5455+
-- schema upgrade operation concurrently.
5456+
5457+
5458+
-- Identifies that a schema migration has started.
5459+
-- Nexuses with "db.version = version in binary" should not access the database any longer.
5460+
quiesce_started BOOL NOT NULL,
5461+
5462+
-- Identifies that a schema migration is ready to hand-off from Old Nexus versions
5463+
-- to newer Nexus versions.
5464+
quiesce_completed BOOL NOT NULL,
5465+
54375466
CHECK (singleton = true)
54385467
);
54395468

@@ -6218,9 +6247,11 @@ INSERT INTO omicron.public.db_metadata (
62186247
time_created,
62196248
time_modified,
62206249
version,
6221-
target_version
6250+
target_version,
6251+
quiesce_started,
6252+
quiesce_completed
62226253
) VALUES
6223-
(TRUE, NOW(), NOW(), '157.0.0', NULL)
6254+
(TRUE, NOW(), NOW(), '158.0.0', NULL, FALSE, FALSE)
62246255
ON CONFLICT DO NOTHING;
62256256

62266257
COMMIT;

0 commit comments

Comments
 (0)