diff options
author | Misha Tyulenev <misha@mongodb.com> | 2017-11-17 17:00:15 -0500 |
---|---|---|
committer | Misha Tyulenev <misha@mongodb.com> | 2017-11-17 17:00:30 -0500 |
commit | a40d277a1c7a735e4d7ed5cf394e23181f8620fb (patch) | |
tree | 5fee3fc10036972f933d71c977e1cd4d89efe605 /src/mongo/db/read_concern.cpp | |
parent | 97af8701b538754261e566b26fa22cb4b54710f3 (diff) | |
download | mongo-a40d277a1c7a735e4d7ed5cf394e23181f8620fb.tar.gz |
SERVER-32006 add a parameter to wait before secondaries perform noop write
Diffstat (limited to 'src/mongo/db/read_concern.cpp')
-rw-r--r-- | src/mongo/db/read_concern.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/mongo/db/read_concern.cpp b/src/mongo/db/read_concern.cpp index 557c83c5f6a..4a11f36908f 100644 --- a/src/mongo/db/read_concern.cpp +++ b/src/mongo/db/read_concern.cpp @@ -102,6 +102,8 @@ private: }; +MONGO_EXPORT_SERVER_PARAMETER(waitForSecondaryBeforeNoopWriteMS, int, 10); + /** * Schedule a write via appendOplogNote command to the primary of this replica set. */ @@ -112,6 +114,20 @@ Status makeNoopWriteIfNeeded(OperationContext* opCtx, LogicalTime clusterTime) { auto& writeRequests = getWriteRequestsSynchronizer(opCtx->getClient()->getServiceContext()); auto lastAppliedOpTime = LogicalTime(replCoord->getMyLastAppliedOpTime().getTimestamp()); + + // secondaries may lag primary so wait first to avoid unnecessary noop writes. + if (clusterTime > lastAppliedOpTime && replCoord->getMemberState().secondary()) { + auto deadline = Date_t::now() + Milliseconds(waitForSecondaryBeforeNoopWriteMS.load()); + auto readConcernArgs = + repl::ReadConcernArgs(clusterTime, repl::ReadConcernLevel::kLocalReadConcern); + auto waitStatus = replCoord->waitUntilOpTimeForReadUntil(opCtx, readConcernArgs, deadline); + lastAppliedOpTime = LogicalTime(replCoord->getMyLastAppliedOpTime().getTimestamp()); + if (!waitStatus.isOK()) { + LOG(1) << "Wait for clusterTime: " << clusterTime.toString() + << " until deadline: " << deadline << " failed with " << waitStatus.toString(); + } + } + auto status = Status::OK(); int remainingAttempts = 3; // this loop addresses the case when two or more threads need to advance the opLog time but the |