Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/adapter/src/catalog/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1430,8 +1430,14 @@ fn remove_invalid_config_param_role_defaults_migration(
Ok(())
}

/// Cluster Replicas may be created ephemerally during an alter statement, these replicas
/// are marked as pending and should be cleaned up on catalog open.
/// Drops replicas left durably marked `pending`.
///
/// No runtime path creates one anymore. An upgrade can still come from a version
/// whose staged reconfiguration machine crashed between the pending-create commit
/// and the finalize, and those replicas are excluded from the cluster
/// controller's ownership test, so this catalog-open sweep is their only
/// remaining cleaner. It goes away together with the durable `pending` field,
/// once no supported upgrade source can still write one.
fn remove_pending_cluster_replicas_migration(
tx: &mut Transaction,
boot_ts: mz_repr::Timestamp,
Expand Down
30 changes: 3 additions & 27 deletions src/adapter/src/coord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ use mz_catalog::config::{AwsPrincipalContext, BuiltinItemMigrationConfig, Cluste
use mz_catalog::durable::OpenableDurableCatalogState;
use mz_catalog::expr_cache::{GlobalExpressions, LocalExpressions};
use mz_catalog::memory::objects::{
CatalogEntry, CatalogItem, ClusterReplicaProcessStatus, ClusterVariantManaged, Connection,
DataSourceDesc, ReconfigurationTarget, Table, TableDataSource,
CatalogEntry, CatalogItem, ClusterReplicaProcessStatus, Connection, DataSourceDesc,
ReconfigurationTarget, Table, TableDataSource,
};
use mz_cloud_resources::{CloudResourceController, VpcEndpointConfig, VpcEndpointEvent};
use mz_compute_client::as_of_selection;
Expand Down Expand Up @@ -153,7 +153,7 @@ use mz_sql::names::{QualifiedItemName, ResolvedIds, SchemaSpecifier};
use mz_sql::optimizer_metrics::OptimizerMetrics;
use mz_sql::plan::{
self, AlterSinkPlan, ConnectionDetails, CreateConnectionPlan, HirRelationExpr,
NetworkPolicyRule, OnTimeoutAction, Params, QueryWhen,
NetworkPolicyRule, Params, QueryWhen,
};
use mz_sql::session::user::User;
use mz_sql::session::vars::{MAX_CREDIT_CONSUMPTION_RATE, SystemVars, Var};
Expand Down Expand Up @@ -875,8 +875,6 @@ pub struct ExplainTimestampFinish {
#[derive(Debug)]
pub enum ClusterStage {
Alter(AlterCluster),
WaitForHydrated(AlterClusterWaitForHydrated),
Finalize(AlterClusterFinalize),
/// The foreground wait-shim over a controller-driven background
/// reconfiguration: poll the durable `reconfiguration` record until it
/// clears, then report success or timeout depending on whether the realized
Expand All @@ -890,24 +888,6 @@ pub struct AlterCluster {
plan: plan::AlterClusterPlan,
}

#[derive(Debug)]
pub struct AlterClusterWaitForHydrated {
validity: PlanValidity,
plan: plan::AlterClusterPlan,
new_config: ClusterVariantManaged,
workload_class: Option<String>,
timeout_time: Instant,
on_timeout: OnTimeoutAction,
}

#[derive(Debug)]
pub struct AlterClusterFinalize {
validity: PlanValidity,
plan: plan::AlterClusterPlan,
new_config: ClusterVariantManaged,
workload_class: Option<String>,
}

#[derive(Debug)]
pub struct AlterClusterAwaitReconfiguration {
validity: PlanValidity,
Expand Down Expand Up @@ -1312,10 +1292,6 @@ pub struct ConnMeta {
#[serde(skip)]
deferred_lock: Option<OwnedMutexGuard<()>>,

/// Cluster reconfigurations that will need to be
/// cleaned up when the current transaction is cleared
pending_cluster_alters: BTreeSet<ClusterId>,

/// Channel on which to send notices to a session.
#[serde(skip)]
notice_tx: mpsc::UnboundedSender<AdapterNotice>,
Expand Down
6 changes: 5 additions & 1 deletion src/adapter/src/coord/cluster_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,11 @@ impl Coordinator {

/// Build the controller's view of one managed cluster from the catalog.
/// Returns `None` for a missing or unmanaged cluster.
fn observe_cluster_state(&self, cluster_id: ClusterId) -> Option<ClusterState> {
///
/// Also used by the ALTER sequencer's synchronous cut-over, which runs the
/// controller's reconcile kernel against this same view so both paths
/// converge on the same replica set.
pub(crate) fn observe_cluster_state(&self, cluster_id: ClusterId) -> Option<ClusterState> {
let cluster = self.catalog().try_get_cluster(cluster_id)?;
let ClusterVariant::Managed(managed) = &cluster.config.variant else {
return None;
Expand Down
3 changes: 0 additions & 3 deletions src/adapter/src/coord/command_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,6 @@ impl Coordinator {
secret_key,
notice_tx,
drop_sinks: BTreeSet::new(),
pending_cluster_alters: BTreeSet::new(),
connected_at: self.now(),
user,
application_name,
Expand Down Expand Up @@ -1984,8 +1983,6 @@ impl Coordinator {
// SQL cancellation has no success response to delay. Each subscribe
// still waits for its own retraction before it observes retirement.
drop(retire_notify);
self.cancel_cluster_reconfigurations_for_conn(&conn_id)
.await;
self.cancel_pending_copy(&conn_id);
if let Some((tx, _rx)) = self.connection_cancel_watches.get_mut(&conn_id) {
let _ = tx.send(true);
Expand Down
72 changes: 1 addition & 71 deletions src/adapter/src/coord/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use serde_json::json;
use tracing::{Instrument, Level, event, info_span, warn};

use crate::active_compute_sink::{ActiveComputeSink, ActiveComputeSinkRetireReason};
use crate::catalog::{DropObjectInfo, Op, ReplicaCreateDropReason, TransactionResult};
use crate::catalog::{DropObjectInfo, Op, TransactionResult};
use crate::coord::Coordinator;
use crate::coord::appends::{BuiltinTableAppendCompletion, BuiltinTableAppendNotify};
use crate::coord::catalog_implications::parsed_state_updates::ParsedStateUpdate;
Expand Down Expand Up @@ -859,43 +859,6 @@ impl Coordinator {
}))
}

/// Drops all pending replicas for a set of clusters
/// that are undergoing reconfiguration.
pub async fn drop_reconfiguration_replicas(
&mut self,
cluster_ids: BTreeSet<ClusterId>,
) -> Result<(), AdapterError> {
let pending_cluster_ops: Vec<Op> = cluster_ids
.iter()
.map(|c| {
self.catalog()
.get_cluster(c.clone())
.replicas()
.filter_map(|r| match r.config.location {
ReplicaLocation::Managed(ref l) if l.pending => {
Some(DropObjectInfo::ClusterReplica((
c.clone(),
r.replica_id,
ReplicaCreateDropReason::Manual,
)))
}
_ => None,
})
.collect::<Vec<DropObjectInfo>>()
})
.filter_map(|pending_replica_drop_ops_by_cluster| {
match pending_replica_drop_ops_by_cluster.len() {
0 => None,
_ => Some(Op::DropObjects(pending_replica_drop_ops_by_cluster)),
}
})
.collect();
if !pending_cluster_ops.is_empty() {
self.catalog_transact(None, pending_cluster_ops).await?;
}
Ok(())
}

/// Cancels all active compute sinks for the identified connection.
#[mz_ore::instrument(level = "debug")]
pub(crate) async fn cancel_compute_sinks_for_conn(
Expand All @@ -906,15 +869,6 @@ impl Coordinator {
.await
}

/// Cancels all active cluster reconfigurations sinks for the identified connection.
#[mz_ore::instrument(level = "debug")]
pub(crate) async fn cancel_cluster_reconfigurations_for_conn(
&mut self,
conn_id: &ConnectionId,
) {
self.retire_cluster_reconfigurations_for_conn(conn_id).await
}

/// Retires all active compute sinks for the identified connection with the
/// specified reason.
#[mz_ore::instrument(level = "debug")]
Expand All @@ -934,30 +888,6 @@ impl Coordinator {
self.retire_compute_sinks(drop_sinks).await
}

/// Cleans pending cluster reconfiguraiotns for the identified connection
#[mz_ore::instrument(level = "debug")]
pub(crate) async fn retire_cluster_reconfigurations_for_conn(
&mut self,
conn_id: &ConnectionId,
) {
let reconfiguring_clusters = self
.active_conns
.get(conn_id)
.expect("must exist for active session")
.pending_cluster_alters
.clone();
// try to drop reconfig replicas
self.drop_reconfiguration_replicas(reconfiguring_clusters)
.await
.unwrap_or_terminate("cannot fail to drop reconfiguration replicas");

self.active_conns
.get_mut(conn_id)
.expect("must exist for active session")
.pending_cluster_alters
.clear();
}

pub(crate) fn drop_storage_sinks(&mut self, sink_gids: Vec<GlobalId>) {
let storage_metadata = self.catalog.state().storage_metadata();
self.controller
Expand Down
Loading
Loading