mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-17 02:12:56 +00:00
`wait_for_active_tenant` is mis-named: its purpose is not to wait for the tenant to become active, but, to prevent new loop iterations while the tenant is not active. However, we never allow a tenant to transition from `!Active` to `Active` state again. So, the "while not active" aspect is moot. Futher, we know that we spawnt he background loops `Tenant::activate` when we just made the tenant `Active`. So, we will never actually wait for the tenant to become active. The only condition where the tenant can be observed `!Active` is when we're shutting down, i.e., transitioning the tenant to `Stopping`. The loops should exit when that happens. But `wait_for_active_tenant` doesn't handle that case. The individual loops use `task_mgr::shutdown_token()` for that. This patch simplifies the code by 1. removing `wait_for_active_tenant` which we have shown above to be quite useless, and 2. by making cancellation of the loops a concern of the `Tenant::set_stopping` / `Tenant::set_broken` This in turn allows us to remove `Tenant::subscribe_for_state_updates`, which is great because now `Tenant::state` is only watched through well-defined APIs like `Tenant::wait_to_become_active`. The context for this PR is me trying to find an alternative to https://github.com/neondatabase/neon/pull/4291 which is s part of the https://github.com/orgs/neondatabase/projects/38 (async get_value_reconstruct_data). I don't know if this leads to a true alternative for 4291, but, it's a useful cleanup by itself.