Skip to content

Commit 82002e5

Browse files
committed
catalog: test hydration history forced migration policy
1 parent 4f4635c commit 82002e5

2 files changed

Lines changed: 43 additions & 27 deletions

File tree

src/adapter/src/catalog/open/builtin_schema_migration.rs

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,34 @@ struct Migration {
656656
config: BuiltinItemMigrationConfig,
657657
}
658658

659+
/// Whether `builtin` participates in a forced migration using `mechanism`.
660+
fn participates_in_forced_migration(
661+
builtin: &Builtin<NameReference>,
662+
mechanism: Mechanism,
663+
) -> bool {
664+
use Builtin::*;
665+
match builtin {
666+
// A forced replacement allocates a fresh shard, which discards the
667+
// table's contents. Exclude the tables whose contents are the point:
668+
// storage usage is retained for billing, and hydration history cannot
669+
// be rebuilt from any other source.
670+
//
671+
// Hydration history takes part in a forced `Evolution`, which keeps the
672+
// rows. It has to: dev upgrades force one for every object, and a table
673+
// left out of the plan never gets its new schema registered, so
674+
// `update_fingerprints` panics at open as soon as the desc changes. See
675+
// the tripwire in `validate_migration_steps` for how to give up the
676+
// replacement exemption deliberately.
677+
Table(table) => {
678+
**table != *MZ_STORAGE_USAGE_BY_SHARD
679+
&& (mechanism != Mechanism::Replacement || **table != *MZ_OBJECT_HYDRATION_HISTORY)
680+
}
681+
MaterializedView(..) => true,
682+
Source(source) => **source != *MZ_CATALOG_RAW,
683+
Log(..) | View(..) | Type(..) | Func(..) | Index(..) | Connection(..) => false,
684+
}
685+
}
686+
659687
impl Migration {
660688
async fn run(self, steps: &[MigrationStep]) -> anyhow::Result<MigrationRunResult> {
661689
info!(
@@ -831,33 +859,7 @@ impl Migration {
831859
// added in this version; the leader will allocate their shards during bootstrap, and
832860
// there is nothing to evolve or replace.
833861
.filter(|(_, info)| info.shard_id.is_some())
834-
.filter(|(_, info)| {
835-
use Builtin::*;
836-
match info.builtin {
837-
// A forced replacement allocates a fresh shard, which
838-
// discards the table's contents. Exclude the tables whose
839-
// contents are the point: storage usage is retained for
840-
// billing, and hydration history cannot be rebuilt from any
841-
// other source.
842-
//
843-
// The hydration history takes part in a forced `Evolution`,
844-
// which keeps the rows. It has to: dev upgrades force one for
845-
// every object, and a table left out of the plan never gets
846-
// its new schema registered, so `update_fingerprints` panics
847-
// at open as soon as the desc changes. The exemption is best
848-
// effort, not a guarantee. See the tripwire in
849-
// `validate_migration_steps` for how to give it up
850-
// deliberately.
851-
Table(table) => {
852-
**table != *MZ_STORAGE_USAGE_BY_SHARD
853-
&& (mechanism != Mechanism::Replacement
854-
|| **table != *MZ_OBJECT_HYDRATION_HISTORY)
855-
}
856-
MaterializedView(..) => true,
857-
Source(source) => **source != *MZ_CATALOG_RAW,
858-
Log(..) | View(..) | Type(..) | Func(..) | Index(..) | Connection(..) => false,
859-
}
860-
})
862+
.filter(|(_, info)| participates_in_forced_migration(info.builtin, mechanism))
861863
.map(|(object, _)| object.clone())
862864
.collect();
863865

src/adapter/src/catalog/open/builtin_schema_migration_tests.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ use tracing::info;
2727

2828
use super::*;
2929

30+
#[mz_ore::test]
31+
fn hydration_history_forced_migration_policy() {
32+
let hydration_history = Builtin::Table(&*MZ_OBJECT_HYDRATION_HISTORY);
33+
34+
assert!(participates_in_forced_migration(
35+
&hydration_history,
36+
Mechanism::Evolution
37+
));
38+
assert!(!participates_in_forced_migration(
39+
&hydration_history,
40+
Mechanism::Replacement
41+
));
42+
}
43+
3044
#[test] // allow(test-attribute)
3145
#[cfg_attr(miri, ignore)] // too slow
3246
fn test_builtin_schema_migration() {

0 commit comments

Comments
 (0)