diff --git a/libs/utils/src/sync/gate.rs b/libs/utils/src/sync/gate.rs index 1391d238e6..9aad0af22d 100644 --- a/libs/utils/src/sync/gate.rs +++ b/libs/utils/src/sync/gate.rs @@ -85,6 +85,13 @@ impl Gate { warn_if_stuck(self.do_close(), &self.name, Duration::from_millis(1000)).await } + /// Check if [`Self::close()`] has finished waiting for all [`Self::enter()`] users to finish. This + /// is usually analoguous for "Did shutdown finish?" for types that include a Gate, whereas checking + /// the CancellationToken on such types is analogous to "Did shutdown start?" + pub fn close_complete(&self) -> bool { + self.sem.is_closed() + } + async fn do_close(&self) { tracing::debug!(gate = self.name, "Closing Gate..."); match self.sem.acquire_many(Self::MAX_UNITS).await { diff --git a/pageserver/src/tenant/mgr.rs b/pageserver/src/tenant/mgr.rs index 27f9d50c54..07d1618272 100644 --- a/pageserver/src/tenant/mgr.rs +++ b/pageserver/src/tenant/mgr.rs @@ -1552,14 +1552,7 @@ impl SlotGuard { /// is responsible for protecting fn old_value_is_shutdown(&self) -> bool { match self.old_value.as_ref() { - Some(TenantSlot::Attached(tenant)) => { - // TODO: PR #5711 will add a gate that enables properly checking that - // shutdown completed. - matches!( - tenant.current_state(), - TenantState::Stopping { .. } | TenantState::Broken { .. } - ) - } + Some(TenantSlot::Attached(tenant)) => tenant.gate.close_complete(), Some(TenantSlot::Secondary) => { // TODO: when adding secondary mode tenants, this will check for shutdown // in the same way that we do for `Tenant` above