summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2019-10-09 11:11:38 +0000
committerevergreen <evergreen@mongodb.com>2019-10-09 11:11:38 +0000
commit342d72abd4b40d5325e7a252ca1c71bada457a9b (patch)
tree38d6eeca77d2fa1652e8896b278761106e1ce8c5
parente3c434d49714eb460b5c35b9d9202cf88082b743 (diff)
downloadmongo-342d72abd4b40d5325e7a252ca1c71bada457a9b.tar.gz
SERVER-39002 IndexBuildsCoordinator checks replication state before writing abortIndexBuild oplog entry
-rw-r--r--src/mongo/db/index_builds_coordinator.cpp49
1 files changed, 33 insertions, 16 deletions
diff --git a/src/mongo/db/index_builds_coordinator.cpp b/src/mongo/db/index_builds_coordinator.cpp
index 80a192fb078..6ebb98a11ab 100644
--- a/src/mongo/db/index_builds_coordinator.cpp
+++ b/src/mongo/db/index_builds_coordinator.cpp
@@ -93,6 +93,31 @@ void checkShardKeyRestrictions(OperationContext* opCtx,
}
/**
+ * Signal downstream secondary nodes to abort index build.
+ */
+void onAbortIndexBuild(OperationContext* opCtx,
+ const NamespaceString& nss,
+ const ReplIndexBuildState& replState,
+ const Status& cause) {
+ if (!serverGlobalParams.featureCompatibility.isVersionInitialized()) {
+ return;
+ }
+
+ if (serverGlobalParams.featureCompatibility.getVersion() !=
+ ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo44) {
+ return;
+ }
+
+ invariant(opCtx->lockState()->isWriteLocked(), replState.buildUUID.toString());
+
+ auto opObserver = opCtx->getServiceContext()->getOpObserver();
+ auto collUUID = replState.collectionUUID;
+ auto fromMigrate = false;
+ opObserver->onAbortIndexBuild(
+ opCtx, nss, collUUID, replState.buildUUID, replState.indexSpecs, cause, fromMigrate);
+}
+
+/**
* Aborts the index build identified by the provided 'replIndexBuildState'.
*
* Sets a signal on the coordinator's repl index build state if the builder does not yet exist in
@@ -934,24 +959,16 @@ void IndexBuildsCoordinator::_runIndexBuildInner(OperationContext* opCtx,
<< "; Database: " << replState->dbName));
}
- // Signal downstream secondary nodes to abort index build.
- if (serverGlobalParams.featureCompatibility.isVersionInitialized() &&
- serverGlobalParams.featureCompatibility.getVersion() ==
- ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo44) {
- UninterruptibleLockGuard noInterrupt(opCtx->lockState());
- Lock::GlobalLock lock(opCtx, MODE_IX);
- auto collUUID = replState->collectionUUID;
- auto fromMigrate = false;
+ UninterruptibleLockGuard noInterrupt(opCtx->lockState());
+ Lock::GlobalLock lock(opCtx, MODE_IX);
+
+ auto replCoord = repl::ReplicationCoordinator::get(opCtx);
+ if (replCoord->getSettings().usingReplSets() && replCoord->canAcceptWritesFor(opCtx, nss)) {
writeConflictRetry(
opCtx, "onAbortIndexBuild", NamespaceString::kRsOplogNamespace.ns(), [&] {
- opCtx->getServiceContext()->getOpObserver()->onAbortIndexBuild(
- opCtx,
- nss,
- collUUID,
- replState->buildUUID,
- replState->indexSpecs,
- status,
- fromMigrate);
+ WriteUnitOfWork wuow(opCtx);
+ onAbortIndexBuild(opCtx, nss, *replState, status);
+ wuow.commit();
});
}