-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Internal Code
-
Server Programmability
-
2
The inspiration for this ticket originated from the bug fixed by SERVER-62682. The problem was that the implicit contract of the condition variable used was violated. The underlying _state variable in PrimaryOnlyService was mutated without an accompanying call to the condition variable's notify_all. Which lead to threads waiting for a change in _state to not be woken up.
Instead of relying on the developer remembering to adhere to the contract, we should create a helper class that will explicitly enforce this contract. This would be for a simple condition variable use case that is relatively common: one single state variable that changes and when it changes all threads waiting on a change should be notified.
From my investigation I think that the class should expose the following functions:
- setState(State newState, )
- waitForStateChange(Function callback)
The current refactor PrimaryOnlyService serves as a good basis for that class. Specifically the _setState and _waitForStateNotRebuilding.
Though other solutions that will explicitly enforce the contract for that common pattern will also work.