[SERVER-62800] Create Condition Variable Helper Class To Enforce State Mutation & Notification Contract Created: 20/Jan/22  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Internal Code
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Luis Osta (Inactive) Assignee: Backlog - Service Architecture
Resolution: Unresolved Votes: 0
Labels: sa-remove-fv-backlog-22
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Service Arch
Participants:
Story Points: 2

 Description   

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.


Generated at Thu Feb 08 05:56:06 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.