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

pageserver: assert that uploads don't modify indexed layers #10228

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
22 changes: 22 additions & 0 deletions pageserver/src/tenant/remote_timeline_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1943,6 +1943,28 @@ impl RemoteTimelineClient {
return;
}

// Assert that we don't modify a layer that's referenced by the current index.
if cfg!(debug_assertions) {
let modified = match &task.op {
UploadOp::UploadLayer(layer, layer_metadata, _) => {
vec![(layer.layer_desc().layer_name(), layer_metadata.clone())]
}
UploadOp::Delete(delete) => delete.layers.clone(),
// These don't modify layers.
UploadOp::UploadMetadata { .. } => Vec::new(),
UploadOp::Barrier(_) => Vec::new(),
UploadOp::Shutdown => Vec::new(),
};
if let Ok(queue) = self.upload_queue.lock().unwrap().initialized_mut() {
for (name, metadata) in modified {
debug_assert!(
!queue.clean.0.references(&name, &metadata),
"layer {name} modified while referenced by index",
);
}
}
}

let upload_result: anyhow::Result<()> = match &task.op {
UploadOp::UploadLayer(ref layer, ref layer_metadata, mode) => {
if let Some(OpType::FlushDeletion) = mode {
Expand Down
11 changes: 11 additions & 0 deletions pageserver/src/tenant/remote_timeline_client/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ impl IndexPart {
pub(crate) fn example() -> Self {
Self::empty(TimelineMetadata::example())
}

/// Returns true if the index contains a reference to the given layer (i.e. file path).
///
/// TODO: either LayerName or PersistentLayerKey should probably contain information about the
/// shard and generation, instead of passing in LayerFileMetadata too.
pub fn references(&self, name: &LayerName, metadata: &LayerFileMetadata) -> bool {
let Some(index_metadata) = self.layer_metadata.get(name) else {
return false;
};
metadata.shard == index_metadata.shard && metadata.generation == index_metadata.generation
}
}

/// Metadata gathered for each of the layer files.
Expand Down
Loading