summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Noma <gregory.noma@gmail.com>2022-01-04 21:51:24 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-01-06 18:28:46 +0000
commit970c93880474dd811a42dd4e08c899db9c67a973 (patch)
treef8ffdc9db3689cad7217877470832165dc1115e7
parent19e604547ccfefd247481c456e92a9c7b30c72e5 (diff)
downloadmongo-970c93880474dd811a42dd4e08c899db9c67a973.tar.gz
SERVER-62173 Wait for no index builds to be in progress on BackgroundOperationInProgressForNamespace during steady state replication with FCV less than 5.2
(cherry picked from commit f7ab9b6b8825cb09ce92ed4797b0ee75a49b5e22)
-rw-r--r--src/mongo/db/repl/oplog.cpp53
1 files changed, 45 insertions, 8 deletions
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp
index a1c0a273f1f..5454baf2abd 100644
--- a/src/mongo/db/repl/oplog.cpp
+++ b/src/mongo/db/repl/oplog.cpp
@@ -1927,14 +1927,51 @@ Status applyCommand_inlock(OperationContext* opCtx,
auto ns = cmd->parse(opCtx, OpMsgRequest::fromDBAndBody(nss.db(), o))->ns();
- invariant(mode == OplogApplication::Mode::kInitialSync);
- abortIndexBuilds(
- opCtx, entry.getCommandType(), ns, "Aborting index builds during initial sync");
- LOGV2_DEBUG(4665901,
- 1,
- "Conflicting DDL operation encountered during initial sync; "
- "aborting index build and retrying",
- "namespace"_attr = ns);
+ // TODO (SERVER-61481): Once kLastLTS is 6.0, this error will only be possible in
+ // mode kInitialSync.
+ if (mode == OplogApplication::Mode::kInitialSync) {
+ abortIndexBuilds(opCtx,
+ entry.getCommandType(),
+ ns,
+ "Aborting index builds during initial sync");
+ LOGV2_DEBUG(4665901,
+ 1,
+ "Conflicting DDL operation encountered during initial sync; "
+ "aborting index build and retrying",
+ logAttrs(ns));
+ } else {
+ auto lockState = opCtx->lockState();
+ Locker::LockSnapshot lockSnapshot;
+ auto locksReleased = lockState->saveLockStateAndUnlock(&lockSnapshot);
+
+ ScopeGuard guard{[&] {
+ if (locksReleased) {
+ invariant(!lockState->isLocked());
+ lockState->restoreLockState(lockSnapshot);
+ }
+ }};
+
+ auto swUUID = entry.getUuid();
+ if (!swUUID) {
+ LOGV2_ERROR(21261,
+ "Failed command during oplog application. Expected a UUID",
+ "command"_attr = redact(o),
+ logAttrs(ns));
+ }
+ IndexBuildsCoordinator::get(opCtx)->awaitNoIndexBuildInProgressForCollection(
+ opCtx, swUUID.get());
+
+ opCtx->recoveryUnit()->abandonSnapshot();
+ opCtx->checkForInterrupt();
+
+ LOGV2_DEBUG(
+ 51775,
+ 1,
+ "Acceptable error during oplog application: background operation in "
+ "progress for namespace",
+ logAttrs(ns),
+ "oplogEntry"_attr = redact(entry.toBSONForLogging()));
+ }
break;
}