Skip to content

Commit

Permalink
testdrive: Disable expr cache in consistency check
Browse files Browse the repository at this point in the history
This commit disables the expression cache in testdrive during catalog
consistency checks. We were noticing elevated CPU usage in testdrive
after merging the expression cache during catalog consistency checks.
The expression cache is still used by environmentd during testdrive
tests unless it's disabled.

Resolves #MaterializeInc/database-issues/8759
  • Loading branch information
jkosh44 committed Nov 19, 2024
1 parent 8954160 commit 3994f4b
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/adapter/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ impl Catalog {
environment_id,
system_parameter_defaults,
bootstrap_args,
None,
)
.await
}
Expand Down Expand Up @@ -580,6 +581,7 @@ impl Catalog {
environment_id,
system_parameter_defaults,
bootstrap_args,
None,
)
.await
}
Expand All @@ -595,6 +597,7 @@ impl Catalog {
system_parameter_defaults: BTreeMap<String, String>,
version: semver::Version,
bootstrap_args: &BootstrapArgs,
enable_expression_cache_override: Option<bool>,
) -> Result<Catalog, anyhow::Error> {
let openable_storage = TestCatalogStateBuilder::new(persist_client.clone())
.with_organization_id(environment_id.organization_id())
Expand All @@ -609,6 +612,7 @@ impl Catalog {
Some(environment_id),
system_parameter_defaults,
bootstrap_args,
enable_expression_cache_override,
)
.await
}
Expand All @@ -620,6 +624,7 @@ impl Catalog {
environment_id: Option<EnvironmentId>,
system_parameter_defaults: BTreeMap<String, String>,
bootstrap_args: &BootstrapArgs,
enable_expression_cache_override: Option<bool>,
) -> Result<Catalog, anyhow::Error> {
let metrics_registry = &MetricsRegistry::new();
let active_connection_count = Arc::new(std::sync::Mutex::new(ConnectionCounter::new(0, 0)));
Expand Down Expand Up @@ -665,6 +670,7 @@ impl Catalog {
active_connection_count,
builtin_item_migration_config: BuiltinItemMigrationConfig::Legacy,
persist_client,
enable_expression_cache_override,
helm_chart_version: None,
},
})
Expand Down
4 changes: 3 additions & 1 deletion src/adapter/src/catalog/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,9 @@ impl Catalog {
info!("startup: coordinator init: catalog open: expr cache open beginning");
// We wait until after the `pre_item_updates` to open the cache so we can get accurate
// dyncfgs because the `pre_item_updates` contains `SystemConfiguration` updates.
let expr_cache_enabled = ENABLE_EXPRESSION_CACHE.get(state.system_config().dyncfgs());
let expr_cache_enabled = config
.enable_expression_cache_override
.unwrap_or_else(|| ENABLE_EXPRESSION_CACHE.get(state.system_config().dyncfgs()));
let (expr_cache_handle, cached_local_exprs, cached_global_exprs) = if expr_cache_enabled {
info!("using expression cache for startup");
let current_ids = txn
Expand Down
1 change: 1 addition & 0 deletions src/adapter/src/coord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3858,6 +3858,7 @@ pub fn serve(
http_host_name,
builtin_item_migration_config,
persist_client: persist_client.clone(),
enable_expression_cache_override: None,
helm_chart_version,
},
})
Expand Down
1 change: 1 addition & 0 deletions src/catalog-debug/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ async fn upgrade_check(
active_connection_count: Arc::new(Mutex::new(ConnectionCounter::new(0, 0))),
builtin_item_migration_config: BuiltinItemMigrationConfig::Legacy,
persist_client,
enable_expression_cache_override: None,
helm_chart_version: None,
},
&mut storage,
Expand Down
3 changes: 3 additions & 0 deletions src/catalog/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ pub struct StateConfig {
pub active_connection_count: Arc<std::sync::Mutex<ConnectionCounter>>,
pub builtin_item_migration_config: BuiltinItemMigrationConfig,
pub persist_client: PersistClient,
/// Overrides the current value of the [`mz_adapter_types::dyncfgs::ENABLE_EXPRESSION_CACHE`]
/// feature flag.
pub enable_expression_cache_override: Option<bool>,
/// Helm chart version
pub helm_chart_version: Option<String>,
}
Expand Down
2 changes: 2 additions & 0 deletions src/testdrive/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ impl State {
system_parameter_defaults: BTreeMap<String, String>,
version: semver::Version,
bootstrap_args: &BootstrapArgs,
enable_expression_cache_override: Option<bool>,
f: F,
) -> Result<Option<T>, anyhow::Error>
where
Expand Down Expand Up @@ -394,6 +395,7 @@ impl State {
system_parameter_defaults,
version,
bootstrap_args,
enable_expression_cache_override,
)
.await?;
let res = f(catalog.for_session(&Session::dummy()));
Expand Down
2 changes: 2 additions & 0 deletions src/testdrive/src/action/consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ async fn check_catalog_state(state: &State) -> Result<(), anyhow::Error> {
system_parameter_defaults,
version,
&state.materialize.bootstrap_args,
// The expression cache can be taxing on the CPU and is unnecessary for consistency checks.
Some(false),
|catalog| catalog.state().clone(),
)
.await
Expand Down

0 comments on commit 3994f4b

Please sign in to comment.