Skip to content

Commit

Permalink
Assert cluster_name on import
Browse files Browse the repository at this point in the history
  • Loading branch information
pcholakov committed Dec 1, 2024
1 parent 85a316b commit 05cf7ea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/worker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ impl Worker {
SnapshotRepository::create(
snapshots_options,
config.common.base_dir().join("pp-snapshots"),
config.common.cluster_name().to_owned(),
)
.await
.map_err(BuildError::SnapshotRepository)?,
Expand Down
11 changes: 11 additions & 0 deletions crates/worker/src/partition/snapshots/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ pub struct SnapshotRepository {
prefix: String,
/// Ingested snapshots staging location.
staging_dir: PathBuf,
/// Expected cluster name for the snapshots in this repository.
cluster_name: String,
}

/// S3 and other stores require a certain minimum size for the parts of a multipart upload. It is an
Expand Down Expand Up @@ -101,6 +103,7 @@ impl SnapshotRepository {
pub async fn create(
snapshots_options: &SnapshotsOptions,
staging_dir: PathBuf,
cluster_name: String,
) -> anyhow::Result<Option<SnapshotRepository>> {
let mut destination = if let Some(ref destination) = snapshots_options.destination {
Url::parse(destination).context("Failed parsing snapshot repository URL")?
Expand Down Expand Up @@ -160,6 +163,7 @@ impl SnapshotRepository {
destination,
prefix,
staging_dir,
cluster_name,
}))
}

Expand Down Expand Up @@ -414,6 +418,13 @@ impl SnapshotRepository {
));
}

if snapshot_metadata.cluster_name != self.cluster_name {
panic!("Snapshot does not match the cluster name of latest snapshot at destination in snapshot id {}! Expected: cluster name=\"{}\", found: \"{}\"",
snapshot_metadata.snapshot_id,
self.cluster_name,
snapshot_metadata.cluster_name);
}

// The snapshot ingest directory should be on the same filesystem as the partition store
// to minimize IO and disk space usage during import.
let snapshot_dir = TempDir::with_prefix_in(
Expand Down

0 comments on commit 05cf7ea

Please sign in to comment.