Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-62800

Create Condition Variable Helper Class To Enforce State Mutation & Notification Contract

    • 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.

            Assignee:
            Unassigned Unassigned
            Reporter:
            luis.osta@mongodb.com Luis Osta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: