summaryrefslogtreecommitdiff
path: root/src/mongo/s/client/shard_local.h
diff options
context:
space:
mode:
authorSpencer T Brody <spencer@mongodb.com>2016-07-06 15:03:55 -0400
committerSpencer T Brody <spencer@mongodb.com>2016-07-07 12:05:29 -0400
commite7cc7ebf50c2883776cb4cc2423d687bcafa35b6 (patch)
tree05cad903f5ee8f0c198c211aafca8f98a735b615 /src/mongo/s/client/shard_local.h
parent130485fbfa76a7134cf674cb06875b9eb74f397d (diff)
downloadmongo-e7cc7ebf50c2883776cb4cc2423d687bcafa35b6.tar.gz
SERVER-24817 Make ShardLocal wait for writes it performed when doing majority reads
This reverts commit ed19a4a874a7ed792a850c71e352eee2f2bb167c.
Diffstat (limited to 'src/mongo/s/client/shard_local.h')
-rw-r--r--src/mongo/s/client/shard_local.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/mongo/s/client/shard_local.h b/src/mongo/s/client/shard_local.h
index b39aba621d0..449a5d7a037 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,31 @@ private:
const BSONObj& query,
const BSONObj& sort,
boost::optional<long long> 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.
+ * The 'previousOpTimeOnClient' parameter is the optime that *was* the optime on this client
+ * before we ran this command through this ShardLocal. By the time this method is called,
+ * if the optime set on the Client is different than 'previousOpTimeOnClient' then that means
+ * the command just run did a write and we should update _lastOpTime to capture the optime of
+ * the write we just did. If the current optime on the client is the same as
+ * 'previousOpTimeOnClient' then the command we just ran didn't do a write, and we should leave
+ * _lastOpTime alone.
+ */
+ void _updateLastOpTimeFromClient(OperationContext* txn,
+ const repl::OpTime& previousOpTimeOnClient);
+
+ 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