summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Russotto <matthew.russotto@mongodb.com>2022-05-31 09:46:33 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-08-03 17:29:15 +0000
commit3433b2931ccd819922e689c232ee7f72d88ede15 (patch)
treea6ee843421d610e74f6341536202223b33dbb93d
parent3cf970945f17c47d2ce60dda0f879b91962c5f6f (diff)
downloadmongo-3433b2931ccd819922e689c232ee7f72d88ede15.tar.gz
SERVER-65657 Reduce calls to the cappedInsertNotifier for the oplog
(cherry picked from commit 7aeab9f7830c47e8b8e3633da35c36d8cfe5a878)
-rw-r--r--src/mongo/db/catalog/collection_impl.cpp6
-rw-r--r--src/mongo/db/repl/oplog_applier_impl.cpp3
-rw-r--r--src/mongo/db/repl/replication_coordinator.h5
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl.cpp6
4 files changed, 14 insertions, 6 deletions
diff --git a/src/mongo/db/catalog/collection_impl.cpp b/src/mongo/db/catalog/collection_impl.cpp
index b79c8c78914..e4f0fdf2074 100644
--- a/src/mongo/db/catalog/collection_impl.cpp
+++ b/src/mongo/db/catalog/collection_impl.cpp
@@ -811,9 +811,9 @@ Status CollectionImpl::insertDocumentsForOplog(OperationContext* opCtx,
_cappedDeleteAsNeeded(opCtx, records->begin()->id);
- opCtx->recoveryUnit()->onCommit(
- [this](boost::optional<Timestamp>) { _shared->notifyCappedWaitersIfNeeded(); });
-
+ // We do not need to notify capped waiters, as we have not yet updated oplog visibility, so
+ // these inserts will not be visible. When visibility updates, it will notify capped
+ // waiters.
return status;
}
diff --git a/src/mongo/db/repl/oplog_applier_impl.cpp b/src/mongo/db/repl/oplog_applier_impl.cpp
index c5ca80bb8d6..26c479cb1c4 100644
--- a/src/mongo/db/repl/oplog_applier_impl.cpp
+++ b/src/mongo/db/repl/oplog_applier_impl.cpp
@@ -147,6 +147,9 @@ protected:
// We have to use setMyLastAppliedOpTimeAndWallTimeForward since this thread races with
// ReplicationExternalStateImpl::onTransitionToPrimary.
_replCoord->setMyLastAppliedOpTimeAndWallTimeForward(newOpTimeAndWallTime);
+ // We know we're at a no-holes point and we've already advanced visibility; we need
+ // to notify waiters since we changed the lastAppliedSnapshot.
+ signalOplogWaiters();
}
void _recordDurable(const OpTimeAndWallTime& newOpTimeAndWallTime) {
diff --git a/src/mongo/db/repl/replication_coordinator.h b/src/mongo/db/repl/replication_coordinator.h
index 01966a7722a..a057bf5ad7b 100644
--- a/src/mongo/db/repl/replication_coordinator.h
+++ b/src/mongo/db/repl/replication_coordinator.h
@@ -380,6 +380,11 @@ public:
* necessarily commit in sequential order. It is also used when we finish oplog batch
* application on secondaries, to avoid any potential race conditions around setting the
* applied optime from more than one thread.
+ *
+ * Since the last applied op time and wall time might not be visible (i.e. there may be
+ * "oplog holes" from oplog entries with earlier timestamps which commit after this one)
+ * this method does not notify oplog waiters. Callers which know the new lastApplied is at
+ * a no-holes point should call signalOplogWaiters after calling this method.
*/
virtual void setMyLastAppliedOpTimeAndWallTimeForward(
const OpTimeAndWallTime& opTimeAndWallTime) = 0;
diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp
index 65f716b4400..f3b5ee9ad01 100644
--- a/src/mongo/db/repl/replication_coordinator_impl.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl.cpp
@@ -292,6 +292,7 @@ InitialSyncerInterface::Options createInitialSyncerOptions(
externalState](const OpTimeAndWallTime& opTimeAndWallTime) {
// Note that setting the last applied opTime forward also advances the global timestamp.
replCoord->setMyLastAppliedOpTimeAndWallTimeForward(opTimeAndWallTime);
+ signalOplogWaiters();
// The oplog application phase of initial sync starts timestamping writes, causing
// WiredTiger to pin this data in memory. Advancing the oldest timestamp in step with the
// last applied optime here will permit WiredTiger to evict this data as it sees fit.
@@ -835,6 +836,7 @@ void ReplicationCoordinatorImpl::_initialSyncerCompletionFunction(
const auto lastApplied = opTimeStatus.getValue();
_setMyLastAppliedOpTimeAndWallTime(lock, lastApplied, false);
+ signalOplogWaiters();
_topCoord->resetMaintenanceCount();
}
@@ -1406,6 +1408,7 @@ void ReplicationCoordinatorImpl::setMyLastAppliedOpTimeAndWallTime(
stdx::unique_lock<Latch> lock(_mutex);
// The optime passed to this function is required to represent a consistent database state.
_setMyLastAppliedOpTimeAndWallTime(lock, opTimeAndWallTime, false);
+ signalOplogWaiters();
_reportUpstream_inlock(std::move(lock));
}
@@ -1479,9 +1482,6 @@ void ReplicationCoordinatorImpl::_setMyLastAppliedOpTimeAndWallTime(
},
opTime);
- // Notify the oplog waiters after updating the local snapshot.
- signalOplogWaiters();
-
if (opTime.isNull()) {
return;
}