summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaria van Keulen <maria@mongodb.com>2019-06-21 15:28:29 -0400
committerMaria van Keulen <maria@mongodb.com>2019-06-24 15:39:06 -0400
commit5c5832b459baa56b6bee172ee13fca97518436e2 (patch)
tree7cefef1040c8d477f12ec2379b458591a5c30553 /src
parent3bf10866faf60721d75aa78f6ea1df88f838fd52 (diff)
downloadmongo-5c5832b459baa56b6bee172ee13fca97518436e2.tar.gz
SERVER-18867 Move Changes logic into RecoveryUnit
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/SConscript1
-rw-r--r--src/mongo/db/storage/SConscript10
-rw-r--r--src/mongo/db/storage/biggie/SConscript1
-rw-r--r--src/mongo/db/storage/biggie/biggie_recovery_unit.cpp31
-rw-r--r--src/mongo/db/storage/biggie/biggie_recovery_unit.h5
-rw-r--r--src/mongo/db/storage/ephemeral_for_test/SConscript1
-rw-r--r--src/mongo/db/storage/mobile/SConscript1
-rw-r--r--src/mongo/db/storage/mobile/mobile_recovery_unit.cpp26
-rw-r--r--src/mongo/db/storage/mobile/mobile_recovery_unit.h5
-rw-r--r--src/mongo/db/storage/recovery_unit.cpp68
-rw-r--r--src/mongo/db/storage/recovery_unit.h6
-rw-r--r--src/mongo/db/storage/wiredtiger/SConscript1
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp67
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h4
14 files changed, 112 insertions, 115 deletions
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript
index cdd4fa310b7..4a232e470f0 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -378,6 +378,7 @@ env.Library(
'$BUILD_DIR/mongo/base',
'$BUILD_DIR/mongo/db/logical_session_id',
'$BUILD_DIR/mongo/db/multi_key_path_tracker',
+ '$BUILD_DIR/mongo/db/storage/recovery_unit_base',
'$BUILD_DIR/mongo/db/storage/write_unit_of_work',
'$BUILD_DIR/mongo/util/clock_sources',
'$BUILD_DIR/mongo/util/concurrency/spin_lock',
diff --git a/src/mongo/db/storage/SConscript b/src/mongo/db/storage/SConscript
index 4b3751f7a05..cbc33342482 100644
--- a/src/mongo/db/storage/SConscript
+++ b/src/mongo/db/storage/SConscript
@@ -49,6 +49,16 @@ env.Library(
)
env.Library(
+ target='recovery_unit_base',
+ source=[
+ 'recovery_unit.cpp',
+ ],
+ LIBDEPS=[
+ '$BUILD_DIR/mongo/base',
+ ],
+ )
+
+env.Library(
target='key_string',
source=[
'key_string.cpp',
diff --git a/src/mongo/db/storage/biggie/SConscript b/src/mongo/db/storage/biggie/SConscript
index a86d5a8cbfd..de9ef74c8ab 100644
--- a/src/mongo/db/storage/biggie/SConscript
+++ b/src/mongo/db/storage/biggie/SConscript
@@ -18,6 +18,7 @@ env.Library(
'$BUILD_DIR/mongo/db/concurrency/write_conflict_exception',
'$BUILD_DIR/mongo/db/storage/index_entry_comparison',
'$BUILD_DIR/mongo/db/storage/kv/kv_prefix',
+ '$BUILD_DIR/mongo/db/storage/recovery_unit_base',
],
LIBDEPS_PRIVATE=[
'$BUILD_DIR/mongo/db/storage/key_string',
diff --git a/src/mongo/db/storage/biggie/biggie_recovery_unit.cpp b/src/mongo/db/storage/biggie/biggie_recovery_unit.cpp
index 0d6d1a610bd..63bae7e8f6f 100644
--- a/src/mongo/db/storage/biggie/biggie_recovery_unit.cpp
+++ b/src/mongo/db/storage/biggie/biggie_recovery_unit.cpp
@@ -80,15 +80,8 @@ void RecoveryUnit::commitUnitOfWork() {
DEV invariant(_mergeBase == _workingCopy);
}
- try {
- _setState(State::kCommitting);
- for (auto& change : _changes)
- change->commit(boost::none);
- _changes.clear();
- } catch (...) {
- std::terminate();
- }
-
+ _setState(State::kCommitting);
+ commitRegisteredChanges(boost::none);
_setState(State::kInactive);
}
@@ -108,11 +101,6 @@ void RecoveryUnit::abandonSnapshot() {
_dirty = false;
}
-void RecoveryUnit::registerChange(Change* change) {
- invariant(_inUnitOfWork(), toString(_getState()));
- _changes.push_back(std::unique_ptr<Change>{change});
-}
-
SnapshotId RecoveryUnit::getSnapshotId() const {
return SnapshotId();
}
@@ -139,20 +127,7 @@ void RecoveryUnit::_abort() {
_forked = false;
_dirty = false;
_setState(State::kAborting);
-
- try {
- for (Changes::const_reverse_iterator it = _changes.rbegin(), end = _changes.rend();
- it != end;
- ++it) {
- Change* change = it->get();
- LOG(2) << "CUSTOM ROLLBACK " << redact(demangleName(typeid(*change)));
- change->rollback();
- }
- _changes.clear();
- } catch (...) {
- std::terminate();
- }
-
+ abortRegisteredChanges();
_setState(State::kInactive);
}
diff --git a/src/mongo/db/storage/biggie/biggie_recovery_unit.h b/src/mongo/db/storage/biggie/biggie_recovery_unit.h
index df282d8c1e0..e3bca95885d 100644
--- a/src/mongo/db/storage/biggie/biggie_recovery_unit.h
+++ b/src/mongo/db/storage/biggie/biggie_recovery_unit.h
@@ -57,8 +57,6 @@ public:
virtual void abandonSnapshot() override;
- virtual void registerChange(Change* change) override;
-
virtual SnapshotId getSnapshotId() const override;
virtual void setOrderedCommit(bool orderedCommit) override;
@@ -92,9 +90,6 @@ private:
bool _forked = false;
bool _dirty = false; // Whether or not we have written to this _workingCopy.
-
- typedef std::vector<std::unique_ptr<Change>> Changes;
- Changes _changes;
};
} // namespace biggie
diff --git a/src/mongo/db/storage/ephemeral_for_test/SConscript b/src/mongo/db/storage/ephemeral_for_test/SConscript
index cf015f545e4..83161eb47de 100644
--- a/src/mongo/db/storage/ephemeral_for_test/SConscript
+++ b/src/mongo/db/storage/ephemeral_for_test/SConscript
@@ -31,6 +31,7 @@ env.Library(
'$BUILD_DIR/mongo/db/repl/repl_coordinator_interface',
'$BUILD_DIR/mongo/db/storage/index_entry_comparison',
'$BUILD_DIR/mongo/db/storage/journal_listener',
+ '$BUILD_DIR/mongo/db/storage/recovery_unit_base',
'$BUILD_DIR/mongo/db/storage/kv/kv_prefix',
]
)
diff --git a/src/mongo/db/storage/mobile/SConscript b/src/mongo/db/storage/mobile/SConscript
index 8c7d1012d99..a90a7ba9eb2 100644
--- a/src/mongo/db/storage/mobile/SConscript
+++ b/src/mongo/db/storage/mobile/SConscript
@@ -30,6 +30,7 @@ env.Library(
'$BUILD_DIR/mongo/db/storage/index_entry_comparison',
'$BUILD_DIR/mongo/db/storage/journal_listener',
'$BUILD_DIR/mongo/db/storage/key_string',
+ '$BUILD_DIR/mongo/db/storage/recovery_unit_base',
'$BUILD_DIR/mongo/db/storage/kv/kv_prefix',
'$BUILD_DIR/mongo/db/storage/oplog_hack',
'$BUILD_DIR/third_party/shim_sqlite',
diff --git a/src/mongo/db/storage/mobile/mobile_recovery_unit.cpp b/src/mongo/db/storage/mobile/mobile_recovery_unit.cpp
index a3c9ba831ba..cbb59b061a9 100644
--- a/src/mongo/db/storage/mobile/mobile_recovery_unit.cpp
+++ b/src/mongo/db/storage/mobile/mobile_recovery_unit.cpp
@@ -68,16 +68,7 @@ void MobileRecoveryUnit::_commit() {
_txnClose(true);
}
_setState(State::kCommitting);
-
- for (auto& change : _changes) {
- try {
- change->commit(boost::none);
- } catch (...) {
- std::terminate();
- }
- }
- _changes.clear();
-
+ commitRegisteredChanges(boost::none);
_setState(State::kInactive);
}
@@ -86,17 +77,9 @@ void MobileRecoveryUnit::_abort() {
_txnClose(false);
}
_setState(State::kAborting);
+ abortRegisteredChanges();
- for (auto it = _changes.rbegin(); it != _changes.rend(); ++it) {
- try {
- (*it)->rollback();
- } catch (...) {
- std::terminate();
- }
- }
- _changes.clear();
invariant(!_isActive(), toString(_getState()));
-
_setState(State::kInactive);
}
@@ -176,11 +159,6 @@ void MobileRecoveryUnit::abandonSnapshot() {
_setState(State::kInactive);
}
-void MobileRecoveryUnit::registerChange(Change* change) {
- 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");
diff --git a/src/mongo/db/storage/mobile/mobile_recovery_unit.h b/src/mongo/db/storage/mobile/mobile_recovery_unit.h
index 2e1ff023c35..bf8917dda3a 100644
--- a/src/mongo/db/storage/mobile/mobile_recovery_unit.h
+++ b/src/mongo/db/storage/mobile/mobile_recovery_unit.h
@@ -58,8 +58,6 @@ public:
void abandonSnapshot() override;
- void registerChange(Change* change) override;
-
SnapshotId getSnapshotId() const override {
return SnapshotId();
}
@@ -98,9 +96,6 @@ private:
std::string _path;
MobileSessionPool* _sessionPool;
std::unique_ptr<MobileSession> _session;
-
- using Changes = std::vector<std::unique_ptr<Change>>;
- Changes _changes;
};
} // namespace mongo
diff --git a/src/mongo/db/storage/recovery_unit.cpp b/src/mongo/db/storage/recovery_unit.cpp
new file mode 100644
index 00000000000..6bb63b332b6
--- /dev/null
+++ b/src/mongo/db/storage/recovery_unit.cpp
@@ -0,0 +1,68 @@
+/**
+ * Copyright (C) 2019-present MongoDB, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the Server Side Public License, version 1,
+ * as published by MongoDB, Inc.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Server Side Public License for more details.
+ *
+ * You should have received a copy of the Server Side Public License
+ * along with this program. If not, see
+ * <http://www.mongodb.com/licensing/server-side-public-license>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the Server Side Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kStorage
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/db/storage/recovery_unit.h"
+#include "mongo/util/log.h"
+
+namespace mongo {
+void RecoveryUnit::registerChange(Change* change) {
+ invariant(_inUnitOfWork());
+ _changes.push_back(std::unique_ptr<Change>{change});
+}
+
+void RecoveryUnit::commitRegisteredChanges(boost::optional<Timestamp> commitTimestamp) {
+ for (auto& change : _changes) {
+ try {
+ change->commit(commitTimestamp);
+ } catch (...) {
+ std::terminate();
+ }
+ }
+ _changes.clear();
+}
+
+void RecoveryUnit::abortRegisteredChanges() {
+ try {
+ for (Changes::const_reverse_iterator it = _changes.rbegin(), end = _changes.rend();
+ it != end;
+ ++it) {
+ Change* change = it->get();
+ LOG(2) << "CUSTOM ROLLBACK " << redact(demangleName(typeid(*change)));
+ change->rollback();
+ }
+ _changes.clear();
+ } catch (...) {
+ std::terminate();
+ }
+}
+} // namespace mongo
diff --git a/src/mongo/db/storage/recovery_unit.h b/src/mongo/db/storage/recovery_unit.h
index c8b04493e8f..dcc8a37482f 100644
--- a/src/mongo/db/storage/recovery_unit.h
+++ b/src/mongo/db/storage/recovery_unit.h
@@ -114,6 +114,8 @@ class RecoveryUnit {
RecoveryUnit& operator=(const RecoveryUnit&) = delete;
public:
+ void commitRegisteredChanges(boost::optional<Timestamp> commitTimestamp);
+ void abortRegisteredChanges();
virtual ~RecoveryUnit() {}
/**
@@ -444,7 +446,7 @@ public:
* The registerChange() method may only be called when a WriteUnitOfWork is active, and
* may not be called during commit or rollback.
*/
- virtual void registerChange(Change* change) = 0;
+ virtual void registerChange(Change* change);
/**
* Registers a callback to be called if the current WriteUnitOfWork rolls back.
@@ -596,6 +598,8 @@ protected:
}
private:
+ typedef std::vector<std::unique_ptr<Change>> Changes;
+ Changes _changes;
State _state = State::kInactive;
};
diff --git a/src/mongo/db/storage/wiredtiger/SConscript b/src/mongo/db/storage/wiredtiger/SConscript
index d1ec377be9c..1fb51968c66 100644
--- a/src/mongo/db/storage/wiredtiger/SConscript
+++ b/src/mongo/db/storage/wiredtiger/SConscript
@@ -72,6 +72,7 @@ if wiredtiger:
'$BUILD_DIR/mongo/db/storage/key_string',
'$BUILD_DIR/mongo/db/storage/kv/kv_prefix',
'$BUILD_DIR/mongo/db/storage/oplog_hack',
+ '$BUILD_DIR/mongo/db/storage/recovery_unit_base',
'$BUILD_DIR/mongo/db/storage/storage_file_util',
'$BUILD_DIR/mongo/db/storage/storage_options',
'$BUILD_DIR/mongo/util/concurrency/ticketholder',
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp
index d6b09f4c9b0..6998b790318 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.cpp
@@ -179,60 +179,36 @@ void WiredTigerRecoveryUnit::_commit() {
// be boost::none and we'll set the commit time to that.
auto commitTime = _commitTimestamp.isNull() ? _lastTimestampSet : _commitTimestamp;
- try {
- bool notifyDone = !_prepareTimestamp.isNull();
- if (_session && _isActive()) {
- _txnClose(true);
- }
- _setState(State::kCommitting);
-
- if (MONGO_FAIL_POINT(WTAlwaysNotifyPrepareConflictWaiters)) {
- notifyDone = true;
- }
+ bool notifyDone = !_prepareTimestamp.isNull();
+ if (_session && _isActive()) {
+ _txnClose(true);
+ }
+ _setState(State::kCommitting);
- if (notifyDone) {
- _sessionCache->notifyPreparedUnitOfWorkHasCommittedOrAborted();
- }
+ if (MONGO_FAIL_POINT(WTAlwaysNotifyPrepareConflictWaiters)) {
+ notifyDone = true;
+ }
- for (Changes::const_iterator it = _changes.begin(), end = _changes.end(); it != end; ++it) {
- (*it)->commit(commitTime);
- }
- _changes.clear();
- } catch (...) {
- std::terminate();
+ if (notifyDone) {
+ _sessionCache->notifyPreparedUnitOfWorkHasCommittedOrAborted();
}
+ commitRegisteredChanges(commitTime);
_setState(State::kInactive);
}
void WiredTigerRecoveryUnit::_abort() {
- try {
- bool notifyDone = !_prepareTimestamp.isNull();
- if (_session && _isActive()) {
- _txnClose(false);
- }
- _setState(State::kAborting);
-
- if (MONGO_FAIL_POINT(WTAlwaysNotifyPrepareConflictWaiters)) {
- notifyDone = true;
- }
-
- if (notifyDone) {
- _sessionCache->notifyPreparedUnitOfWorkHasCommittedOrAborted();
- }
+ bool notifyDone = !_prepareTimestamp.isNull();
+ if (_session && _isActive()) {
+ _txnClose(false);
+ }
+ _setState(State::kAborting);
- for (Changes::const_reverse_iterator it = _changes.rbegin(), end = _changes.rend();
- it != end;
- ++it) {
- Change* change = it->get();
- LOG(2) << "CUSTOM ROLLBACK " << redact(demangleName(typeid(*change)));
- change->rollback();
- }
- _changes.clear();
- } catch (...) {
- std::terminate();
+ if (notifyDone || MONGO_FAIL_POINT(WTAlwaysNotifyPrepareConflictWaiters)) {
+ _sessionCache->notifyPreparedUnitOfWorkHasCommittedOrAborted();
}
+ abortRegisteredChanges();
_setState(State::kInactive);
}
@@ -293,11 +269,6 @@ bool WiredTigerRecoveryUnit::waitUntilUnjournaledWritesDurable(bool stableCheckp
return true;
}
-void WiredTigerRecoveryUnit::registerChange(Change* change) {
- invariant(_inUnitOfWork(), toString(_getState()));
- _changes.push_back(std::unique_ptr<Change>{change});
-}
-
void WiredTigerRecoveryUnit::assertInActiveTxn() const {
if (_isActive()) {
return;
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h
index 7b480ee82bb..7ed61acf29b 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h
@@ -111,8 +111,6 @@ public:
bool waitUntilUnjournaledWritesDurable(bool stableCheckpoint = true) override;
- void registerChange(Change* change) override;
-
void abandonSnapshot() override;
void preallocateSnapshot() override;
@@ -255,8 +253,6 @@ private:
std::unique_ptr<Timer> _timer;
bool _isOplogReader = false;
boost::optional<int64_t> _oplogVisibleTs = boost::none;
- typedef std::vector<std::unique_ptr<Change>> Changes;
- Changes _changes;
};
} // namespace mongo