From 88daeb804d093011144cb5e3a0295aa9eb89c42b Mon Sep 17 00:00:00 2001 From: Spencer T Brody Date: Mon, 27 Jun 2016 18:46:49 -0400 Subject: SERVER-24817 Make ShardLocal wait for writes it performed when doing majority reads This gives config servers read-your-own-write semantics, even when the writes are performed as w:1 and the reads have readConcern:majority --- src/mongo/s/client/shard_local.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/mongo/s/client/shard_local.h') diff --git a/src/mongo/s/client/shard_local.h b/src/mongo/s/client/shard_local.h index b39aba621d0..1c65015b78e 100644 --- a/src/mongo/s/client/shard_local.h +++ b/src/mongo/s/client/shard_local.h @@ -30,7 +30,9 @@ #include "mongo/base/disallow_copying.h" #include "mongo/client/dbclientinterface.h" +#include "mongo/db/repl/optime.h" #include "mongo/s/client/shard.h" +#include "mongo/stdx/mutex.h" namespace mongo { @@ -75,6 +77,23 @@ private: const BSONObj& query, const BSONObj& sort, boost::optional limit) final; + + /** + * Checks if an OpTime was set on the current Client (ie if the current operation performed a + * write) and if so updates _lastOpTime to the OpTime from the write that was just performed. + */ + void _updateLastOpTimeFromClient(OperationContext* txn); + + repl::OpTime _getLastOpTime(); + + // Guards _lastOpTime below. + stdx::mutex _mutex; + + // Stores the optime that was generated by the last operation to perform a write that was run + // through _runCommand. Used in _exhaustiveFindOnConfig for waiting for that optime to be + // committed so that readConcern majority reads will read the writes that were performed without + // a w:majority write concern. + repl::OpTime _lastOpTime{}; }; } // namespace mongo -- cgit v1.2.1