Skip to content

Commit

Permalink
turn Timeline::layers into tokio::sync::RwLock
Browse files Browse the repository at this point in the history
  • Loading branch information
problame committed May 26, 2023
1 parent 7de3799 commit 2001c31
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 124 deletions.
2 changes: 1 addition & 1 deletion pageserver/src/disk_usage_eviction_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ async fn collect_eviction_candidates(
if !tl.is_active() {
continue;
}
let info = tl.get_local_layers_for_disk_usage_eviction();
let info = tl.get_local_layers_for_disk_usage_eviction().await;
debug!(tenant_id=%tl.tenant_id, timeline_id=%tl.timeline_id, "timeline resident layers count: {}", info.resident_layers.len());
tenant_candidates.extend(
info.resident_layers
Expand Down
11 changes: 6 additions & 5 deletions pageserver/src/http/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ async fn build_timeline_info(
) -> anyhow::Result<TimelineInfo> {
crate::tenant::debug_assert_current_span_has_tenant_and_timeline_id();

let mut info = build_timeline_info_common(timeline, ctx)?;
let mut info = build_timeline_info_common(timeline, ctx).await?;
if include_non_incremental_logical_size {
// XXX we should be using spawn_ondemand_logical_size_calculation here.
// Otherwise, if someone deletes the timeline / detaches the tenant while
Expand All @@ -198,7 +198,7 @@ async fn build_timeline_info(
Ok(info)
}

fn build_timeline_info_common(
async fn build_timeline_info_common(
timeline: &Arc<Timeline>,
ctx: &RequestContext,
) -> anyhow::Result<TimelineInfo> {
Expand Down Expand Up @@ -229,7 +229,7 @@ fn build_timeline_info_common(
None
}
};
let current_physical_size = Some(timeline.layer_size_sum());
let current_physical_size = Some(timeline.layer_size_sum().await);
let state = timeline.current_state();
let remote_consistent_lsn = timeline.get_remote_consistent_lsn().unwrap_or(Lsn(0));

Expand Down Expand Up @@ -291,6 +291,7 @@ async fn timeline_create_handler(mut request: Request<Body>) -> Result<Response<
Ok(Some(new_timeline)) => {
// Created. Construct a TimelineInfo for it.
let timeline_info = build_timeline_info_common(&new_timeline, &ctx)
.await
.map_err(ApiError::InternalServerError)?;
json_response(StatusCode::CREATED, timeline_info)
}
Expand Down Expand Up @@ -522,7 +523,7 @@ async fn tenant_status(request: Request<Body>) -> Result<Response<Body>, ApiErro
// Calculate total physical size of all timelines
let mut current_physical_size = 0;
for timeline in tenant.list_timelines().await.iter() {
current_physical_size += timeline.layer_size_sum();
current_physical_size += timeline.layer_size_sum().await;
}

let state = tenant.current_state();
Expand Down Expand Up @@ -627,7 +628,7 @@ async fn layer_map_info_handler(request: Request<Body>) -> Result<Response<Body>
check_permission(&request, Some(tenant_id))?;

let timeline = active_timeline_of_active_tenant(tenant_id, timeline_id).await?;
let layer_map_info = timeline.layer_map_info(reset);
let layer_map_info = timeline.layer_map_info(reset).await;

json_response(StatusCode::OK, layer_map_info)
}
Expand Down
6 changes: 3 additions & 3 deletions pageserver/src/pgdatadir_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ impl<'a> DatadirModification<'a> {

let writer = self.tline.writer().await;

let mut layer_map = self.tline.layers.write().unwrap();
let mut layer_map = self.tline.layers.write().await;

// Flush relation and SLRU data blocks, keep metadata.
let mut result: anyhow::Result<()> = Ok(());
Expand Down Expand Up @@ -1152,10 +1152,10 @@ impl<'a> DatadirModification<'a> {
self.pending_nblocks = 0;

for (key, value) in self.pending_updates.drain() {
writer.put(key, lsn, &value)?;
writer.put(key, lsn, &value).await?;
}
for key_range in self.pending_deletions.drain(..) {
writer.delete(key_range, lsn)?;
writer.delete(key_range, lsn).await?;
}

writer.finish_write(lsn);
Expand Down
Loading

0 comments on commit 2001c31

Please sign in to comment.