domain: release the resource group controller on Domain close and avoid leaking it on init failure
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Enhancement
TiDB creates one `ResourceGroupsController` per process (in `Domain.initResourceGroupsController`) and installs it into process-global integrations: client-go's global resource-control interceptor and the PD client's process-global controller state. tikv/pd#11080 makes this single-controller model an explicit lifecycle contract in `pd/client`: at most one controller acquired through the supported API can be usable in a process at a time, and a replacement can only be acquired after the previous controller has fully stopped and released ownership (enforced by tikv/pd#11132).
The TiDB side should preserve this contract in its controller lifecycle:
- `Domain.Close` currently neither unsets the global resource-control interceptor nor stops the controller. It should do both, so that bootstrap temporary-Domain handoff and Domain initialization retries (which call `Domain.Close` before creating the replacement Domain) release the old controller's ownership before the replacement controller is acquired.
- `initResourceGroupsController` starts the controller before a later fallible step (`infosync.GetServerInfo`), so an error return can leak a started controller that nobody stops. The server info should be fetched before the controller is created, leaving no fallible step between creating the controller and installing it on the Domain.
These changes are compatible with the current pd/client dependency and do not require the enforcement in tikv/pd#11132 to land first. Once TiDB upgrades to a pd/client version that includes the enforcement, the explicit release in `Domain.Close` becomes load-bearing for Domain replacement scenarios.
Contributor guide
Research direction
Start with Domain.initResourceGroupsController and Domain.Close, then trace the ResourceGroupsController setup, infosync.GetServerInfo, and the global resource-control integrations. Verify that server information is fetched before controller creation, that initialization failures leave no running controller, and that Domain.Close unsets the interceptor and stops the controller before replacement.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend, distributed-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100