src/mongo/db/repl/rs_rollback.cpp
/**
 * This must be called before making any changes to our local data and after fetching any
 * information from the upstream node. If any information is fetched from the upstream node after we
 * have written locally, the function must be called again.
 */
This must be called before making any changes to our local data and after fetching any
information from the upstream node. If any information is fetched from the upstream node after we
have written locally, the function must be called again.
This must be called before making any changes to our local data and after fetching any information from the upstream node . If any information is fetched from the upstream node after we have written locally the function must be called again .
void checkRbidAndUpdateMinValid(OperationContext* opCtx,
                                const int rbid,
                                const RollbackSource& rollbackSource,
                                ReplicationProcess* replicationProcess) {
    const auto newMinValidDoc = rollbackSource.getLastOperation();
    if (newMinValidDoc.isEmpty()) {
        uasserted(40500, "rollback error newest oplog entry on source is missing or empty");
    }
    if (rbid != rollbackSource.getRollbackId()) {
        uasserted(40508, "rollback rbid on source changed during rollback, canceling this attempt");
    }
    OpTime minValid = fassertStatusOK(40492, OpTime::parseFromOplogEntry(newMinValidDoc));
    log() << "Setting minvalid to " << minValid;
    replicationProcess->getConsistencyMarkers()->setAppliedThrough(opCtx, {});  
    replicationProcess->getConsistencyMarkers()->setMinValid(opCtx, minValid);
    if (MONGO_FAIL_POINT(rollbackHangThenFailAfterWritingMinValid)) {
        log() << "rollback - rollbackHangThenFailAfterWritingMinValid fail point "
                 "enabled. Blocking until fail point is disabled.";
        while (MONGO_FAIL_POINT(rollbackHangThenFailAfterWritingMinValid)) {
            invariant(!globalInShutdownDeprecated());  
            mongo::sleepsecs(1);
        }
        uasserted(40502,
                  "failing rollback due to rollbackHangThenFailAfterWritingMinValid fail point");
    }
}
void checkRbidAndUpdateMinValid ( OperationContext * opCtx , const int rbid , const RollbackSource & rollbackSource , ReplicationProcess * replicationProcess ) { const auto newMinValidDoc = rollbackSource . getLastOperation ( ) ; if ( newMinValidDoc . isEmpty ( ) ) { uasserted ( 40500 , " " ) ; } if ( rbid != rollbackSource . getRollbackId ( ) ) { uasserted ( 40508 , " " ) ; } OpTime minValid = fassertStatusOK ( 40492 , OpTime :: parseFromOplogEntry ( newMinValidDoc ) ) ; log ( ) << " " << minValid ; replicationProcess -> getConsistencyMarkers ( ) -> setAppliedThrough ( opCtx , { } ) ; replicationProcess -> getConsistencyMarkers ( ) -> setMinValid ( opCtx , minValid ) ; if ( MONGO_FAIL_POINT ( rollbackHangThenFailAfterWritingMinValid ) ) { log ( ) << " " " " ; while ( MONGO_FAIL_POINT ( rollbackHangThenFailAfterWritingMinValid ) ) { invariant ( ! globalInShutdownDeprecated ( ) ) ; mongo :: sleepsecs ( 1 ) ; } uasserted ( 40502 , " " ) ; } }
This must be called before making any changes to our local data and after fetching any
 information from the upstream node.
This must be called before making any changes to our local data and after fetching any information from the upstream node .
// It is important that the steps are performed in order to avoid racing with upstream // rollbacks. // 1. Gets the last doc in their oplog. // 2. Gets their RBID and fail if it has changed. // 3. Sets our minValid to the previously fetched OpTime of the top of their oplog. // Our source rolled back so the data we received is not necessarily consistent. // We have items we are writing that aren't from a point-in-time. Thus, it is best not to come // online until we get to that point in freshness. In other words, we do not transition from // RECOVERING state to SECONDARY state until we have reached the minValid oplog entry. // Use top of oplog. // This log output is used in jstests so please leave it. // It is an error to shutdown while enabled.