summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/db/SConscript2
-rw-r--r--src/mongo/db/session.h2
-rw-r--r--src/mongo/db/transaction_coordinator.cpp53
-rw-r--r--src/mongo/db/transaction_coordinator.h55
-rw-r--r--src/mongo/db/transaction_participant.cpp53
-rw-r--r--src/mongo/db/transaction_participant.h55
6 files changed, 219 insertions, 1 deletions
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript
index 54445e732fd..7739779e9cc 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -615,6 +615,8 @@ env.Library(
'server_transactions_metrics.cpp',
'session.cpp',
'session_catalog.cpp',
+ 'transaction_coordinator.cpp',
+ 'transaction_participant.cpp',
'transaction_history_iterator.cpp',
env.Idlc('session_txn_record.idl')[0],
env.Idlc('transactions_stats.idl')[0],
diff --git a/src/mongo/db/session.h b/src/mongo/db/session.h
index e95ba535ae4..53a22f0cc82 100644
--- a/src/mongo/db/session.h
+++ b/src/mongo/db/session.h
@@ -60,7 +60,7 @@ class UpdateRequest;
* refresh' (in which case refreshFromStorageIfNeeded needs to be called in order to make it
* up-to-date).
*/
-class Session {
+class Session : public Decorable<Session> {
MONGO_DISALLOW_COPYING(Session);
public:
diff --git a/src/mongo/db/transaction_coordinator.cpp b/src/mongo/db/transaction_coordinator.cpp
new file mode 100644
index 00000000000..c0f6811746c
--- /dev/null
+++ b/src/mongo/db/transaction_coordinator.cpp
@@ -0,0 +1,53 @@
+/**
+ * Copyright (C) 2018 MongoDB, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * 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
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * 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 GNU Affero General 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::kSharding
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/db/transaction_coordinator.h"
+
+#include "mongo/db/session.h"
+
+namespace mongo {
+
+namespace {
+const Session::Decoration<boost::optional<TransactionCoordinator>> getTransactionCoordinator =
+ Session::declareDecoration<boost::optional<TransactionCoordinator>>();
+} // namespace
+
+boost::optional<TransactionCoordinator>& TransactionCoordinator::get(Session* session) {
+ return getTransactionCoordinator(session);
+}
+
+void TransactionCoordinator::create(Session* session) {
+ invariant(!getTransactionCoordinator(session));
+ getTransactionCoordinator(session).emplace();
+}
+
+} // namespace mongo
diff --git a/src/mongo/db/transaction_coordinator.h b/src/mongo/db/transaction_coordinator.h
new file mode 100644
index 00000000000..a74a607bfdd
--- /dev/null
+++ b/src/mongo/db/transaction_coordinator.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2018 MongoDB, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * 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
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * 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 GNU Affero General 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.
+ */
+
+#pragma once
+
+#include <boost/optional.hpp>
+
+#include "mongo/base/disallow_copying.h"
+#include "mongo/util/decorable.h"
+
+namespace mongo {
+
+class Session;
+
+/**
+ * A state machine that coordinates a distributed transaction commit with the transaction
+ * participants.
+ */
+class TransactionCoordinator {
+ MONGO_DISALLOW_COPYING(TransactionCoordinator);
+
+public:
+ TransactionCoordinator() = default;
+ ~TransactionCoordinator() = default;
+
+ static boost::optional<TransactionCoordinator>& get(Session* session);
+ static void create(Session* session);
+};
+
+} // namespace mongo
diff --git a/src/mongo/db/transaction_participant.cpp b/src/mongo/db/transaction_participant.cpp
new file mode 100644
index 00000000000..91b32184f97
--- /dev/null
+++ b/src/mongo/db/transaction_participant.cpp
@@ -0,0 +1,53 @@
+/**
+ * Copyright (C) 2018 MongoDB, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * 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
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * 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 GNU Affero General 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::kSharding
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/db/transaction_participant.h"
+
+#include "mongo/db/session.h"
+
+namespace mongo {
+
+namespace {
+const Session::Decoration<boost::optional<TransactionParticipant>> getTransactionParticipant =
+ Session::declareDecoration<boost::optional<TransactionParticipant>>();
+} // namespace
+
+boost::optional<TransactionParticipant>& TransactionParticipant::get(Session* session) {
+ return getTransactionParticipant(session);
+}
+
+void TransactionParticipant::create(Session* session) {
+ invariant(!getTransactionParticipant(session));
+ getTransactionParticipant(session).emplace();
+}
+
+} // namespace mongo
diff --git a/src/mongo/db/transaction_participant.h b/src/mongo/db/transaction_participant.h
new file mode 100644
index 00000000000..57fef52c023
--- /dev/null
+++ b/src/mongo/db/transaction_participant.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2018 MongoDB, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * 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
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * 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 GNU Affero General 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.
+ */
+
+#pragma once
+
+#include <boost/optional.hpp>
+
+#include "mongo/base/disallow_copying.h"
+#include "mongo/util/decorable.h"
+
+namespace mongo {
+
+class Session;
+
+/**
+ * A state machine that coordinates a distributed transaction commit with the transaction
+ * coordinator.
+ */
+class TransactionParticipant {
+ MONGO_DISALLOW_COPYING(TransactionParticipant);
+
+public:
+ TransactionParticipant() = default;
+ ~TransactionParticipant() = default;
+
+ static boost::optional<TransactionParticipant>& get(Session* session);
+ static void create(Session* session);
+};
+
+} // namespace mongo