diff options
author | Matthew Russotto <matthew.russotto@10gen.com> | 2018-04-23 16:34:57 -0400 |
---|---|---|
committer | Matthew Russotto <matthew.russotto@10gen.com> | 2018-04-24 10:07:14 -0400 |
commit | 91148023de6e299ff33832e6e960e73697a0f921 (patch) | |
tree | 166b3f17284c4e329f829979de0ac6df9e1c0d31 /src/mongo/db/read_concern.cpp | |
parent | 2d77fd7d723e98e9dc398aea0c6d639e322dc691 (diff) | |
download | mongo-91148023de6e299ff33832e6e960e73697a0f921.tar.gz |
SERVER-34195 Support speculative readConcern behavior in transactions.
Diffstat (limited to 'src/mongo/db/read_concern.cpp')
-rw-r--r-- | src/mongo/db/read_concern.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/mongo/db/read_concern.cpp b/src/mongo/db/read_concern.cpp index 95350667659..e37d7af49d6 100644 --- a/src/mongo/db/read_concern.cpp +++ b/src/mongo/db/read_concern.cpp @@ -47,6 +47,7 @@ #include "mongo/db/s/sharding_state.h" #include "mongo/db/server_options.h" #include "mongo/db/server_parameters.h" +#include "mongo/db/session_catalog.h" #include "mongo/s/client/shard_registry.h" #include "mongo/s/grid.h" #include "mongo/util/log.h" @@ -210,6 +211,10 @@ Status waitForReadConcern(OperationContext* opCtx, opCtx->recoveryUnit()->setReadConcernLevelAndReplicationMode(readConcernArgs.getLevel(), replCoord->getReplicationMode()); + auto session = OperationContextSession::get(opCtx); + // Currently speculative read concern is used only for transactions and snapshot reads. + const bool speculative = session && session->inSnapshotReadOrMultiDocumentTransaction(); + if (readConcernArgs.getLevel() == repl::ReadConcernLevel::kLinearizableReadConcern) { if (replCoord->getReplicationMode() != repl::ReplicationCoordinator::modeReplSet) { // For standalone nodes, Linearizable Read is not supported. @@ -246,6 +251,11 @@ Status waitForReadConcern(OperationContext* opCtx, return {ErrorCodes::IncompatibleElectionProtocol, "Replica sets running protocol version 0 do not support readConcern: snapshot"}; } + if (speculative) { + fassert(50807, + opCtx->recoveryUnit()->setPointInTimeReadTimestamp( + replCoord->getMyLastAppliedOpTime().getTimestamp())); + } } auto afterClusterTime = readConcernArgs.getArgsAfterClusterTime(); @@ -305,6 +315,7 @@ Status waitForReadConcern(OperationContext* opCtx, if ((readConcernArgs.getLevel() == repl::ReadConcernLevel::kMajorityReadConcern || readConcernArgs.getLevel() == repl::ReadConcernLevel::kSnapshotReadConcern) && + !speculative && replCoord->getReplicationMode() == repl::ReplicationCoordinator::Mode::modeReplSet) { if (!replCoord->isV1ElectionProtocol()) { return {ErrorCodes::IncompatibleElectionProtocol, |