TLA Line data Source code
1 : //! Helpers to do common higher-level tasks with the [`Client`].
2 :
3 : use std::sync::Arc;
4 :
5 : use tokio::task::JoinSet;
6 : use utils::id::{TenantId, TenantTimelineId};
7 :
8 : use super::Client;
9 :
10 : /// Retrieve a list of all of the pageserver's timelines.
11 : ///
12 : /// Fails if there are sharded tenants present on the pageserver.
13 UBC 0 : pub async fn get_pageserver_tenant_timelines_unsharded(
14 0 : api_client: &Arc<Client>,
15 0 : ) -> anyhow::Result<Vec<TenantTimelineId>> {
16 0 : let mut timelines: Vec<TenantTimelineId> = Vec::new();
17 0 : let mut tenants: Vec<TenantId> = Vec::new();
18 0 : for ti in api_client.list_tenants().await? {
19 0 : if !ti.id.is_unsharded() {
20 0 : anyhow::bail!(
21 0 : "only unsharded tenants are supported at this time: {}",
22 0 : ti.id
23 0 : );
24 0 : }
25 0 : tenants.push(ti.id.tenant_id)
26 : }
27 0 : let mut js = JoinSet::new();
28 0 : for tenant_id in tenants {
29 0 : js.spawn({
30 0 : let mgmt_api_client = Arc::clone(api_client);
31 0 : async move {
32 0 : (
33 0 : tenant_id,
34 0 : mgmt_api_client.tenant_details(tenant_id).await.unwrap(),
35 0 : )
36 0 : }
37 0 : });
38 0 : }
39 0 : while let Some(res) = js.join_next().await {
40 0 : let (tenant_id, details) = res.unwrap();
41 0 : for timeline_id in details.timelines {
42 0 : timelines.push(TenantTimelineId {
43 0 : tenant_id,
44 0 : timeline_id,
45 0 : });
46 0 : }
47 : }
48 0 : Ok(timelines)
49 0 : }
|