mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-16 09:52:54 +00:00
## Problem The logic in Service::optimize_all would sometimes choose to migrate a tenant to a secondary location that was only recently created, resulting in Reconciler::live_migrate hitting its 5 minute timeout warming up the location, and proceeding to attach a tenant to a location that doesn't have a warm enough local set of layer files for good performance. Closes: #7532 ## Summary of changes - Add a pageserver API for checking download progress of a secondary location - During `optimize_all`, connect to pageservers of candidate optimization secondary locations, and check they are warm. - During shard split, do heatmap uploads and start secondary downloads, so that the new shards' secondary locations start downloading ASAP, rather than waiting minutes for background downloads to kick in. I have intentionally not implemented this by continuously reading the status of locations, to avoid dealing with the scale challenge of efficiently polling & updating 10k-100k locations status. If we implement that in the future, then this code can be simplified to act based on latest state of a location rather than fetching it inline during optimize_all.
238 lines
7.1 KiB
Rust
238 lines
7.1 KiB
Rust
use pageserver_api::{
|
|
models::{
|
|
LocationConfig, LocationConfigListResponse, PageserverUtilization, SecondaryProgress,
|
|
TenantScanRemoteStorageResponse, TenantShardSplitRequest, TenantShardSplitResponse,
|
|
TimelineCreateRequest, TimelineInfo,
|
|
},
|
|
shard::TenantShardId,
|
|
};
|
|
use pageserver_client::mgmt_api::{Client, Result};
|
|
use reqwest::StatusCode;
|
|
use utils::id::{NodeId, TenantId, TimelineId};
|
|
|
|
/// Thin wrapper around [`pageserver_client::mgmt_api::Client`]. It allows the storage
|
|
/// controller to collect metrics in a non-intrusive manner.
|
|
#[derive(Debug, Clone)]
|
|
pub(crate) struct PageserverClient {
|
|
inner: Client,
|
|
node_id_label: String,
|
|
}
|
|
|
|
macro_rules! measured_request {
|
|
($name:literal, $method:expr, $node_id: expr, $invoke:expr) => {{
|
|
let labels = crate::metrics::PageserverRequestLabelGroup {
|
|
pageserver_id: $node_id,
|
|
path: $name,
|
|
method: $method,
|
|
};
|
|
|
|
let latency = &crate::metrics::METRICS_REGISTRY
|
|
.metrics_group
|
|
.storage_controller_pageserver_request_latency;
|
|
let _timer_guard = latency.start_timer(labels.clone());
|
|
|
|
let res = $invoke;
|
|
|
|
if res.is_err() {
|
|
let error_counters = &crate::metrics::METRICS_REGISTRY
|
|
.metrics_group
|
|
.storage_controller_pageserver_request_error;
|
|
error_counters.inc(labels)
|
|
}
|
|
|
|
res
|
|
}};
|
|
}
|
|
|
|
impl PageserverClient {
|
|
pub(crate) fn new(node_id: NodeId, mgmt_api_endpoint: String, jwt: Option<&str>) -> Self {
|
|
Self {
|
|
inner: Client::from_client(reqwest::Client::new(), mgmt_api_endpoint, jwt),
|
|
node_id_label: node_id.0.to_string(),
|
|
}
|
|
}
|
|
|
|
pub(crate) fn from_client(
|
|
node_id: NodeId,
|
|
raw_client: reqwest::Client,
|
|
mgmt_api_endpoint: String,
|
|
jwt: Option<&str>,
|
|
) -> Self {
|
|
Self {
|
|
inner: Client::from_client(raw_client, mgmt_api_endpoint, jwt),
|
|
node_id_label: node_id.0.to_string(),
|
|
}
|
|
}
|
|
|
|
pub(crate) async fn tenant_delete(&self, tenant_shard_id: TenantShardId) -> Result<StatusCode> {
|
|
measured_request!(
|
|
"tenant",
|
|
crate::metrics::Method::Delete,
|
|
&self.node_id_label,
|
|
self.inner.tenant_delete(tenant_shard_id).await
|
|
)
|
|
}
|
|
|
|
pub(crate) async fn tenant_time_travel_remote_storage(
|
|
&self,
|
|
tenant_shard_id: TenantShardId,
|
|
timestamp: &str,
|
|
done_if_after: &str,
|
|
) -> Result<()> {
|
|
measured_request!(
|
|
"tenant_time_travel_remote_storage",
|
|
crate::metrics::Method::Put,
|
|
&self.node_id_label,
|
|
self.inner
|
|
.tenant_time_travel_remote_storage(tenant_shard_id, timestamp, done_if_after)
|
|
.await
|
|
)
|
|
}
|
|
|
|
pub(crate) async fn tenant_scan_remote_storage(
|
|
&self,
|
|
tenant_id: TenantId,
|
|
) -> Result<TenantScanRemoteStorageResponse> {
|
|
measured_request!(
|
|
"tenant_scan_remote_storage",
|
|
crate::metrics::Method::Get,
|
|
&self.node_id_label,
|
|
self.inner.tenant_scan_remote_storage(tenant_id).await
|
|
)
|
|
}
|
|
|
|
pub(crate) async fn tenant_secondary_download(
|
|
&self,
|
|
tenant_id: TenantShardId,
|
|
wait: Option<std::time::Duration>,
|
|
) -> Result<(StatusCode, SecondaryProgress)> {
|
|
measured_request!(
|
|
"tenant_secondary_download",
|
|
crate::metrics::Method::Post,
|
|
&self.node_id_label,
|
|
self.inner.tenant_secondary_download(tenant_id, wait).await
|
|
)
|
|
}
|
|
|
|
pub(crate) async fn tenant_secondary_status(
|
|
&self,
|
|
tenant_shard_id: TenantShardId,
|
|
) -> Result<SecondaryProgress> {
|
|
measured_request!(
|
|
"tenant_secondary_status",
|
|
crate::metrics::Method::Get,
|
|
&self.node_id_label,
|
|
self.inner.tenant_secondary_status(tenant_shard_id).await
|
|
)
|
|
}
|
|
|
|
pub(crate) async fn tenant_heatmap_upload(&self, tenant_id: TenantShardId) -> Result<()> {
|
|
measured_request!(
|
|
"tenant_heatmap_upload",
|
|
crate::metrics::Method::Post,
|
|
&self.node_id_label,
|
|
self.inner.tenant_heatmap_upload(tenant_id).await
|
|
)
|
|
}
|
|
|
|
pub(crate) async fn location_config(
|
|
&self,
|
|
tenant_shard_id: TenantShardId,
|
|
config: LocationConfig,
|
|
flush_ms: Option<std::time::Duration>,
|
|
lazy: bool,
|
|
) -> Result<()> {
|
|
measured_request!(
|
|
"location_config",
|
|
crate::metrics::Method::Put,
|
|
&self.node_id_label,
|
|
self.inner
|
|
.location_config(tenant_shard_id, config, flush_ms, lazy)
|
|
.await
|
|
)
|
|
}
|
|
|
|
pub(crate) async fn list_location_config(&self) -> Result<LocationConfigListResponse> {
|
|
measured_request!(
|
|
"location_configs",
|
|
crate::metrics::Method::Get,
|
|
&self.node_id_label,
|
|
self.inner.list_location_config().await
|
|
)
|
|
}
|
|
|
|
pub(crate) async fn get_location_config(
|
|
&self,
|
|
tenant_shard_id: TenantShardId,
|
|
) -> Result<Option<LocationConfig>> {
|
|
measured_request!(
|
|
"location_config",
|
|
crate::metrics::Method::Get,
|
|
&self.node_id_label,
|
|
self.inner.get_location_config(tenant_shard_id).await
|
|
)
|
|
}
|
|
|
|
pub(crate) async fn timeline_create(
|
|
&self,
|
|
tenant_shard_id: TenantShardId,
|
|
req: &TimelineCreateRequest,
|
|
) -> Result<TimelineInfo> {
|
|
measured_request!(
|
|
"timeline",
|
|
crate::metrics::Method::Post,
|
|
&self.node_id_label,
|
|
self.inner.timeline_create(tenant_shard_id, req).await
|
|
)
|
|
}
|
|
|
|
pub(crate) async fn timeline_delete(
|
|
&self,
|
|
tenant_shard_id: TenantShardId,
|
|
timeline_id: TimelineId,
|
|
) -> Result<StatusCode> {
|
|
measured_request!(
|
|
"timeline",
|
|
crate::metrics::Method::Delete,
|
|
&self.node_id_label,
|
|
self.inner
|
|
.timeline_delete(tenant_shard_id, timeline_id)
|
|
.await
|
|
)
|
|
}
|
|
|
|
pub(crate) async fn tenant_shard_split(
|
|
&self,
|
|
tenant_shard_id: TenantShardId,
|
|
req: TenantShardSplitRequest,
|
|
) -> Result<TenantShardSplitResponse> {
|
|
measured_request!(
|
|
"tenant_shard_split",
|
|
crate::metrics::Method::Put,
|
|
&self.node_id_label,
|
|
self.inner.tenant_shard_split(tenant_shard_id, req).await
|
|
)
|
|
}
|
|
|
|
pub(crate) async fn timeline_list(
|
|
&self,
|
|
tenant_shard_id: &TenantShardId,
|
|
) -> Result<Vec<TimelineInfo>> {
|
|
measured_request!(
|
|
"timelines",
|
|
crate::metrics::Method::Get,
|
|
&self.node_id_label,
|
|
self.inner.timeline_list(tenant_shard_id).await
|
|
)
|
|
}
|
|
|
|
pub(crate) async fn get_utilization(&self) -> Result<PageserverUtilization> {
|
|
measured_request!(
|
|
"utilization",
|
|
crate::metrics::Method::Get,
|
|
&self.node_id_label,
|
|
self.inner.get_utilization().await
|
|
)
|
|
}
|
|
}
|