-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stopper: remove RunWorker and ShouldStop
`Stopper` has grown organically over the years. Initially, we were trying really hard to give us an ordered shutdown regimen in which a cluster would continue to "work" at a basic level but would only shed incoming load (until no more load was there). This was ultimately abandoned (today we have higher-level primitives for such things, like the Drain RPC), but the corresponding unwieldy APIs not phased out. Roughly we were left with two types of goroutines: - "Workers", which were expected to be long-running and would not be blocked from starting by the stopper (we probably initially assumed that they would all be spun up by the time the stopper could possibly stop, which has not been true for a long time and will likely never be again), and - "Tasks", which are everything else and which are no longer allowed to start once `stopper.Stop()` has been called. In practice, this lead to a lot of confusion and undesired behavior. In particular, a common workaround in our code was to retrofit the "don't allow starting if already shutting down" behavior for workers by wrapping their creation in a synchronous task. It also complicated the shutdown semantics because there were three stages: - quiescing: i.e. no more new tasks but there are still tasks running - stopping: i.e. no more tasks, but there could still be workers - stopped-A: the workers are gone now, but we still have to run the closers! - stopped-B: the closers have also run (signals `IsStopped`). This commit rips off the band-aid: 1. there are no more workers. Everything is a task and can run as long as it likes. 2. there is no more `ShouldStop` and consequently no confusion about which one to listen to (listening to `ShouldStop` only in a task is a deadlock - no longer possible). Now, on Stop(), the Stopper - invokes Quiesce, which causes the Stopper to refuse new work (that is, its Run* family of methods starts returning ErrUnavailable), closes the channel returned by ShouldQuiesce, and blocks until until no more tasks are tracked, then - runs all of the methods supplied to AddCloser, then - closes the IsStopped channel. The `stop` package hasn't gotten TLC in many years, so there is a lot more one might want to do, but that is for another day. Release note: None
- Loading branch information
Showing
71 changed files
with
524 additions
and
499 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.