|
SERVER-43949 added an invariant that awaitReplication only waits for an OpTime in the term that the primary node is currently writing to. This is a safe assumption in waitForWriteConcern codepath because we add an OpTime to the _replicationWaiterList only if the term of the OpTime is the same as the current term. And on stepDown, we clear the _replicationWaiterList.
However, in stepDown, we blindly add an OpTime to the _replicationWaiterList. So if a stepDown starts in the middle of primary catch-up mode, the lastAppliedOpTime will have a previous term. But once the primary catch-up mode finishes, the primary will write an noop with its new term. And then when we want to wake up waiters in the _replicationWaiterList, we hit this invariant.
In fact, if the lastAppliedOpTime we get during stepDown has a stale term compared to the current term, it means that the current primary has not yet written any oplog entry or this is an unconditional stepDown on hearing a higher term. So it is more correct to simply skip waiting for majority. And it is not the current primary's responsibility to wait for something written in the previous term to become majority committed before it steps down. Indeed, the previous primary should have done so already (assuming the previous primary was non-force stepped down).
|