Skip to content
Merged
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
29 changes: 19 additions & 10 deletions crates/metadb-cluster/src/cell_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,28 @@ impl DurableCellManager {
let _ = mgr.host.shutdown_all().await;
return Err(error);
}
if mgr.cluster_id() == 0 && mgr.replicated_membership() {
let _ = mgr.host.shutdown_all().await;
return Err(MetaDbError::IdentityRejected(
"legacy replicated cell directory has no shared CLUSTER_IDENTITY; refusing to invent a per-member cluster id"
.to_string(),
));
}
if let Err(error) = mgr.recover_incomplete_splits().await {
let _ = mgr.host.shutdown_all().await;
return Err(error);
}
if let Err(error) = mgr.ingest_engine_bindings() {
let _ = mgr.host.shutdown_all().await;
return Err(error);
}
if mgr.cluster_id() == 0 {
if mgr.replicated_membership() {
// A restored log already names this node's instance. Minting a new id
// would be rejected as a reused node identity.
if mgr.bound_instance(mgr.host.node_id()).is_some() {
let _ = mgr.host.shutdown_all().await;
return Err(MetaDbError::IdentityRejected(
"legacy replicated cell directory has no shared CLUSTER_IDENTITY; refusing to invent a per-member cluster id"
"CLUSTER_IDENTITY is missing but this node is already bound; refusing to mint a new instance id"
.to_string(),
));
}
Expand All @@ -299,14 +316,6 @@ impl DurableCellManager {
}
}
}
if let Err(error) = mgr.recover_incomplete_splits().await {
let _ = mgr.host.shutdown_all().await;
return Err(error);
}
if let Err(error) = mgr.ingest_engine_bindings() {
let _ = mgr.host.shutdown_all().await;
return Err(error);
}
if let Err(error) = mgr.bind_local_instance().await {
let _ = mgr.host.shutdown_all().await;
return Err(error);
Expand Down
23 changes: 23 additions & 0 deletions crates/metadb-raft/src/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,18 @@ fn copy_node_metadata(
files,
)?;
}
let identity = entry.path().join("CLUSTER_IDENTITY");
if !identity.is_file() {
return Err(backup_error(format!(
"{name}/CLUSTER_IDENTITY is missing; refusing a backup that cannot reopen this node's instance id"
)));
}
copy_verified_frame(
&identity,
&tree.join(&name).join("CLUSTER_IDENTITY"),
&format!("{name}/CLUSTER_IDENTITY"),
files,
)?;
cells += 1;
}
if cells == 0 {
Expand Down Expand Up @@ -1268,6 +1280,17 @@ fn validate_manifest_tree(tree: &Path, manifest: &BackupManifest) -> Result<()>
{
return Err(restore_error("CELL_MANAGER_STATE is missing"));
}
for file in &manifest.files {
if !(file.path.starts_with("cell_") && file.path.ends_with("/CELL_MANAGER_STATE")) {
continue;
}
let identity = file.path.replace("CELL_MANAGER_STATE", "CLUSTER_IDENTITY");
if !listed.contains(identity.as_str()) {
return Err(restore_error(format!(
"{identity} is missing; refusing a restore that would mint a new node instance id"
)));
}
}
for shard in &manifest.shards {
let prefix = format!("be/shards/{:020}", shard.shard_id);
let raft = tree
Expand Down
34 changes: 28 additions & 6 deletions crates/metadb-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,11 +705,22 @@ impl PersistentMetaDbCluster {
let bg_handle = tokio::spawn(async move {
loop {
tokio::select! {
biased;
_ = bg_rx.changed() => break,
_ = tokio::time::sleep(Duration::from_millis(250)) => {
let Some(c) = bg_cluster.upgrade() else { break; };
let _ = c.run_maintenance_tick_inner(false).await;
}
_ = tokio::time::sleep(Duration::from_millis(250)) => {}
}
if *bg_rx.borrow() {
break;
}
let Some(c) = bg_cluster.upgrade() else {
break;
};
// Drop an in-flight tick when shutdown is signaled. The tick proposes
// through Raft, and a missing voter can leave that proposal unable to commit.
tokio::select! {
biased;
_ = bg_rx.changed() => break,
_ = c.run_maintenance_tick_inner(false) => {}
Comment on lines +722 to +723
}
}
});
Expand Down Expand Up @@ -886,10 +897,21 @@ impl PersistentMetaDbCluster {
self.metrics_addr.get().map(String::as_str)
}

/// Gracefully stops gRPC/background loops, flushes all shard state to disk, and stops OpenRaft groups.
/// Stops gRPC and maintenance, drains auxiliary work, flushes memtables, and stops OpenRaft.
///
/// The drain proposes through Raft. After a peer is gone that proposal cannot commit,
/// so a stuck drain cannot pin process exit. Committed entries that are not in the
/// memtable flush stay in the Raft log and replay on the next open.
pub async fn shutdown(&self) -> Result<()> {
self.stop_tasks().await;
self.flush_all().await?;
match tokio::time::timeout(Duration::from_secs(10), self.flush_all()).await {
Ok(result) => result?,
Err(_) => {
for group in self.host.all_groups() {
group.state_machine().flush_to_lsm()?;
}
}
}
let result = self.host.shutdown_all().await;
backup::unregister_runtime(&self.config.node.data_dir);
result
Expand Down
Loading