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

Change `isStandaloneOrPrimary` checks to use `writesAreReplicated`

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Replication
    • 166

      The shard server op observer is offering the isStandaloneOrPrimary function to verify if a node is primary by checking that writes on the admin database are allowed. The used method from the replication coordinator expects the caller to always hold the RSTL lock or to perform a lock free read, that may not always be the case when observing operations.

      As of today, the observer is always using the function after checking for the namespace an operation happens on (e.g. here) and by hazard the RSTL lock is always held for those operations.

      Purpose of this ticket is to make the function resilient to any kind of observable operation and avoid future unsafe usages that may lead to hit the invariant.

      A solution would be to replace the existing implementation with the following code snippet:

      auto replCoord = repl::ReplicationCoordinator::get(serviceContext);
      if (!replCoord || !replCoord->isReplEnabled() || !opCtx->writesAreReplicated()) {
          return;
      }
      

       

      Thank you cheahuychou.mao@mongodb.com for spotting that and proposing a solution!

            Assignee:
            backlog-server-repl [DO NOT USE] Backlog - Replication Team
            Reporter:
            pierlauro.sciarelli@mongodb.com Pierlauro Sciarelli
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: