summaryrefslogtreecommitdiff
path: root/src/mongo/db/session.cpp
diff options
context:
space:
mode:
authorTess Avitabile <tess.avitabile@mongodb.com>2018-02-20 16:51:50 -0500
committerTess Avitabile <tess.avitabile@mongodb.com>2018-02-22 17:08:22 -0500
commitadfa37c74e716826cde8b7bb1ebbe9e6c99d77d4 (patch)
tree9c207a1729a573b2558dce04eb4656c1af07f790 /src/mongo/db/session.cpp
parentc0480b762f7b155ca0a06921acf99fc31859ea85 (diff)
downloadmongo-adfa37c74e716826cde8b7bb1ebbe9e6c99d77d4.tar.gz
SERVER-33372 Support readConcern snapshot for updates
Diffstat (limited to 'src/mongo/db/session.cpp')
-rw-r--r--src/mongo/db/session.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/mongo/db/session.cpp b/src/mongo/db/session.cpp
index 863ddb4227f..60ea0762b99 100644
--- a/src/mongo/db/session.cpp
+++ b/src/mongo/db/session.cpp
@@ -460,14 +460,15 @@ void Session::stashTransactionResources(OperationContext* opCtx) {
return;
}
- if (!opCtx->hasStashedCursor()) {
- if (opCtx->getWriteUnitOfWork()) {
- opCtx->setWriteUnitOfWork(nullptr);
- }
- return;
- }
+ invariant(opCtx->hasStashedCursor());
if (*opCtx->getTxnNumber() != _activeTxnNumber) {
+ // The session is checked out, so _activeTxnNumber cannot advance due to a user operation.
+ // However, when a chunk is migrated, session and transaction information is copied from the
+ // donor shard to the recipient. This occurs outside of the check-out mechanism and can lead
+ // to a higher _activeTxnNumber during the lifetime of a checkout. If that occurs, we abort
+ // the current transaction. Note that it would indicate a user bug to have a newer
+ // transaction on one shard while an older transaction is still active on another shard.
uasserted(ErrorCodes::TransactionAborted,
str::stream() << "Transaction aborted. Active txnNumber is now "
<< _activeTxnNumber);
@@ -487,6 +488,12 @@ void Session::stashTransactionResources(OperationContext* opCtx) {
void Session::unstashTransactionResources(OperationContext* opCtx) {
stdx::lock_guard<stdx::mutex> lg(_mutex);
if (opCtx->getTxnNumber() < _activeTxnNumber) {
+ // The session is checked out, so _activeTxnNumber cannot advance due to a user operation.
+ // However, when a chunk is migrated, session and transaction information is copied from the
+ // donor shard to the recipient. This occurs outside of the check-out mechanism and can lead
+ // to a higher _activeTxnNumber during the lifetime of a checkout. If that occurs, we abort
+ // the current transaction. Note that it would indicate a user bug to have a newer
+ // transaction on one shard while an older transaction is still active on another shard.
_releaseStashedTransactionResources(lg, opCtx);
uasserted(ErrorCodes::TransactionAborted,
str::stream() << "Transaction aborted. Active txnNumber is now "