Make ReplicationCoordinatorImpl public accessors lock-free

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Fixed
    • Priority: Major - P3
    • 8.3.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Replication
    • Fully Compatible
    • Repl 2025-11-10, Repl 2025-11-24
    • 200
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      RCI has public accessors for some of its members. Those accessors take RCI._mutex, which blocks critical operations. Performance could be improved by caching those members in atomics and reading from the atomics in cases where only a single value is read. An example is getMyLastWrittenOpTime:

      OpTime ReplicationCoordinatorImpl::getMyLastWrittenOpTime() const {
          stdx::lock_guard lock(_mutex);
          return _getMyLastWrittenOpTime(lock);
      }
      
      OpTimeAndWallTime ReplicationCoordinatorImpl::_getMyLastWrittenOpTimeAndWallTime(WithLock) const {
          return _topCoord->getMyLastWrittenOpTimeAndWallTime();
      }

      Without changing the internal accessor, we could rewrite the public accessor to read and return an atomic:

      OpTime ReplicationCoordinatorImpl::getMyLastWrittenOpTime() const {
          return _myLastWrittenOpTimeCached.load();
      }

      This is safe as long as we store new lastWritten values while holding RCI._mutex.

            Assignee:
            Brad Cater
            Reporter:
            Brad Cater
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: