summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEsha Maharishi <esha.maharishi@mongodb.com>2018-08-09 13:41:38 -0400
committerEsha Maharishi <esha.maharishi@mongodb.com>2018-08-09 15:17:10 -0400
commit80a858db1a1077087743e98ece9c81f7c274ba82 (patch)
treeee08cff3084cdd0d31a4bf71e5c49da26d706103
parent0faa26ed8b17295b071edb9c4debadada899aeb2 (diff)
downloadmongo-80a858db1a1077087743e98ece9c81f7c274ba82.tar.gz
SERVER-36560 Move the coordinateCommitTransaction command into txn_two_phase_commit_cmds.cpp
-rw-r--r--src/mongo/db/s/SConscript2
-rw-r--r--src/mongo/db/s/coordinate_commit_transaction.idl39
-rw-r--r--src/mongo/db/s/coordinate_commit_transaction_command.cpp98
-rw-r--r--src/mongo/db/s/txn_two_phase_commit_cmds.cpp57
-rw-r--r--src/mongo/db/s/txn_two_phase_commit_cmds.idl21
5 files changed, 76 insertions, 141 deletions
diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript
index b81dee88169..bf7ee5a5022 100644
--- a/src/mongo/db/s/SConscript
+++ b/src/mongo/db/s/SConscript
@@ -138,7 +138,6 @@ env.Library(
env.Library(
target='sharded_transaction_types',
source=[
- env.Idlc('coordinate_commit_transaction.idl')[0],
env.Idlc('prepare_transaction.idl')[0],
],
LIBDEPS=[
@@ -290,7 +289,6 @@ env.Library(
'config/configsvr_shard_collection_command.cpp',
'config/configsvr_split_chunk_command.cpp',
'config/configsvr_update_zone_key_range_command.cpp',
- 'coordinate_commit_transaction_command.cpp',
'txn_two_phase_commit_cmds.cpp',
'flush_database_cache_updates_command.cpp',
'flush_routing_table_cache_updates_command.cpp',
diff --git a/src/mongo/db/s/coordinate_commit_transaction.idl b/src/mongo/db/s/coordinate_commit_transaction.idl
deleted file mode 100644
index 46dae99861c..00000000000
--- a/src/mongo/db/s/coordinate_commit_transaction.idl
+++ /dev/null
@@ -1,39 +0,0 @@
-# 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/>.
-#
-
-global:
- cpp_namespace: "mongo"
-
-imports:
- - "mongo/idl/basic_types.idl"
- - "mongo/s/sharding_types.idl"
-
-structs:
- CommitParticipant:
- description: "Describes a shard participant in a transaction commit"
- fields:
- shardId:
- description: "The id of the shard"
- type: shard_id
-
-commands:
- coordinateCommitTransaction:
- description: "Parser for the 'coordinateCommitTransaction' command."
- strict: false
- namespace: ignored
- fields:
- participants:
- description: "An array of shard participants that must be included in the commit."
- type: array<CommitParticipant>
diff --git a/src/mongo/db/s/coordinate_commit_transaction_command.cpp b/src/mongo/db/s/coordinate_commit_transaction_command.cpp
deleted file mode 100644
index 1e3b23a6cbc..00000000000
--- a/src/mongo/db/s/coordinate_commit_transaction_command.cpp
+++ /dev/null
@@ -1,98 +0,0 @@
-/**
- * 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::kCommand
-
-#include "mongo/platform/basic.h"
-
-#include "mongo/db/commands.h"
-#include "mongo/db/repl/repl_client_info.h"
-#include "mongo/db/s/coordinate_commit_transaction_gen.h"
-#include "mongo/db/transaction_participant.h"
-#include "mongo/util/log.h"
-
-namespace mongo {
-namespace {
-
-class CoordinateCommitTransactionCmd : public TypedCommand<CoordinateCommitTransactionCmd> {
-public:
- using Request = CoordinateCommitTransaction;
- class Invocation final : public InvocationBase {
- public:
- using InvocationBase::InvocationBase;
-
- void typedRun(OperationContext* opCtx) {
- auto txnParticipant = TransactionParticipant::get(opCtx);
- uassert(ErrorCodes::CommandFailed,
- "commitTransaction must be run within a transaction",
- txnParticipant);
-
- // commitTransaction is retryable.
- if (txnParticipant->transactionIsCommitted()) {
- // We set the client last op to the last optime observed by the system to ensure
- // that we wait for the specified write concern on an optime greater than or equal
- // to the commit oplog entry.
- auto& replClient = repl::ReplClientInfo::forClient(opCtx->getClient());
- replClient.setLastOpToSystemLastOpTime(opCtx);
- return;
- }
-
- uassert(ErrorCodes::NoSuchTransaction,
- "Transaction isn't in progress",
- txnParticipant->inMultiDocumentTransaction());
-
- txnParticipant->commitUnpreparedTransaction(opCtx);
- }
-
- private:
- bool supportsWriteConcern() const override {
- return true;
- }
-
- NamespaceString ns() const override {
- return NamespaceString(request().getDbName(), "");
- }
-
- void doCheckAuthorization(OperationContext* opCtx) const override {}
- };
-
- bool adminOnly() const override {
- return true;
- }
-
- std::string help() const override {
- return "Coordinates the commit for a transaction. Only called by mongos.";
- }
-
- AllowedOnSecondary secondaryAllowed(ServiceContext*) const override {
- return AllowedOnSecondary::kNever;
- }
-} coordinateCommitTransactionCmd;
-
-} // namespace
-} // namespace mongo
diff --git a/src/mongo/db/s/txn_two_phase_commit_cmds.cpp b/src/mongo/db/s/txn_two_phase_commit_cmds.cpp
index c7222d73f83..a1c9ed05864 100644
--- a/src/mongo/db/s/txn_two_phase_commit_cmds.cpp
+++ b/src/mongo/db/s/txn_two_phase_commit_cmds.cpp
@@ -31,7 +31,9 @@
#include "mongo/platform/basic.h"
#include "mongo/db/commands.h"
+#include "mongo/db/repl/repl_client_info.h"
#include "mongo/db/s/txn_two_phase_commit_cmds_gen.h"
+#include "mongo/db/transaction_participant.h"
namespace mongo {
namespace {
@@ -106,5 +108,60 @@ public:
}
} voteAbortTransactionCmd;
+class CoordinateCommitTransactionCmd : public TypedCommand<CoordinateCommitTransactionCmd> {
+public:
+ using Request = CoordinateCommitTransaction;
+ class Invocation final : public InvocationBase {
+ public:
+ using InvocationBase::InvocationBase;
+
+ void typedRun(OperationContext* opCtx) {
+ auto txnParticipant = TransactionParticipant::get(opCtx);
+ uassert(ErrorCodes::CommandFailed,
+ "commitTransaction must be run within a transaction",
+ txnParticipant);
+
+ // commitTransaction is retryable.
+ if (txnParticipant->transactionIsCommitted()) {
+ // We set the client last op to the last optime observed by the system to ensure
+ // that we wait for the specified write concern on an optime greater than or equal
+ // to the commit oplog entry.
+ auto& replClient = repl::ReplClientInfo::forClient(opCtx->getClient());
+ replClient.setLastOpToSystemLastOpTime(opCtx);
+ return;
+ }
+
+ uassert(ErrorCodes::NoSuchTransaction,
+ "Transaction isn't in progress",
+ txnParticipant->inMultiDocumentTransaction());
+
+ txnParticipant->commitUnpreparedTransaction(opCtx);
+ }
+
+ private:
+ bool supportsWriteConcern() const override {
+ return true;
+ }
+
+ NamespaceString ns() const override {
+ return NamespaceString(request().getDbName(), "");
+ }
+
+ void doCheckAuthorization(OperationContext* opCtx) const override {}
+ };
+
+ bool adminOnly() const override {
+ return true;
+ }
+
+ std::string help() const override {
+ return "Coordinates the commit for a transaction. Only called by mongos.";
+ }
+
+ AllowedOnSecondary secondaryAllowed(ServiceContext*) const override {
+ return AllowedOnSecondary::kNever;
+ }
+} coordinateCommitTransactionCmd;
+
} // namespace
} // namespace mongo
diff --git a/src/mongo/db/s/txn_two_phase_commit_cmds.idl b/src/mongo/db/s/txn_two_phase_commit_cmds.idl
index 92a2d557546..24c6b8842d1 100644
--- a/src/mongo/db/s/txn_two_phase_commit_cmds.idl
+++ b/src/mongo/db/s/txn_two_phase_commit_cmds.idl
@@ -19,9 +19,17 @@ imports:
- "mongo/idl/basic_types.idl"
- "mongo/s/sharding_types.idl"
+structs:
+ CommitParticipant:
+ description: "Describes a shard participant in a transaction commit"
+ fields:
+ shardId:
+ description: "The id of the shard"
+ type: shard_id
+
commands:
voteCommitTransaction:
- description: "voteCommitTransaction Command"
+ description: "Parser for the 'voteCommitTransaction' command."
namespace: ignored
fields:
shardId:
@@ -33,9 +41,18 @@ commands:
type: timestamp
voteAbortTransaction:
- description: "voteAbortTransaction Command"
+ description: "Parser for the 'voteAbortTransaction' command."
namespace: ignored
fields:
shardId:
description: "The shard name of the sender"
type: shard_id
+
+ coordinateCommitTransaction:
+ description: "Parser for the 'coordinateCommitTransaction' command."
+ strict: false
+ namespace: ignored
+ fields:
+ participants:
+ description: "An array of shard participants that must be included in the commit."
+ type: array<CommitParticipant>