diff --git a/svc/pkg/cluster/ops/datacenter-get/src/lib.rs b/svc/pkg/cluster/ops/datacenter-get/src/lib.rs index d2b43a1b4..12d2cc7b4 100644 --- a/svc/pkg/cluster/ops/datacenter-get/src/lib.rs +++ b/svc/pkg/cluster/ops/datacenter-get/src/lib.rs @@ -48,6 +48,32 @@ pub async fn handle( .map(common::Uuid::as_uuid) .collect::>(); + let datacenters = ctx + .cache() + .fetch_all_proto("cluster.datacenters", datacenter_ids, { + let ctx = ctx.base(); + move |mut cache, datacenter_ids| { + let ctx = ctx.clone(); + async move { + let dcs = get_dcs(ctx, datacenter_ids).await?; + for dc in dcs { + let dc_id = unwrap!(dc.datacenter_id).as_uuid(); + cache.resolve(&dc_id, dc); + } + + Ok(cache) + } + } + }) + .await?; + + Ok(cluster::datacenter_get::Response { datacenters }) +} + +async fn get_dcs( + ctx: OperationContext<()>, + datacenter_ids: Vec, +) -> GlobalResult> { let configs = sql_fetch_all!( [ctx, Datacenter] " @@ -69,10 +95,10 @@ pub async fn handle( ) .await?; - Ok(cluster::datacenter_get::Response { - datacenters: configs - .into_iter() - .map(TryInto::try_into) - .collect::>>()?, - }) + let datacenters = configs + .into_iter() + .map(TryInto::try_into) + .collect::>>()?; + + Ok(datacenters) } diff --git a/svc/pkg/cluster/ops/datacenter-location-get/src/lib.rs b/svc/pkg/cluster/ops/datacenter-location-get/src/lib.rs index aeeedf233..86ebbca11 100644 --- a/svc/pkg/cluster/ops/datacenter-location-get/src/lib.rs +++ b/svc/pkg/cluster/ops/datacenter-location-get/src/lib.rs @@ -14,6 +14,32 @@ pub async fn handle( .map(common::Uuid::as_uuid) .collect::>(); + let datacenters = ctx + .cache() + .fetch_all_proto("cluster.datacenters.location", datacenter_ids, { + let ctx = ctx.base(); + move |mut cache, datacenter_ids| { + let ctx = ctx.clone(); + async move { + let dcs = query_dcs(ctx, datacenter_ids).await?; + for dc in dcs { + let dc_id = unwrap!(dc.datacenter_id).as_uuid(); + cache.resolve(&dc_id, dc); + } + + Ok(cache) + } + } + }) + .await?; + + Ok(cluster::datacenter_location_get::Response { datacenters }) +} + +async fn query_dcs( + ctx: OperationContext<()>, + datacenter_ids: Vec, +) -> GlobalResult> { // NOTE: if there is no active GG node in a datacenter, we cannot retrieve its location // Fetch the gg node public ip for each datacenter (there may be more than one, hence `DISTINCT`) let server_rows = sql_fetch_all!( @@ -62,15 +88,13 @@ pub async fn handle( .try_collect::>() .await?; - Ok(cluster::datacenter_location_get::Response { - datacenters: coords_res - .into_iter() - .map( - |(datacenter_id, coords)| cluster::datacenter_location_get::response::Datacenter { - datacenter_id: Some(datacenter_id.into()), - coords, - }, - ) - .collect::>(), - }) + Ok(coords_res + .into_iter() + .map( + |(datacenter_id, coords)| cluster::datacenter_location_get::response::Datacenter { + datacenter_id: Some(datacenter_id.into()), + coords, + }, + ) + .collect::>()) } diff --git a/svc/pkg/cluster/worker/src/workers/datacenter_scale.rs b/svc/pkg/cluster/worker/src/workers/datacenter_scale.rs index 877766d2d..5a16b9484 100644 --- a/svc/pkg/cluster/worker/src/workers/datacenter_scale.rs +++ b/svc/pkg/cluster/worker/src/workers/datacenter_scale.rs @@ -213,6 +213,8 @@ async fn scale_servers( .filter(|server| matches!(server.drain_state, DrainState::None)); let active_count = active_servers_in_pool.clone().count(); + tracing::info!(desired=%pctx.desired_count, active=%active_count, "comparing {:?}", pctx.pool_type); + match pctx.desired_count.cmp(&active_count) { Ordering::Less => match pctx.pool_type { backend::cluster::PoolType::Job => { diff --git a/svc/pkg/cluster/worker/src/workers/datacenter_update.rs b/svc/pkg/cluster/worker/src/workers/datacenter_update.rs index 9b819e1ca..0bf29fb4a 100644 --- a/svc/pkg/cluster/worker/src/workers/datacenter_update.rs +++ b/svc/pkg/cluster/worker/src/workers/datacenter_update.rs @@ -64,6 +64,11 @@ async fn worker( ) .await?; + // Purge cache + ctx.cache() + .purge("cluster.datacenters", [datacenter_id]) + .await?; + msg!([ctx] cluster::msg::datacenter_scale(datacenter_id) { datacenter_id: ctx.datacenter_id, })