Skip to content

Commit 4afd695

Browse files
committed
adapter: Remove legacy builtin item migrations
Previously, the adapter maintained two different implementations of the builtin item migration framework. One that was used before 0dt and one that was used with 0dt. The 0dt implementation still works when 0dt is turned off, but we wanted to keep the legacy implementation around while the 0dt implementation was still new. The 0dt implementation has been around long enough in production to prove that it works. On the other hand, the legacy implementation has not been tested in production in a long time. This commit removes the legacy implementation and always uses the new implementation. This should reduce the maintenance burden of builtin item migrations. In the future, the builtin item migration framework should be completely removed and replaced with `ALTER TABLE`.
1 parent 3c544a1 commit 4afd695

File tree

8 files changed

+54
-1312
lines changed

8 files changed

+54
-1312
lines changed

src/adapter/src/catalog.rs

Lines changed: 9 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ use uuid::Uuid;
8585

8686
// DO NOT add any more imports from `crate` outside of `crate::catalog`.
8787
pub use crate::catalog::builtin_table_updates::BuiltinTableUpdate;
88-
pub use crate::catalog::open::{
89-
BuiltinMigrationMetadata, InitializeStateResult, OpenCatalogResult,
90-
};
88+
pub use crate::catalog::open::{InitializeStateResult, OpenCatalogResult};
9189
pub use crate::catalog::state::CatalogState;
9290
pub use crate::catalog::transact::{
9391
DropObjectInfo, Op, ReplicaCreateDropReason, TransactionResult,
@@ -671,9 +669,9 @@ impl Catalog {
671669
// debugging/testing.
672670
let previous_ts = now().into();
673671
let replica_size = &bootstrap_args.default_cluster_replica_size;
672+
let read_only = false;
674673
let OpenCatalogResult {
675674
catalog,
676-
storage_collections_to_drop: _,
677675
migrated_storage_collections_0dt: _,
678676
new_builtin_collections: _,
679677
builtin_table_updates: _,
@@ -687,7 +685,7 @@ impl Catalog {
687685
all_features: false,
688686
build_info: &DUMMY_BUILD_INFO,
689687
environment_id: environment_id.unwrap_or(EnvironmentId::for_tests()),
690-
read_only: false,
688+
read_only,
691689
now,
692690
boot_ts: previous_ts,
693691
skip_migrations: true,
@@ -705,7 +703,10 @@ impl Catalog {
705703
aws_privatelink_availability_zones: None,
706704
http_host_name: None,
707705
connection_context: ConnectionContext::for_tests(secrets_reader),
708-
builtin_item_migration_config: BuiltinItemMigrationConfig::Legacy,
706+
builtin_item_migration_config: BuiltinItemMigrationConfig {
707+
persist_client: persist_client.clone(),
708+
read_only,
709+
},
709710
persist_client,
710711
enable_expression_cache_override,
711712
enable_0dt_deployment: true,
@@ -2267,10 +2268,7 @@ mod tests {
22672268
use tokio_postgres::NoTls;
22682269
use uuid::Uuid;
22692270

2270-
use mz_catalog::builtin::{
2271-
Builtin, BuiltinType, UnsafeBuiltinTableFingerprintWhitespace, BUILTINS,
2272-
UNSAFE_DO_NOT_CALL_THIS_IN_PRODUCTION_BUILTIN_TABLE_FINGERPRINT_WHITESPACE,
2273-
};
2271+
use mz_catalog::builtin::{Builtin, BuiltinType, BUILTINS};
22742272
use mz_catalog::durable::{test_bootstrap_args, CatalogError, DurableCatalogError, FenceError};
22752273
use mz_catalog::SYSTEM_CONN_ID;
22762274
use mz_controller_types::{ClusterId, ReplicaId};
@@ -2285,9 +2283,7 @@ mod tests {
22852283
CatalogItemId, Datum, GlobalId, RelationType, RelationVersionSelector, RowArena,
22862284
ScalarType, Timestamp,
22872285
};
2288-
use mz_sql::catalog::{
2289-
BuiltinsConfig, CatalogDatabase, CatalogSchema, CatalogType, SessionCatalog,
2290-
};
2286+
use mz_sql::catalog::{BuiltinsConfig, CatalogSchema, CatalogType, SessionCatalog};
22912287
use mz_sql::func::{Func, FuncImpl, Operation, OP_IMPLS};
22922288
use mz_sql::names::{
22932289
self, DatabaseId, ItemQualifiers, ObjectId, PartialItemName, QualifiedItemName,
@@ -3507,119 +3503,6 @@ mod tests {
35073503
.await
35083504
}
35093505

3510-
#[mz_ore::test(tokio::test)]
3511-
#[cfg_attr(miri, ignore)] // unsupported operation: can't call foreign function `TLS_client_method` on OS `linux`
3512-
async fn test_builtin_migrations() {
3513-
let persist_client = PersistClient::new_for_tests().await;
3514-
let bootstrap_args = test_bootstrap_args();
3515-
let organization_id = Uuid::new_v4();
3516-
let mv_name = "mv";
3517-
let (mz_tables_id, mv_id) = {
3518-
let mut catalog = Catalog::open_debug_catalog(
3519-
persist_client.clone(),
3520-
organization_id.clone(),
3521-
&bootstrap_args,
3522-
)
3523-
.await
3524-
.expect("unable to open debug catalog");
3525-
3526-
// Create a materialized view over `mz_tables`.
3527-
let database_id = DatabaseId::User(1);
3528-
let database = catalog.get_database(&database_id);
3529-
let database_name = database.name();
3530-
let schemas = database.schemas();
3531-
let schema = schemas.first().expect("must have at least one schema");
3532-
let schema_spec = schema.id().clone();
3533-
let schema_name = &schema.name().schema;
3534-
let database_spec = ResolvedDatabaseSpecifier::Id(database_id);
3535-
let id_ts = catalog.storage().await.current_upper().await;
3536-
let (mv_id, mv_gid) = catalog
3537-
.allocate_user_id(id_ts)
3538-
.await
3539-
.expect("unable to allocate id");
3540-
let mv = catalog
3541-
.state()
3542-
.deserialize_item(
3543-
mv_gid,
3544-
&format!("CREATE MATERIALIZED VIEW {database_name}.{schema_name}.{mv_name} AS SELECT name FROM mz_tables"),
3545-
&BTreeMap::new(),
3546-
&mut LocalExpressionCache::Closed,
3547-
None,
3548-
)
3549-
.expect("unable to deserialize item");
3550-
let commit_ts = catalog.current_upper().await;
3551-
catalog
3552-
.transact(
3553-
None,
3554-
commit_ts,
3555-
None,
3556-
vec![Op::CreateItem {
3557-
id: mv_id,
3558-
name: QualifiedItemName {
3559-
qualifiers: ItemQualifiers {
3560-
database_spec,
3561-
schema_spec,
3562-
},
3563-
item: mv_name.to_string(),
3564-
},
3565-
item: mv,
3566-
owner_id: MZ_SYSTEM_ROLE_ID,
3567-
}],
3568-
)
3569-
.await
3570-
.expect("unable to transact");
3571-
3572-
let mz_tables_id = catalog
3573-
.entries()
3574-
.find(|entry| &entry.name.item == "mz_tables" && entry.is_table())
3575-
.expect("mz_tables doesn't exist")
3576-
.id();
3577-
let check_mv_id = catalog
3578-
.entries()
3579-
.find(|entry| &entry.name.item == mv_name && entry.is_materialized_view())
3580-
.unwrap_or_else(|| panic!("{mv_name} doesn't exist"))
3581-
.id();
3582-
assert_eq!(check_mv_id, mv_id);
3583-
catalog.expire().await;
3584-
(mz_tables_id, mv_id)
3585-
};
3586-
// Forcibly migrate all tables.
3587-
{
3588-
let mut guard =
3589-
UNSAFE_DO_NOT_CALL_THIS_IN_PRODUCTION_BUILTIN_TABLE_FINGERPRINT_WHITESPACE
3590-
.lock()
3591-
.expect("lock poisoned");
3592-
*guard = Some((
3593-
UnsafeBuiltinTableFingerprintWhitespace::All,
3594-
"\n".to_string(),
3595-
));
3596-
}
3597-
{
3598-
let catalog =
3599-
Catalog::open_debug_catalog(persist_client, organization_id, &bootstrap_args)
3600-
.await
3601-
.expect("unable to open debug catalog");
3602-
3603-
let new_mz_tables_id = catalog
3604-
.entries()
3605-
.find(|entry| &entry.name.item == "mz_tables" && entry.is_table())
3606-
.expect("mz_tables doesn't exist")
3607-
.id();
3608-
// Assert that the table was migrated and got a new ID.
3609-
assert_ne!(new_mz_tables_id, mz_tables_id);
3610-
3611-
let new_mv_id = catalog
3612-
.entries()
3613-
.find(|entry| &entry.name.item == mv_name && entry.is_materialized_view())
3614-
.unwrap_or_else(|| panic!("{mv_name} doesn't exist"))
3615-
.id();
3616-
// Assert that the materialized view was migrated and got a new ID.
3617-
assert_ne!(new_mv_id, mv_id);
3618-
3619-
catalog.expire().await;
3620-
}
3621-
}
3622-
36233506
#[mz_ore::test(tokio::test)]
36243507
#[cfg_attr(miri, ignore)] // unsupported operation: can't call foreign function `TLS_client_method` on OS `linux`
36253508
async fn test_multi_subscriber_catalog() {

0 commit comments

Comments
 (0)