OpTime ReplicationCoordinatorExternalStateImpl::onTransitionToPrimary(OperationContext* txn, bool isV1ElectionProtocol) { invariant(txn->lockState()->isW()); // Clear the appliedThrough marker so on startup we'll use the top of the oplog. This must be // done before we add anything to our oplog. invariant(_storageInterface->getOplogDeleteFromPoint(txn).isNull()); _storageInterface->setAppliedThrough(txn, {}); if (isV1ElectionProtocol) { MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN { ScopedTransaction scopedXact(txn, MODE_X); WriteUnitOfWork wuow(txn); txn->getClient()->getServiceContext()->getOpObserver()->onOpMessage( txn, BSON("msg" << "new primary")); wuow.commit(); } MONGO_WRITE_CONFLICT_RETRY_LOOP_END( txn, "logging transition to primary to oplog", "local.oplog.rs"); } const auto opTimeToReturn = fassertStatusOK(28665, loadLastOpTime(txn)); _shardingOnTransitionToPrimaryHook(txn); _dropAllTempCollections(txn); return opTimeToReturn; }
OpTime ReplicationCoordinatorExternalStateImpl::onTransitionToPrimary(OperationContext* opCtx, bool isV1ElectionProtocol) { invariant(opCtx->lockState()->isW()); // Clear the appliedThrough marker so on startup we'll use the top of the oplog. This must be // done before we add anything to our oplog. // We record this update at the 'lastAppliedOpTime'. If there are any outstanding // checkpoints being taken, they should only reflect this write if they see all writes up // to our 'lastAppliedOpTime'. invariant( _replicationProcess->getConsistencyMarkers()->getOplogTruncateAfterPoint(opCtx).isNull()); auto lastAppliedOpTime = repl::ReplicationCoordinator::get(opCtx)->getMyLastAppliedOpTime(); _replicationProcess->getConsistencyMarkers()->clearAppliedThrough( opCtx, lastAppliedOpTime.getTimestamp()); if (isV1ElectionProtocol) { writeConflictRetry(opCtx, "logging transition to primary to oplog", "local.oplog.rs", [&] { WriteUnitOfWork wuow(opCtx); opCtx->getClient()->getServiceContext()->getOpObserver()->onOpMessage( opCtx, BSON("msg" << "new primary")); wuow.commit(); }); } const auto opTimeToReturn = fassertStatusOK(28665, loadLastOpTime(opCtx)); _shardingOnTransitionToPrimaryHook(opCtx); _dropAllTempCollections(opCtx); serverGlobalParams.validateFeaturesAsMaster.store(true); return opTimeToReturn; }