@@ -92,6 +92,31 @@ void checkShardKeyRestrictions(OperationContext* opCtx,
92
92
shardKeyPattern.isUniqueIndexCompatible (newIdxKey));
93
93
}
94
94
95
+ /* *
96
+ * Signal downstream secondary nodes to abort index build.
97
+ */
98
+ void onAbortIndexBuild (OperationContext* opCtx,
99
+ const NamespaceString& nss,
100
+ const ReplIndexBuildState& replState,
101
+ const Status& cause) {
102
+ if (!serverGlobalParams.featureCompatibility .isVersionInitialized ()) {
103
+ return ;
104
+ }
105
+
106
+ if (serverGlobalParams.featureCompatibility .getVersion () !=
107
+ ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo44 ) {
108
+ return ;
109
+ }
110
+
111
+ invariant (opCtx->lockState ()->isWriteLocked (), replState.buildUUID .toString ());
112
+
113
+ auto opObserver = opCtx->getServiceContext ()->getOpObserver ();
114
+ auto collUUID = replState.collectionUUID ;
115
+ auto fromMigrate = false ;
116
+ opObserver->onAbortIndexBuild (
117
+ opCtx, nss, collUUID, replState.buildUUID , replState.indexSpecs , cause, fromMigrate);
118
+ }
119
+
95
120
/* *
96
121
* Aborts the index build identified by the provided 'replIndexBuildState'.
97
122
*
@@ -934,24 +959,16 @@ void IndexBuildsCoordinator::_runIndexBuildInner(OperationContext* opCtx,
934
959
<< " ; Database: " << replState->dbName ));
935
960
}
936
961
937
- // Signal downstream secondary nodes to abort index build.
938
- if (serverGlobalParams.featureCompatibility .isVersionInitialized () &&
939
- serverGlobalParams.featureCompatibility .getVersion () ==
940
- ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo44 ) {
941
- UninterruptibleLockGuard noInterrupt (opCtx->lockState ());
942
- Lock::GlobalLock lock (opCtx, MODE_IX);
943
- auto collUUID = replState->collectionUUID ;
944
- auto fromMigrate = false ;
962
+ UninterruptibleLockGuard noInterrupt (opCtx->lockState ());
963
+ Lock::GlobalLock lock (opCtx, MODE_IX);
964
+
965
+ auto replCoord = repl::ReplicationCoordinator::get (opCtx);
966
+ if (replCoord->getSettings ().usingReplSets () && replCoord->canAcceptWritesFor (opCtx, nss)) {
945
967
writeConflictRetry (
946
968
opCtx, " onAbortIndexBuild" , NamespaceString::kRsOplogNamespace .ns (), [&] {
947
- opCtx->getServiceContext ()->getOpObserver ()->onAbortIndexBuild (
948
- opCtx,
949
- nss,
950
- collUUID,
951
- replState->buildUUID ,
952
- replState->indexSpecs ,
953
- status,
954
- fromMigrate);
969
+ WriteUnitOfWork wuow (opCtx);
970
+ onAbortIndexBuild (opCtx, nss, *replState, status);
971
+ wuow.commit ();
955
972
});
956
973
}
957
974
0 commit comments