summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeert Bosch <geert@mongodb.com>2016-04-01 15:10:04 -0400
committerGeert Bosch <geert@mongodb.com>2016-04-01 17:13:48 -0400
commitfbf9ef5b5d8d5376d8b920509cc31c34959e722e (patch)
tree74b08e04a26d3a0d28d65c0fdfc83ceeb33b6ac2
parent60f69c2d3cd5ff2a297325f719b38c9fef6e6d9e (diff)
downloadmongo-fbf9ef5b5d8d5376d8b920509cc31c34959e722e.tar.gz
SERVER-23418 Use globally unique snapshot IDs
(cherry picked from commit 2ab9b1fd7ea20319e2d9ddb0532234729877703f)
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp14
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h2
2 files changed, 11 insertions, 5 deletions
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp
index 7a41d0d7341..c87e036d16f 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp
@@ -44,13 +44,19 @@
#include "mongo/util/stacktrace.h"
namespace mongo {
+namespace {
+// SnapshotIds need to be globally unique, as they are used in a WorkingSetMember to
+// determine if documents changed, but a different recovery unit may be used across a getMore,
+// so there is a chance the snapshot ID will be reused.
+AtomicUInt64 nextSnapshotId{1};
+} // namespace
WiredTigerRecoveryUnit::WiredTigerRecoveryUnit(WiredTigerSessionCache* sc)
: _sessionCache(sc),
_session(NULL),
_inUnitOfWork(false),
_active(false),
- _myTransactionCount(1),
+ _mySnapshotId(nextSnapshotId.fetchAndAdd(1)),
_everStartedWrite(false) {}
WiredTigerRecoveryUnit::~WiredTigerRecoveryUnit() {
@@ -66,7 +72,7 @@ void WiredTigerRecoveryUnit::reportState(BSONObjBuilder* b) const {
b->append("wt_inUnitOfWork", _inUnitOfWork);
b->append("wt_active", _active);
b->append("wt_everStartedWrite", _everStartedWrite);
- b->appendNumber("wt_myTransactionCount", static_cast<long long>(_myTransactionCount));
+ b->appendNumber("wt_mySnapshotId", static_cast<long long>(_mySnapshotId));
if (_active)
b->append("wt_millisSinceCommit", _timer.millis());
}
@@ -211,12 +217,12 @@ void WiredTigerRecoveryUnit::_txnClose(bool commit) {
LOG(3) << "WT rollback_transaction";
}
_active = false;
- _myTransactionCount++;
+ _mySnapshotId = nextSnapshotId.fetchAndAdd(1);
}
SnapshotId WiredTigerRecoveryUnit::getSnapshotId() const {
// TODO: use actual wiredtiger txn id
- return SnapshotId(_myTransactionCount);
+ return SnapshotId(_mySnapshotId);
}
Status WiredTigerRecoveryUnit::setReadFromMajorityCommittedSnapshot() {
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h
index b70b4bebfea..9b486c5893a 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h
@@ -132,7 +132,7 @@ private:
bool _areWriteUnitOfWorksBanned = false;
bool _inUnitOfWork;
bool _active;
- uint64_t _myTransactionCount;
+ uint64_t _mySnapshotId;
bool _everStartedWrite;
Timer _timer;
RecordId _oplogReadTill;