-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: 8.0.13, 7.0.48
-
Component/s: Replication
-
None
-
Replication - Oplog and Recovery
-
ALL
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Versions: 7.0, 8.0 (same code). Not 9.0 or master (intent registry on by default).
Problem
Lock::GlobalLock takes the RSTL in IX in _takeGlobalAndRSTLLocks, then waits for a ticket in LockerImpl::lockGlobal (_acquireTicket). It calls setGlobalLockTakenInMode only after the ticket and the global lock are granted.
ReplicationCoordinatorImpl::_killConflictingOpsOnStepUpAndStepDown interrupts an operation only if one of these is true:
- wasGlobalLockTakenInModeConflictingWithWrites
- shouldAlwaysInterruptAtStepDownOrUp (multi-document transactions)
- it is waiting on a prepare conflict
None of these is true for an operation still waiting for its ticket. So the operation keeps the RSTL and the step-down never interrupts it. If tickets do not free up within fassertOnLockTimeoutForStepUpDown, the step-down fasserts (5675600 on 7.0, 7152000 on 8.0).
Who is affected: writes outside transactions, and reads that take regular locks (dbHash, dbStats, the session-refresh read in refreshTransactionFromStorage, ...). Lock-free reads (find, aggregate, count, distinct, getMore) are not: they take the global lock with skipRSTLLock. Only the first acquisition is exposed. After a yield, restoreLockState re-takes the RSTL behind the pending X.
Evidence
On 8.0.13, this is the most common RSTL-holder shape in the lock dumps logged with 7152000: 536 of 568 holder entries across 6 of 15 dumps. The stacks show Lock::GlobalLock -> _takeGlobalAndRSTLLocks -> lockGlobal -> _acquireTicket -> waitForTicketUntil, many of them through checkOutSession -> refreshTransactionFromStorage.
Proposed fix (options)
- Do not hold the RSTL while waiting for a ticket. In _takeGlobalAndRSTLLocks, if the ticket is not available immediately, release the RSTL, wait for the ticket, then re-take the RSTL in IX. A pending X then queues the operation behind the state transition instead of being blocked by it. Writes then fail with NotWritablePrimary as usual.
- Fail the wait when a state transition is pending. LockerImpl::reacquireTicket already does this for the yield path. It waits in 100 ms slices and uasserts LockTimeout when hasConflictingRequests reports a conflicting request on a held resource. Doing the same in the first _acquireTicket call, for the RSTL only, and with a retryable code (InterruptedDueToReplStateChange), would release the RSTL within 100 ms of the step-down enqueueing X.
- Interrupt queued operations in the kill pass. Use the locker's client state (kQueuedReader/kQueuedWriter) with the RSTL held. Option 1 or 2 is less invasive, because reads are normally not interrupted at step-down.