Skip to content
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

blue/green: Update items in the transaction all at once #26361

Merged
merged 3 commits into from
Apr 1, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/adapter/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ use mz_controller::clusters::{
use mz_controller_types::{ClusterId, ReplicaId};
use mz_expr::OptimizedMirRelationExpr;
use mz_ore::cast::CastFrom;
use mz_ore::collections::HashSet;
use mz_ore::instrument;
use mz_ore::metrics::MetricsRegistry;
use mz_ore::now::{EpochMillis, NowFn};
Expand Down Expand Up @@ -2478,10 +2477,10 @@ impl Catalog {
let database_name = &database.name;

let mut updates = Vec::new();
let mut already_updated = HashSet::new();
let mut items_to_update = BTreeMap::new();

let mut update_item = |id| {
if already_updated.contains(id) {
if items_to_update.contains_key(id) {
return Ok(());
}

Expand All @@ -2504,14 +2503,11 @@ impl Catalog {

// Update the catalog storage and Builtin Tables.
ParkMyCar marked this conversation as resolved.
Show resolved Hide resolved
if !new_entry.item().is_temporary() {
tx.update_item(*id, new_entry.clone().into())?;
items_to_update.insert(*id, new_entry.clone().into());
}
builtin_table_updates.extend(state.pack_item_update(*id, -1));
updates.push((id.clone(), entry.name().clone(), new_entry.item));

// Track which IDs we update.
already_updated.insert(id);

Ok::<_, AdapterError>(())
};

Expand All @@ -2525,6 +2521,9 @@ impl Catalog {
update_item(id)?;
}
}
// Note: When updating the transaction it's very important that we update the
// items as a whole group, otherwise we exhibit quadratic behavior.
tx.update_items(items_to_update)?;

// Renaming temporary schemas is not supported.
let SchemaSpecifier::Id(schema_id) = *schema.id() else {
Expand Down