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:02:01 -0400
commit2ab9b1fd7ea20319e2d9ddb0532234729877703f (patch)
treea1b91553fb647350d02409b7a7c5ce5dbaa42547
parentec75e8622c942bbf139551be78c1b99cf4b108f3 (diff)
downloadmongo-r3.3.4.tar.gz
SERVER-23418 Use globally unique snapshot IDsr3.3.4
-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 64ef576378a..da241c5e20e 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp
@@ -44,12 +44,18 @@
#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),
_inUnitOfWork(false),
_active(false),
- _myTransactionCount(1),
+ _mySnapshotId(nextSnapshotId.fetchAndAdd(1)),
_everStartedWrite(false) {}
WiredTigerRecoveryUnit::~WiredTigerRecoveryUnit() {
@@ -61,7 +67,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());
}
@@ -206,12 +212,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 63e49c06c86..cbd6ad955d5 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h
@@ -131,7 +131,7 @@ private:
bool _areWriteUnitOfWorksBanned = false;
bool _inUnitOfWork;
bool _active;
- uint64_t _myTransactionCount;
+ uint64_t _mySnapshotId;
bool _everStartedWrite;
Timer _timer;
RecordId _oplogReadTill;