summaryrefslogtreecommitdiff
path: root/src/mongo/db/op_observer_impl.cpp
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2021-10-01 17:35:46 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-10-04 20:36:46 +0000
commite24c4546b90a5af883dc111c0a60c6424ac395d2 (patch)
tree2321c53b3331edc4593ffa97004c168d18e80ce4 /src/mongo/db/op_observer_impl.cpp
parent5a7aade7b5939c5946f84b337886f861a33bab1a (diff)
downloadmongo-e24c4546b90a5af883dc111c0a60c6424ac395d2.tar.gz
SERVER-60343 Single-phase index builds perform timestamped catalog writes on abort
Diffstat (limited to 'src/mongo/db/op_observer_impl.cpp')
-rw-r--r--src/mongo/db/op_observer_impl.cpp61
1 files changed, 44 insertions, 17 deletions
diff --git a/src/mongo/db/op_observer_impl.cpp b/src/mongo/db/op_observer_impl.cpp
index d8d52d1bc4c..b10e47fca8d 100644
--- a/src/mongo/db/op_observer_impl.cpp
+++ b/src/mongo/db/op_observer_impl.cpp
@@ -304,6 +304,31 @@ void writeToChangeStreamPreImagesCollection(OperationContext* opCtx,
!res.existing && !res.upsertedId.isEmpty());
}
+bool shouldTimestampIndexBuildSinglePhase(OperationContext* opCtx, const NamespaceString& nss) {
+ // This function returns whether a timestamp for a catalog write when beginning an index build,
+ // or aborting an index build is necessary. There are four scenarios:
+
+ // 1. A timestamp is already set -- replication application sets a timestamp ahead of time.
+ // This could include the phase of initial sync where it applies oplog entries. Also,
+ // primaries performing an index build via `applyOps` may have a wrapping commit timestamp.
+ if (!opCtx->recoveryUnit()->getCommitTimestamp().isNull())
+ return false;
+
+ // 2. If the node is initial syncing, we do not set a timestamp.
+ auto replCoord = repl::ReplicationCoordinator::get(opCtx);
+ if (replCoord->isReplEnabled() && replCoord->getMemberState().startup2())
+ return false;
+
+ // 3. If the index build is on the local database, do not timestamp.
+ if (nss.isLocal())
+ return false;
+
+ // 4. All other cases, we generate a timestamp by writing a no-op oplog entry. This is
+ // better than using a ghost timestamp. Writing an oplog entry ensures this node is
+ // primary.
+ return true;
+}
+
} // namespace
BSONObj OpObserverImpl::DocumentKey::getId() const {
@@ -397,32 +422,34 @@ void OpObserverImpl::onStartIndexBuild(OperationContext* opCtx,
void OpObserverImpl::onStartIndexBuildSinglePhase(OperationContext* opCtx,
const NamespaceString& nss) {
- // This function sets a timestamp for the initial catalog write when beginning an index
- // build, if necessary. There are four scenarios:
-
- // 1. A timestamp is already set -- replication application sets a timestamp ahead of time.
- // This could include the phase of initial sync where it applies oplog entries. Also,
- // primaries performing an index build via `applyOps` may have a wrapping commit timestamp.
- if (!opCtx->recoveryUnit()->getCommitTimestamp().isNull())
+ if (!shouldTimestampIndexBuildSinglePhase(opCtx, nss)) {
return;
+ }
- // 2. If the node is initial syncing, we do not set a timestamp.
- auto replCoord = repl::ReplicationCoordinator::get(opCtx);
- if (replCoord->isReplEnabled() && replCoord->getMemberState().startup2())
- return;
- // 3. If the index build is on the local database, do not timestamp.
- if (nss.isLocal())
+ onInternalOpMessage(
+ opCtx,
+ {},
+ boost::none,
+ BSON("msg" << std::string(str::stream() << "Creating indexes. Coll: " << nss)),
+ boost::none,
+ boost::none,
+ boost::none,
+ boost::none,
+ boost::none);
+}
+
+void OpObserverImpl::onAbortIndexBuildSinglePhase(OperationContext* opCtx,
+ const NamespaceString& nss) {
+ if (!shouldTimestampIndexBuildSinglePhase(opCtx, nss)) {
return;
+ }
- // 4. All other cases, we generate a timestamp by writing a no-op oplog entry. This is
- // better than using a ghost timestamp. Writing an oplog entry ensures this node is
- // primary.
onInternalOpMessage(
opCtx,
{},
boost::none,
- BSON("msg" << std::string(str::stream() << "Creating indexes. Coll: " << nss)),
+ BSON("msg" << std::string(str::stream() << "Aborting indexes. Coll: " << nss)),
boost::none,
boost::none,
boost::none,