Skip to content

Commit

Permalink
load_layer_map: schedule deletions for any future layers (#5103)
Browse files Browse the repository at this point in the history
Unrelated fixes noticed while integrating #4938.

- Stop leaking future layers in remote storage
- We schedule extra index_part uploads if layer name to be removed was
not actually present
  • Loading branch information
koivunej authored and arpad-m committed Aug 28, 2023
1 parent 8257bc1 commit d698189
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
5 changes: 3 additions & 2 deletions pageserver/src/tenant/remote_timeline_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,9 @@ impl RemoteTimelineClient {
// to syntactically forbid ? or bail! calls here.
let no_bail_here = || {
for name in names {
upload_queue.latest_files.remove(name);
upload_queue.latest_files_changes_since_metadata_upload_scheduled += 1;
if upload_queue.latest_files.remove(name).is_some() {
upload_queue.latest_files_changes_since_metadata_upload_scheduled += 1;
}
}

if upload_queue.latest_files_changes_since_metadata_upload_scheduled > 0 {
Expand Down
19 changes: 11 additions & 8 deletions pageserver/src/tenant/timeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1615,7 +1615,7 @@ impl Timeline {
let (conf, tenant_id, timeline_id) = (self.conf, self.tenant_id, self.timeline_id);
let span = tracing::Span::current();

let (loaded_layers, needs_upload, total_physical_size) = tokio::task::spawn_blocking({
let (loaded_layers, to_sync, total_physical_size) = tokio::task::spawn_blocking({
move || {
let _g = span.entered();
let discovered = init::scan_timeline_dir(&timeline_path)?;
Expand Down Expand Up @@ -1661,6 +1661,7 @@ impl Timeline {

let mut loaded_layers = Vec::new();
let mut needs_upload = Vec::new();
let mut needs_cleanup = Vec::new();
let mut total_physical_size = 0;

for (name, decision) in decided {
Expand All @@ -1676,14 +1677,10 @@ impl Timeline {
Err(FutureLayer { local }) => {
if local.is_some() {
path.push(name.file_name());
init::cleanup_future_layer(&path, name, disk_consistent_lsn)?;
init::cleanup_future_layer(&path, &name, disk_consistent_lsn)?;
path.pop();
} else {
// we cannot do anything for remote layers, but not continuing to
// process it will leave it out index_part.json as well.
}
//
// we do not currently schedule deletions for these.
needs_cleanup.push(name);
continue;
}
};
Expand Down Expand Up @@ -1737,7 +1734,11 @@ impl Timeline {

loaded_layers.push(layer);
}
Ok((loaded_layers, needs_upload, total_physical_size))
Ok((
loaded_layers,
(needs_upload, needs_cleanup),
total_physical_size,
))
}
})
.await
Expand All @@ -1749,9 +1750,11 @@ impl Timeline {
guard.initialize_local_layers(loaded_layers, disk_consistent_lsn + 1);

if let Some(rtc) = self.remote_client.as_ref() {
let (needs_upload, needs_cleanup) = to_sync;
for (layer, m) in needs_upload {
rtc.schedule_layer_file_upload(&layer.layer_desc().filename(), &m)?;
}
rtc.schedule_layer_file_deletion(&needs_cleanup)?;
rtc.schedule_index_upload_for_file_changes()?;
// Tenant::create_timeline will wait for these uploads to happen before returning, or
// on retry.
Expand Down
2 changes: 1 addition & 1 deletion pageserver/src/tenant/timeline/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ pub(super) fn cleanup_local_file_for_remote(

pub(super) fn cleanup_future_layer(
path: &Path,
name: LayerFileName,
name: &LayerFileName,
disk_consistent_lsn: Lsn,
) -> anyhow::Result<()> {
use LayerFileName::*;
Expand Down

0 comments on commit d698189

Please sign in to comment.