diff options
author | Gregory Noma <gregory.noma@gmail.com> | 2019-06-19 14:16:46 -0400 |
---|---|---|
committer | Gregory Noma <gregory.noma@gmail.com> | 2019-06-19 14:16:46 -0400 |
commit | 0194322119368dd4918212cd0a5108023748e534 (patch) | |
tree | 06318015426213afe5ddb1b078e6ecd0e2863003 /src/mongo/db | |
parent | d3c0e4ad46fcba5aac61ecec1409e9df6e11f66e (diff) | |
download | mongo-0194322119368dd4918212cd0a5108023748e534.tar.gz |
SERVER-38397 Make WiredTigerRecoveryUnit::State a general concept in RecoveryUnit
Diffstat (limited to 'src/mongo/db')
9 files changed, 183 insertions, 179 deletions
diff --git a/src/mongo/db/storage/biggie/biggie_recovery_unit.cpp b/src/mongo/db/storage/biggie/biggie_recovery_unit.cpp index 67479c0ea74..0d6d1a610bd 100644 --- a/src/mongo/db/storage/biggie/biggie_recovery_unit.cpp +++ b/src/mongo/db/storage/biggie/biggie_recovery_unit.cpp @@ -44,17 +44,18 @@ RecoveryUnit::RecoveryUnit(KVEngine* parentKVEngine, std::function<void()> cb) : _waitUntilDurableCallback(cb), _KVEngine(parentKVEngine) {} RecoveryUnit::~RecoveryUnit() { - invariant(!_inUnitOfWork); + invariant(!_inUnitOfWork(), toString(_getState())); _abort(); } void RecoveryUnit::beginUnitOfWork(OperationContext* opCtx) { - invariant(!_inUnitOfWork); - _inUnitOfWork = true; + invariant(!_inUnitOfWork(), toString(_getState())); + _setState(State::kInactiveInUnitOfWork); } void RecoveryUnit::commitUnitOfWork() { - invariant(_inUnitOfWork); + invariant(_inUnitOfWork(), toString(_getState())); + if (_dirty) { invariant(_forked); while (true) { @@ -80,6 +81,7 @@ void RecoveryUnit::commitUnitOfWork() { } try { + _setState(State::kCommitting); for (auto& change : _changes) change->commit(boost::none); _changes.clear(); @@ -87,28 +89,27 @@ void RecoveryUnit::commitUnitOfWork() { std::terminate(); } - _inUnitOfWork = false; + _setState(State::kInactive); } void RecoveryUnit::abortUnitOfWork() { - invariant(_inUnitOfWork); - _inUnitOfWork = false; + invariant(_inUnitOfWork(), toString(_getState())); _abort(); } bool RecoveryUnit::waitUntilDurable() { - invariant(!_inUnitOfWork); + invariant(!_inUnitOfWork(), toString(_getState())); return true; // This is an in-memory storage engine. } void RecoveryUnit::abandonSnapshot() { - invariant(!_inUnitOfWork); + invariant(!_inUnitOfWork(), toString(_getState())); _forked = false; _dirty = false; } void RecoveryUnit::registerChange(Change* change) { - invariant(_inUnitOfWork); + invariant(_inUnitOfWork(), toString(_getState())); _changes.push_back(std::unique_ptr<Change>{change}); } @@ -137,6 +138,8 @@ void RecoveryUnit::setOrderedCommit(bool orderedCommit) {} void RecoveryUnit::_abort() { _forked = false; _dirty = false; + _setState(State::kAborting); + try { for (Changes::const_reverse_iterator it = _changes.rbegin(), end = _changes.rend(); it != end; @@ -149,6 +152,8 @@ void RecoveryUnit::_abort() { } catch (...) { std::terminate(); } + + _setState(State::kInactive); } RecoveryUnit* RecoveryUnit::get(OperationContext* opCtx) { diff --git a/src/mongo/db/storage/biggie/biggie_recovery_unit.h b/src/mongo/db/storage/biggie/biggie_recovery_unit.h index 2ad64ffc784..df282d8c1e0 100644 --- a/src/mongo/db/storage/biggie/biggie_recovery_unit.h +++ b/src/mongo/db/storage/biggie/biggie_recovery_unit.h @@ -50,7 +50,7 @@ public: void abortUnitOfWork() override final; bool inActiveTxn() const { - return _inUnitOfWork; + return _inUnitOfWork(); } virtual bool waitUntilDurable() override; @@ -92,7 +92,6 @@ private: bool _forked = false; bool _dirty = false; // Whether or not we have written to this _workingCopy. - bool _inUnitOfWork = false; typedef std::vector<std::unique_ptr<Change>> Changes; Changes _changes; diff --git a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.cpp b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.cpp index f54fb20aec6..61abd09b8f8 100644 --- a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.cpp +++ b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.cpp @@ -39,16 +39,18 @@ namespace mongo { EphemeralForTestRecoveryUnit::~EphemeralForTestRecoveryUnit() { - invariant(!_inUnitOfWork); + invariant(!_inUnitOfWork(), toString(_getState())); } void EphemeralForTestRecoveryUnit::beginUnitOfWork(OperationContext* opCtx) { - invariant(!_inUnitOfWork); - _inUnitOfWork = true; + invariant(!_inUnitOfWork(), toString(_getState())); + _setState(State::kInactiveInUnitOfWork); } void EphemeralForTestRecoveryUnit::commitUnitOfWork() { - invariant(_inUnitOfWork); + invariant(_inUnitOfWork(), toString(_getState())); + _setState(State::kCommitting); + try { for (Changes::iterator it = _changes.begin(), end = _changes.end(); it != end; ++it) { (*it)->commit(boost::none); @@ -62,12 +64,13 @@ void EphemeralForTestRecoveryUnit::commitUnitOfWork() { // SERVER-22575: Remove this once we add a generic mechanism to periodically wait // for durability. waitUntilDurable(); - _inUnitOfWork = false; + _setState(State::kInactive); } void EphemeralForTestRecoveryUnit::abortUnitOfWork() { - invariant(_inUnitOfWork); - _inUnitOfWork = false; + invariant(_inUnitOfWork(), toString(_getState())); + _setState(State::kAborting); + try { for (Changes::reverse_iterator it = _changes.rbegin(), end = _changes.rend(); it != end; ++it) { @@ -79,6 +82,8 @@ void EphemeralForTestRecoveryUnit::abortUnitOfWork() { } catch (...) { std::terminate(); } + + _setState(State::kInactive); } bool EphemeralForTestRecoveryUnit::waitUntilDurable() { @@ -89,11 +94,11 @@ bool EphemeralForTestRecoveryUnit::waitUntilDurable() { } bool EphemeralForTestRecoveryUnit::inActiveTxn() const { - return _inUnitOfWork; + return _inUnitOfWork(); } void EphemeralForTestRecoveryUnit::abandonSnapshot() { - invariant(!_inUnitOfWork); + invariant(!_inUnitOfWork(), toString(_getState())); } Status EphemeralForTestRecoveryUnit::obtainMajorityCommittedSnapshot() { diff --git a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.h b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.h index 2566deea072..d117a993090 100644 --- a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.h +++ b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.h @@ -92,8 +92,6 @@ private: typedef std::shared_ptr<Change> ChangePtr; typedef std::vector<ChangePtr> Changes; - bool _inUnitOfWork = false; - Changes _changes; std::function<void()> _waitUntilDurableCallback; diff --git a/src/mongo/db/storage/mobile/mobile_recovery_unit.cpp b/src/mongo/db/storage/mobile/mobile_recovery_unit.cpp index 60181ac0b02..a3c9ba831ba 100644 --- a/src/mongo/db/storage/mobile/mobile_recovery_unit.cpp +++ b/src/mongo/db/storage/mobile/mobile_recovery_unit.cpp @@ -50,7 +50,7 @@ namespace mongo { AtomicWord<long long> MobileRecoveryUnit::_nextID(0); MobileRecoveryUnit::MobileRecoveryUnit(MobileSessionPool* sessionPool) - : _inUnitOfWork(false), _active(false), _isReadOnly(true), _sessionPool(sessionPool) { + : _isReadOnly(true), _sessionPool(sessionPool) { // Increment the global instance count and assign this instance an id. _id = _nextID.addAndFetch(1); @@ -58,15 +58,16 @@ MobileRecoveryUnit::MobileRecoveryUnit(MobileSessionPool* sessionPool) } MobileRecoveryUnit::~MobileRecoveryUnit() { - invariant(!_inUnitOfWork); + invariant(!_inUnitOfWork(), toString(_getState())); _abort(); RECOVERY_UNIT_TRACE() << "Destroyed."; } void MobileRecoveryUnit::_commit() { - if (_session && _active) { + if (_session && _isActive()) { _txnClose(true); } + _setState(State::kCommitting); for (auto& change : _changes) { try { @@ -76,12 +77,16 @@ void MobileRecoveryUnit::_commit() { } } _changes.clear(); + + _setState(State::kInactive); } void MobileRecoveryUnit::_abort() { - if (_session && _active) { + if (_session && _isActive()) { _txnClose(false); } + _setState(State::kAborting); + for (auto it = _changes.rbegin(); it != _changes.rend(); ++it) { try { (*it)->rollback(); @@ -90,41 +95,40 @@ void MobileRecoveryUnit::_abort() { } } _changes.clear(); - invariant(!_active); + invariant(!_isActive(), toString(_getState())); + + _setState(State::kInactive); } void MobileRecoveryUnit::beginUnitOfWork(OperationContext* opCtx) { - invariant(!_areWriteUnitOfWorksBanned); - invariant(!_inUnitOfWork); + invariant(!_inUnitOfWork(), toString(_getState())); RECOVERY_UNIT_TRACE() << "Unit of work Active."; - if (_active) { + if (_isActive()) { // Confirm a write transaction is not running invariant(_isReadOnly); // Rollback read transaction running outside wuow _txnClose(false); } + _setState(State::kInactiveInUnitOfWork); _txnOpen(opCtx, false); - _inUnitOfWork = true; } void MobileRecoveryUnit::commitUnitOfWork() { - invariant(_inUnitOfWork); + invariant(_inUnitOfWork(), toString(_getState())); RECOVERY_UNIT_TRACE() << "Unit of work commited, marked inactive."; - _inUnitOfWork = false; _commit(); } void MobileRecoveryUnit::abortUnitOfWork() { - invariant(_inUnitOfWork); + invariant(_inUnitOfWork(), toString(_getState())); RECOVERY_UNIT_TRACE() << "Unit of work aborted, marked inactive."; - _inUnitOfWork = false; _abort(); } @@ -164,24 +168,24 @@ bool MobileRecoveryUnit::waitUntilDurable() { } void MobileRecoveryUnit::abandonSnapshot() { - invariant(!_inUnitOfWork); - if (_active) { + invariant(!_inUnitOfWork(), toString(_getState())); + if (_isActive()) { // We can't be in a WriteUnitOfWork, so it is safe to rollback. _txnClose(false); } - _areWriteUnitOfWorksBanned = false; + _setState(State::kInactive); } void MobileRecoveryUnit::registerChange(Change* change) { - invariant(_inUnitOfWork); + invariant(_inUnitOfWork(), toString(_getState())); _changes.push_back(std::unique_ptr<Change>{change}); } MobileSession* MobileRecoveryUnit::getSession(OperationContext* opCtx, bool readOnly) { RECOVERY_UNIT_TRACE() << "getSession called with readOnly:" << (readOnly ? "TRUE" : "FALSE"); - invariant(_inUnitOfWork || readOnly); - if (!_active) { + invariant(_inUnitOfWork() || readOnly); + if (!_isActive()) { _txnOpen(opCtx, readOnly); } @@ -194,7 +198,7 @@ MobileSession* MobileRecoveryUnit::getSessionNoTxn(OperationContext* opCtx) { } void MobileRecoveryUnit::assertInActiveTxn() const { - fassert(37050, _active); + fassert(37050, _isActive()); } void MobileRecoveryUnit::_ensureSession(OperationContext* opCtx) { @@ -205,7 +209,7 @@ void MobileRecoveryUnit::_ensureSession(OperationContext* opCtx) { } void MobileRecoveryUnit::_txnOpen(OperationContext* opCtx, bool readOnly) { - invariant(!_active); + invariant(!_isActive(), toString(_getState())); RECOVERY_UNIT_TRACE() << "_txnOpen called with readOnly:" << (readOnly ? "TRUE" : "FALSE"); _ensureSession(opCtx); @@ -237,11 +241,11 @@ void MobileRecoveryUnit::_txnOpen(OperationContext* opCtx, bool readOnly) { } _isReadOnly = readOnly; - _active = true; + _setState(_inUnitOfWork() ? State::kActive : State::kActiveNotInUnitOfWork); } void MobileRecoveryUnit::_txnClose(bool commit) { - invariant(_active); + invariant(_isActive(), toString(_getState())); RECOVERY_UNIT_TRACE() << "_txnClose called with " << (commit ? "commit " : "rollback "); if (commit) { @@ -250,7 +254,6 @@ void MobileRecoveryUnit::_txnClose(bool commit) { SqliteStatement::execQuery(_session.get(), "ROLLBACK"); } - _active = false; _isReadOnly = true; // I don't suppose we need this, but no harm in doing so } diff --git a/src/mongo/db/storage/mobile/mobile_recovery_unit.h b/src/mongo/db/storage/mobile/mobile_recovery_unit.h index 6cce4542c89..2e1ff023c35 100644 --- a/src/mongo/db/storage/mobile/mobile_recovery_unit.h +++ b/src/mongo/db/storage/mobile/mobile_recovery_unit.h @@ -69,7 +69,7 @@ public: MobileSession* getSessionNoTxn(OperationContext* opCtx); bool inActiveTxn() const { - return _active; + return _isActive(); } void assertInActiveTxn() const; @@ -91,10 +91,6 @@ private: void _txnOpen(OperationContext* opCtx, bool readOnly); void _upgradeToWriteSession(OperationContext* opCtx); - bool _areWriteUnitOfWorksBanned = false; - bool _inUnitOfWork; - bool _active; - static AtomicWord<long long> _nextID; uint64_t _id; bool _isReadOnly; diff --git a/src/mongo/db/storage/recovery_unit.h b/src/mongo/db/storage/recovery_unit.h index 4fa6b0d482d..c8b04493e8f 100644 --- a/src/mongo/db/storage/recovery_unit.h +++ b/src/mongo/db/storage/recovery_unit.h @@ -492,8 +492,111 @@ public: virtual void setOrderedCommit(bool orderedCommit) = 0; + /** + * State transitions: + * + * /------------------------> Inactive <-----------------------------\ + * | | | + * | | | + * | /--------------+--------------\ | + * | | | | abandonSnapshot() + * | | | | + * | beginUOW() | | _txnOpen() | + * | | | | + * | V V | + * | InactiveInUnitOfWork ActiveNotInUnitOfWork ---------/ + * | | | + * | | | + * | _txnOpen() | | beginUOW() + * | | | + * | \--------------+--------------/ + * | | + * | | + * | V + * | Active + * | | + * | | + * | /--------------+--------------\ + * | | | + * | | | + * | abortUOW() | | commitUOW() + * | | | + * | V V + * | Aborting Committing + * | | | + * | | | + * | | | + * \--------------+-----------------------------/ + * + */ + enum class State { + kInactive, + kInactiveInUnitOfWork, + kActiveNotInUnitOfWork, + kActive, + kAborting, + kCommitting, + }; + State getState_forTest() const; + + std::string toString(State state) const { + switch (state) { + case State::kInactive: + return "Inactive"; + case State::kInactiveInUnitOfWork: + return "InactiveInUnitOfWork"; + case State::kActiveNotInUnitOfWork: + return "ActiveNotInUnitOfWork"; + case State::kActive: + return "Active"; + case State::kCommitting: + return "Committing"; + case State::kAborting: + return "Aborting"; + } + MONGO_UNREACHABLE; + } + protected: RecoveryUnit() {} + + /** + * Returns the current state. + */ + State _getState() const { + return _state; + } + + /** + * Transitions to new state. + */ + void _setState(State newState) { + _state = newState; + } + + /** + * Returns true if active. + */ + bool _isActive() const { + return State::kActiveNotInUnitOfWork == _state || State::kActive == _state; + } + + /** + * Returns true if currently managed by a WriteUnitOfWork. + */ + bool _inUnitOfWork() const { + return State::kInactiveInUnitOfWork == _state || State::kActive == _state; + } + + /** + * Returns true if currently running commit or rollback handlers + */ + bool _isCommittingOrAborting() const { + return State::kCommitting == _state || State::kAborting == _state; + } + +private: + State _state = State::kInactive; }; } // namespace mongo diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp index 0bfe56fa5d9..d6b09f4c9b0 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp @@ -59,27 +59,6 @@ AtomicWord<unsigned long long> nextSnapshotId{1}; logger::LogSeverity kSlowTransactionSeverity = logger::LogSeverity::Debug(1); -/** - * Returns a string representation of WiredTigerRecoveryUnit::State for logging. - */ -std::string toString(WiredTigerRecoveryUnit::State state) { - switch (state) { - case WiredTigerRecoveryUnit::State::kInactive: - return "Inactive"; - case WiredTigerRecoveryUnit::State::kInactiveInUnitOfWork: - return "InactiveInUnitOfWork"; - case WiredTigerRecoveryUnit::State::kActiveNotInUnitOfWork: - return "ActiveNotInUnitOfWork"; - case WiredTigerRecoveryUnit::State::kActive: - return "Active"; - case WiredTigerRecoveryUnit::State::kCommitting: - return "Committing"; - case WiredTigerRecoveryUnit::State::kAborting: - return "Aborting"; - } - MONGO_UNREACHABLE; -} - } // namespace using Section = WiredTigerOperationStats::Section; @@ -190,7 +169,7 @@ WiredTigerRecoveryUnit::WiredTigerRecoveryUnit(WiredTigerSessionCache* sc, _mySnapshotId(nextSnapshotId.fetchAndAdd(1)) {} WiredTigerRecoveryUnit::~WiredTigerRecoveryUnit() { - invariant(!_inUnitOfWork(), toString(_state)); + invariant(!_inUnitOfWork(), toString(_getState())); _abort(); } @@ -258,16 +237,16 @@ void WiredTigerRecoveryUnit::_abort() { } void WiredTigerRecoveryUnit::beginUnitOfWork(OperationContext* opCtx) { - invariant(!_inUnitOfWork(), toString(_state)); + invariant(!_inUnitOfWork(), toString(_getState())); invariant(!_isCommittingOrAborting(), str::stream() << "cannot begin unit of work while commit or rollback handlers are " "running: " - << toString(_state)); + << toString(_getState())); _setState(_isActive() ? State::kActive : State::kInactiveInUnitOfWork); } void WiredTigerRecoveryUnit::prepareUnitOfWork() { - invariant(_inUnitOfWork(), toString(_state)); + invariant(_inUnitOfWork(), toString(_getState())); invariant(!_prepareTimestamp.isNull()); auto session = getSession(); @@ -281,12 +260,12 @@ void WiredTigerRecoveryUnit::prepareUnitOfWork() { } void WiredTigerRecoveryUnit::commitUnitOfWork() { - invariant(_inUnitOfWork(), toString(_state)); + invariant(_inUnitOfWork(), toString(_getState())); _commit(); } void WiredTigerRecoveryUnit::abortUnitOfWork() { - invariant(_inUnitOfWork(), toString(_state)); + invariant(_inUnitOfWork(), toString(_getState())); _abort(); } @@ -297,7 +276,7 @@ void WiredTigerRecoveryUnit::_ensureSession() { } bool WiredTigerRecoveryUnit::waitUntilDurable() { - invariant(!_inUnitOfWork(), toString(_state)); + invariant(!_inUnitOfWork(), toString(_getState())); const bool forceCheckpoint = false; const bool stableCheckpoint = false; _sessionCache->waitUntilDurable(forceCheckpoint, stableCheckpoint); @@ -305,7 +284,7 @@ bool WiredTigerRecoveryUnit::waitUntilDurable() { } bool WiredTigerRecoveryUnit::waitUntilUnjournaledWritesDurable(bool stableCheckpoint) { - invariant(!_inUnitOfWork(), toString(_state)); + invariant(!_inUnitOfWork(), toString(_getState())); const bool forceCheckpoint = true; // Calling `waitUntilDurable` with `forceCheckpoint` set to false only performs a log // (journal) flush, and thus has no effect on unjournaled writes. Setting `forceCheckpoint` to @@ -315,7 +294,7 @@ bool WiredTigerRecoveryUnit::waitUntilUnjournaledWritesDurable(bool stableCheckp } void WiredTigerRecoveryUnit::registerChange(Change* change) { - invariant(_inUnitOfWork(), toString(_state)); + invariant(_inUnitOfWork(), toString(_getState())); _changes.push_back(std::unique_ptr<Change>{change}); } @@ -323,7 +302,7 @@ void WiredTigerRecoveryUnit::assertInActiveTxn() const { if (_isActive()) { return; } - severe() << "Recovery unit is not active. Current state: " << toString(_state); + severe() << "Recovery unit is not active. Current state: " << toString(_getState()); fassertFailed(28575); } @@ -355,7 +334,7 @@ WiredTigerSession* WiredTigerRecoveryUnit::getSessionNoTxn() { } void WiredTigerRecoveryUnit::abandonSnapshot() { - invariant(!_inUnitOfWork(), toString(_state)); + invariant(!_inUnitOfWork(), toString(_getState())); if (_isActive()) { // Can't be in a WriteUnitOfWork, so safe to rollback _txnClose(false); @@ -369,7 +348,7 @@ void WiredTigerRecoveryUnit::preallocateSnapshot() { } void WiredTigerRecoveryUnit::_txnClose(bool commit) { - invariant(_isActive(), toString(_state)); + invariant(_isActive(), toString(_getState())); WT_SESSION* s = _session->getSession(); if (_timer) { const int transactionTime = _timer->millis(); @@ -506,10 +485,10 @@ boost::optional<Timestamp> WiredTigerRecoveryUnit::getPointInTimeReadTimestamp() } void WiredTigerRecoveryUnit::_txnOpen() { - invariant(!_isActive(), toString(_state)); + invariant(!_isActive(), toString(_getState())); invariant(!_isCommittingOrAborting(), str::stream() << "commit or rollback handler reopened transaction: " - << toString(_state)); + << toString(_getState())); _ensureSession(); // Only start a timer for transaction's lifetime if we're going to log it. @@ -652,7 +631,7 @@ Status WiredTigerRecoveryUnit::setTimestamp(Timestamp timestamp) { _ensureSession(); LOG(3) << "WT set timestamp of future write operations to " << timestamp; WT_SESSION* session = _session->getSession(); - invariant(_inUnitOfWork(), toString(_state)); + invariant(_inUnitOfWork(), toString(_getState())); invariant(_prepareTimestamp.isNull()); invariant(_commitTimestamp.isNull(), str::stream() << "Commit timestamp set to " << _commitTimestamp.toString() @@ -681,7 +660,7 @@ void WiredTigerRecoveryUnit::setCommitTimestamp(Timestamp timestamp) { // setPrepareTimestamp() is called. Prepared transactions ensure the correct timestamping // semantics and the set-once commitTimestamp behavior is exactly what prepared transactions // want. - invariant(!_inUnitOfWork() || !_prepareTimestamp.isNull(), toString(_state)); + invariant(!_inUnitOfWork() || !_prepareTimestamp.isNull(), toString(_getState())); invariant(_commitTimestamp.isNull(), str::stream() << "Commit timestamp set to " << _commitTimestamp.toString() << " and trying to set it to " @@ -715,7 +694,7 @@ Timestamp WiredTigerRecoveryUnit::getDurableTimestamp() const { } void WiredTigerRecoveryUnit::clearCommitTimestamp() { - invariant(!_inUnitOfWork(), toString(_state)); + invariant(!_inUnitOfWork(), toString(_getState())); invariant(!_commitTimestamp.isNull()); invariant(!_lastTimestampSet, str::stream() << "Last timestamp set is " << _lastTimestampSet->toString() @@ -726,7 +705,7 @@ void WiredTigerRecoveryUnit::clearCommitTimestamp() { } void WiredTigerRecoveryUnit::setPrepareTimestamp(Timestamp timestamp) { - invariant(_inUnitOfWork(), toString(_state)); + invariant(_inUnitOfWork(), toString(_getState())); invariant(_prepareTimestamp.isNull(), str::stream() << "Trying to set prepare timestamp to " << timestamp.toString() << ". It's already set to " @@ -744,7 +723,7 @@ void WiredTigerRecoveryUnit::setPrepareTimestamp(Timestamp timestamp) { } Timestamp WiredTigerRecoveryUnit::getPrepareTimestamp() const { - invariant(_inUnitOfWork(), toString(_state)); + invariant(_inUnitOfWork(), toString(_getState())); invariant(!_prepareTimestamp.isNull()); invariant(_commitTimestamp.isNull(), str::stream() << "Commit timestamp is " << _commitTimestamp.toString() @@ -763,7 +742,7 @@ void WiredTigerRecoveryUnit::setPrepareConflictBehavior(PrepareConflictBehavior // ignoring prepare conflicts, since that behavior is applied when the transaction is opened. invariant( !_isActive(), - str::stream() << "Current state: " << toString(_state) + str::stream() << "Current state: " << toString(_getState()) << ". Invalid internal state while setting prepare conflict behavior to: " << static_cast<int>(behavior)); @@ -779,7 +758,7 @@ void WiredTigerRecoveryUnit::setRoundUpPreparedTimestamps(bool value) { invariant(!_isActive(), str::stream() << "Can't change round up prepared timestamps flag " << "when current state is " - << toString(_state)); + << toString(_getState())); _roundUpPreparedTimestamps = (value) ? RoundUpPreparedTimestamps::kRound : RoundUpPreparedTimestamps::kNoRound; } @@ -790,7 +769,7 @@ void WiredTigerRecoveryUnit::setTimestampReadSource(ReadSource readSource, << ", provided timestamp: " << ((provided) ? provided->toString() : "none"); invariant(!_isActive() || _timestampReadSource == readSource, - str::stream() << "Current state: " << toString(_state) + str::stream() << "Current state: " << toString(_getState()) << ". Invalid internal state while setting timestamp read source: " << static_cast<int>(readSource) << ", provided timestamp: " @@ -828,20 +807,4 @@ std::shared_ptr<StorageStats> WiredTigerRecoveryUnit::getOperationStatistics() c return statsPtr; } -void WiredTigerRecoveryUnit::_setState(State newState) { - _state = newState; -} - -bool WiredTigerRecoveryUnit::_isActive() const { - return State::kActiveNotInUnitOfWork == _state || State::kActive == _state; -} - -bool WiredTigerRecoveryUnit::_inUnitOfWork() const { - return State::kInactiveInUnitOfWork == _state || State::kActive == _state; -} - -bool WiredTigerRecoveryUnit::_isCommittingOrAborting() const { - return State::kCommitting == _state || State::kAborting == _state; -} - } // namespace mongo diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h index f3e6b31162b..7b480ee82bb 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h @@ -201,53 +201,6 @@ public: static void appendGlobalStats(BSONObjBuilder& b); - /** - * State transitions: - * - * /------------------------> Inactive <-----------------------------\ - * | | | - * | | | - * | /--------------+--------------\ | - * | | | | abandonSnapshot() - * | | | | - * | beginUOW() | | _txnOpen() | - * | | | | - * | V V | - * | InactiveInUnitOfWork ActiveNotInUnitOfWork ---------/ - * | | | - * | | | - * | _txnOpen() | | beginUOW() - * | | | - * | \--------------+--------------/ - * | | - * | | - * | V - * | Active - * | | - * | | - * | /--------------+--------------\ - * | | | - * | | | - * | abortUOW() | | commitUOW() - * | | | - * | V V - * | Aborting Committing - * | | | - * | | | - * | | | - * \--------------+-----------------------------/ - * - */ - enum class State { - kInactive, - kInactiveInUnitOfWork, - kActiveNotInUnitOfWork, - kActive, - kAborting, - kCommitting, - }; - State getState_forTest() const; - private: void _abort(); void _commit(); @@ -273,30 +226,9 @@ private: */ Timestamp _getTransactionReadTimestamp(WT_SESSION* session); - /** - * Transitions to new state. - */ - void _setState(State newState); - - /** - * Returns true if active. - */ - bool _isActive() const; - - /** - * Returns true if currently managed by a WriteUnitOfWork. - */ - bool _inUnitOfWork() const; - - /** - * Returns true if currently running commit or rollback handlers - */ - bool _isCommittingOrAborting() const; - WiredTigerSessionCache* _sessionCache; // not owned WiredTigerOplogManager* _oplogManager; // not owned UniqueWiredTigerSession _session; - State _state = State::kInactive; bool _isTimestamped = false; // Specifies which external source to use when setting read timestamps on transactions. |