summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenrik Edin <henrik.edin@mongodb.com>2018-09-27 11:52:50 -0400
committerHenrik Edin <henrik.edin@mongodb.com>2018-10-04 10:18:00 -0400
commit6d71a539ce484770c9830f59e3984130a7100dbd (patch)
tree132f80ad9dd4446c4c98bb451a28f99cef49d1b4
parent68fe3afd3b7b3037a18deea5c063256027e5e029 (diff)
downloadmongo-6d71a539ce484770c9830f59e3984130a7100dbd.tar.gz
SERVER-37300 Move the transaction coordinator to separate lib and remove embedded dependency to it.
-rw-r--r--src/mongo/db/SConscript31
-rw-r--r--src/mongo/db/operation_context_session_mongod.cpp11
-rw-r--r--src/mongo/db/s/SConscript1
-rw-r--r--src/mongo/db/transaction_coordinator_factory.cpp33
-rw-r--r--src/mongo/db/transaction_coordinator_factory.h38
-rw-r--r--src/mongo/db/transaction_coordinator_factory_mongod.cpp46
-rw-r--r--src/mongo/embedded/SConscript1
-rw-r--r--src/mongo/embedded/transaction_coordinator_factory_embedded.cpp34
8 files changed, 179 insertions, 16 deletions
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript
index 708fc4514c5..3908d564117 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -617,6 +617,26 @@ env.Library(
)
env.Library(
+ target='transaction_coordinator',
+ source=[
+ 'transaction_coordinator.cpp',
+ 'transaction_coordinator_catalog.cpp',
+ 'transaction_coordinator_factory_mongod.cpp',
+ 'transaction_coordinator_service.cpp',
+ 'transaction_coordinator_commands_impl.cpp',
+ ],
+ LIBDEPS=[
+ '$BUILD_DIR/mongo/base',
+ 'catalog_raii',
+ ],
+ LIBDEPS_PRIVATE=[
+ '$BUILD_DIR/mongo/db/commands/txn_cmd_request',
+ '$BUILD_DIR/mongo/s/async_requests_sender',
+ '$BUILD_DIR/mongo/s/grid',
+ ]
+)
+
+env.Library(
target='catalog_raii',
source=[
'catalog_raii.cpp',
@@ -626,10 +646,7 @@ env.Library(
'session.cpp',
'session_catalog.cpp',
'single_transaction_stats.cpp',
- 'transaction_coordinator.cpp',
- 'transaction_coordinator_catalog.cpp',
- 'transaction_coordinator_service.cpp',
- 'transaction_coordinator_commands_impl.cpp',
+ 'transaction_coordinator_factory.cpp',
'transaction_metrics_observer.cpp',
'transaction_participant.cpp',
'transaction_history_iterator.cpp',
@@ -640,8 +657,6 @@ env.Library(
LIBDEPS=[
'$BUILD_DIR/mongo/db/stats/fill_locker_info',
'$BUILD_DIR/mongo/idl/idl_parser',
- '$BUILD_DIR/mongo/s/async_requests_sender',
- '$BUILD_DIR/mongo/s/grid',
'catalog/collection',
'catalog/database',
'catalog/database_holder',
@@ -652,6 +667,7 @@ env.Library(
'curop_metrics',
'dbdirectclient',
'index/index_access_method',
+ 'kill_sessions',
'logical_session_id',
'namespace_string',
'repl/oplog_entry',
@@ -680,7 +696,7 @@ env.CppUnitTest(
'$BUILD_DIR/mongo/s/catalog/sharding_catalog_client_mock',
'$BUILD_DIR/mongo/s/shard_server_test_fixture',
'auth/authmocks',
- 'catalog_raii',
+ 'transaction_coordinator',
],
)
@@ -824,6 +840,7 @@ env.Library(
'$BUILD_DIR/mongo/db/stats/top',
'$BUILD_DIR/mongo/db/storage/storage_engine_lock_file',
'$BUILD_DIR/mongo/db/storage/storage_engine_metadata',
+ '$BUILD_DIR/mongo/s/grid',
],
)
diff --git a/src/mongo/db/operation_context_session_mongod.cpp b/src/mongo/db/operation_context_session_mongod.cpp
index 7ae26abcd2c..0e79480b31c 100644
--- a/src/mongo/db/operation_context_session_mongod.cpp
+++ b/src/mongo/db/operation_context_session_mongod.cpp
@@ -28,8 +28,7 @@
#include "mongo/db/operation_context_session_mongod.h"
-#include "mongo/db/transaction_coordinator.h"
-#include "mongo/db/transaction_coordinator_service.h"
+#include "mongo/db/transaction_coordinator_factory.h"
#include "mongo/db/transaction_participant.h"
namespace mongo {
@@ -49,16 +48,10 @@ OperationContextSessionMongod::OperationContextSessionMongod(OperationContext* o
session->beginOrContinueTxn(opCtx, clientTxnNumber);
if (startTransaction && *startTransaction) {
- auto clientLsid = opCtx->getLogicalSessionId().get();
- auto clockSource = opCtx->getServiceContext()->getFastClockSource();
-
// If this shard has been selected as the coordinator, set up the coordinator state
// to be ready to receive votes.
if (coordinator && *coordinator) {
- TransactionCoordinatorService::get(opCtx)->createCoordinator(
- clientLsid,
- clientTxnNumber,
- clockSource->now() + Seconds(transactionLifetimeLimitSeconds.load()));
+ createTransactionCoordinator(opCtx, clientTxnNumber);
}
}
diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript
index f99ed28e113..458e8bd7148 100644
--- a/src/mongo/db/s/SConscript
+++ b/src/mongo/db/s/SConscript
@@ -296,6 +296,7 @@ env.Library(
'$BUILD_DIR/mongo/db/index_d',
'$BUILD_DIR/mongo/db/repl/repl_coordinator_interface',
'$BUILD_DIR/mongo/db/repl/replica_set_messages',
+ '$BUILD_DIR/mongo/db/transaction_coordinator',
'$BUILD_DIR/mongo/s/commands/shared_cluster_commands',
'$BUILD_DIR/mongo/s/sharding_router_api',
'$BUILD_DIR/mongo/s/sharding_initialization',
diff --git a/src/mongo/db/transaction_coordinator_factory.cpp b/src/mongo/db/transaction_coordinator_factory.cpp
new file mode 100644
index 00000000000..007f7219b3e
--- /dev/null
+++ b/src/mongo/db/transaction_coordinator_factory.cpp
@@ -0,0 +1,33 @@
+/*
+ * 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.
+ */
+
+#include "mongo/db/transaction_coordinator_factory.h"
+
+namespace mongo {
+MONGO_DEFINE_SHIM(createTransactionCoordinator);
+}
diff --git a/src/mongo/db/transaction_coordinator_factory.h b/src/mongo/db/transaction_coordinator_factory.h
new file mode 100644
index 00000000000..563fdcc9405
--- /dev/null
+++ b/src/mongo/db/transaction_coordinator_factory.h
@@ -0,0 +1,38 @@
+/*
+ * 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 "mongo/base/shim.h"
+#include "mongo/db/logical_session_id.h"
+#include "mongo/db/operation_context.h"
+
+namespace mongo {
+extern MONGO_DECLARE_SHIM((OperationContext * opCtx, TxnNumber clientTxnNumber)->void)
+ createTransactionCoordinator;
+} // namespace mongo
diff --git a/src/mongo/db/transaction_coordinator_factory_mongod.cpp b/src/mongo/db/transaction_coordinator_factory_mongod.cpp
new file mode 100644
index 00000000000..767700e7395
--- /dev/null
+++ b/src/mongo/db/transaction_coordinator_factory_mongod.cpp
@@ -0,0 +1,46 @@
+/*
+ * 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.
+ */
+
+#include "mongo/db/transaction_coordinator_factory.h"
+#include "mongo/db/transaction_coordinator_service.h"
+#include "mongo/db/transaction_participant.h"
+
+namespace mongo {
+MONGO_REGISTER_SHIM(createTransactionCoordinator)
+(OperationContext* opCtx, TxnNumber clientTxnNumber)->void {
+ auto clientLsid = opCtx->getLogicalSessionId().get();
+ auto clockSource = opCtx->getServiceContext()->getFastClockSource();
+
+ // If this shard has been selected as the coordinator, set up the coordinator state
+ // to be ready to receive votes.
+ TransactionCoordinatorService::get(opCtx)->createCoordinator(
+ clientLsid,
+ clientTxnNumber,
+ clockSource->now() + Seconds(transactionLifetimeLimitSeconds.load()));
+}
+} // namespace mongo
diff --git a/src/mongo/embedded/SConscript b/src/mongo/embedded/SConscript
index 5b54fadee8d..a46205b2cd3 100644
--- a/src/mongo/embedded/SConscript
+++ b/src/mongo/embedded/SConscript
@@ -69,6 +69,7 @@ env.Library(
'process_interface_factory_embedded.cpp',
'replication_coordinator_embedded.cpp',
'service_entry_point_embedded.cpp',
+ 'transaction_coordinator_factory_embedded.cpp',
],
LIBDEPS=[
'$BUILD_DIR/mongo/base',
diff --git a/src/mongo/embedded/transaction_coordinator_factory_embedded.cpp b/src/mongo/embedded/transaction_coordinator_factory_embedded.cpp
new file mode 100644
index 00000000000..7158bd2e020
--- /dev/null
+++ b/src/mongo/embedded/transaction_coordinator_factory_embedded.cpp
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+
+#include "mongo/db/transaction_coordinator_factory.h"
+
+namespace mongo {
+MONGO_REGISTER_SHIM(createTransactionCoordinator)
+(OperationContext* opCtx, TxnNumber clientTxnNumber)->void {}
+} // namespace mongo