Skip to content

Commit

Permalink
Move load_timeline_metadata into separate function (#9080)
Browse files Browse the repository at this point in the history
Moves the per-timeline code to load timeline metadata into a new
dedicated function called `load_timeline_metadata`. The old
`load_timeline_metadata` becomes `load_timelines_metadata`.

Split out of #8907

Part of #8088
  • Loading branch information
arpad-m authored Sep 21, 2024
1 parent 9a32aa8 commit a3800dc
Showing 1 changed file with 38 additions and 36 deletions.
74 changes: 38 additions & 36 deletions pageserver/src/tenant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use camino::Utf8Path;
use camino::Utf8PathBuf;
use enumset::EnumSet;
use futures::stream::FuturesUnordered;
use futures::FutureExt;
use futures::StreamExt;
use pageserver_api::models;
use pageserver_api::models::AuxFilePolicy;
Expand All @@ -34,6 +33,7 @@ use remote_storage::GenericRemoteStorage;
use remote_storage::TimeoutOrCancel;
use std::collections::BTreeMap;
use std::fmt;
use std::future::Future;
use std::sync::Weak;
use std::time::SystemTime;
use storage_broker::BrokerClientChannel;
Expand Down Expand Up @@ -1031,13 +1031,9 @@ impl Tenant {
}

Ok(TenantPreload {
timelines: Self::load_timeline_metadata(
self,
remote_timeline_ids,
remote_storage,
cancel,
)
.await?,
timelines: self
.load_timelines_metadata(remote_timeline_ids, remote_storage, cancel)
.await?,
})
}

Expand Down Expand Up @@ -1303,41 +1299,18 @@ impl Tenant {
.await
}

async fn load_timeline_metadata(
async fn load_timelines_metadata(
self: &Arc<Tenant>,
timeline_ids: HashSet<TimelineId>,
remote_storage: &GenericRemoteStorage,
cancel: CancellationToken,
) -> anyhow::Result<HashMap<TimelineId, TimelinePreload>> {
let mut part_downloads = JoinSet::new();
for timeline_id in timeline_ids {
let client = RemoteTimelineClient::new(
remote_storage.clone(),
self.deletion_queue_client.clone(),
self.conf,
self.tenant_shard_id,
timeline_id,
self.generation,
);
let cancel_clone = cancel.clone();
part_downloads.spawn(
async move {
debug!("starting index part download");

let index_part = client.download_index_file(&cancel_clone).await;

debug!("finished index part download");

Result::<_, anyhow::Error>::Ok(TimelinePreload {
client,
timeline_id,
index_part,
})
}
.map(move |res| {
res.with_context(|| format!("download index part for timeline {timeline_id}"))
})
.instrument(info_span!("download_index_part", %timeline_id)),
self.load_timeline_metadata(timeline_id, remote_storage.clone(), cancel_clone)
.instrument(info_span!("download_index_part", %timeline_id)),
);
}

Expand All @@ -1348,8 +1321,7 @@ impl Tenant {
next = part_downloads.join_next() => {
match next {
Some(result) => {
let preload_result = result.context("join preload task")?;
let preload = preload_result?;
let preload = result.context("join preload task")?;
timeline_preloads.insert(preload.timeline_id, preload);
},
None => {
Expand All @@ -1366,6 +1338,36 @@ impl Tenant {
Ok(timeline_preloads)
}

fn load_timeline_metadata(
self: &Arc<Tenant>,
timeline_id: TimelineId,
remote_storage: GenericRemoteStorage,
cancel: CancellationToken,
) -> impl Future<Output = TimelinePreload> {
let client = RemoteTimelineClient::new(
remote_storage.clone(),
self.deletion_queue_client.clone(),
self.conf,
self.tenant_shard_id,
timeline_id,
self.generation,
);
async move {
debug_assert_current_span_has_tenant_and_timeline_id();
debug!("starting index part download");

let index_part = client.download_index_file(&cancel).await;

debug!("finished index part download");

TimelinePreload {
client,
timeline_id,
index_part,
}
}
}

pub(crate) async fn apply_timeline_archival_config(
&self,
timeline_id: TimelineId,
Expand Down

1 comment on commit a3800dc

@github-actions
Copy link

@github-actions github-actions bot commented on a3800dc Sep 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5091 tests run: 4917 passed, 0 failed, 174 skipped (full report)


Flaky tests (10)

Postgres 17

Postgres 16

Postgres 15

  • test_ondemand_wal_download_in_replication_slot_funcs: release-x86-64

Postgres 14

Code coverage* (full report)

  • functions: 31.9% (7436 of 23316 functions)
  • lines: 49.9% (59923 of 120123 lines)

* collected from Rust tests only


The comment gets automatically updated with the latest test results
a3800dc at 2024-09-21T23:37:10.051Z :recycle:

Please sign in to comment.