summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEsha Maharishi <esha.maharishi@mongodb.com>2018-08-09 14:03:25 -0400
committerEsha Maharishi <esha.maharishi@mongodb.com>2018-08-09 16:06:04 -0400
commit7c317b85b1273a8d465479f2205eefedb42154c9 (patch)
treedebee31ab9c1a829b7aed2f364b09bba93c847df
parent25033952fa8cd51f18acada50f1894c232b610ff (diff)
downloadmongo-7c317b85b1273a8d465479f2205eefedb42154c9.tar.gz
SERVER-36561 Move the prepareTransaction command into txn_two_phase_commit_cmds.cpp
-rw-r--r--src/mongo/db/commands/txn_cmds.cpp49
-rw-r--r--src/mongo/db/s/SConscript12
-rw-r--r--src/mongo/db/s/prepare_transaction.idl31
-rw-r--r--src/mongo/db/s/txn_two_phase_commit_cmds.cpp46
-rw-r--r--src/mongo/db/s/txn_two_phase_commit_cmds.idl9
5 files changed, 55 insertions, 92 deletions
diff --git a/src/mongo/db/commands/txn_cmds.cpp b/src/mongo/db/commands/txn_cmds.cpp
index a2cd9ba8d21..50b86c48aa3 100644
--- a/src/mongo/db/commands/txn_cmds.cpp
+++ b/src/mongo/db/commands/txn_cmds.cpp
@@ -33,7 +33,6 @@
#include "mongo/bson/bsonobj.h"
#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/db/commands.h"
-#include "mongo/db/commands/test_commands_enabled.h"
#include "mongo/db/commands/txn_cmds_gen.h"
#include "mongo/db/op_observer.h"
#include "mongo/db/operation_context.h"
@@ -110,54 +109,6 @@ public:
} commitTxn;
-class CmdPrepareTxn : public BasicCommand {
-public:
- CmdPrepareTxn() : BasicCommand("prepareTransaction") {}
-
- AllowedOnSecondary secondaryAllowed(ServiceContext*) const override {
- return AllowedOnSecondary::kNever;
- }
-
- virtual bool adminOnly() const {
- return true;
- }
-
- bool supportsWriteConcern(const BSONObj& cmd) const override {
- return true;
- }
-
- std::string help() const override {
- return "Prepares a transaction. This is only expected to be called by mongos.";
- }
-
- Status checkAuthForOperation(OperationContext* opCtx,
- const std::string& dbname,
- const BSONObj& cmdObj) const override {
- return Status::OK();
- }
-
- bool run(OperationContext* opCtx,
- const std::string& dbname,
- const BSONObj& cmdObj,
- BSONObjBuilder& result) override {
- auto txnParticipant = TransactionParticipant::get(opCtx);
- uassert(ErrorCodes::CommandFailed,
- "prepareTransaction must be run within a transaction",
- txnParticipant);
-
- uassert(ErrorCodes::NoSuchTransaction,
- "Transaction isn't in progress",
- txnParticipant->inMultiDocumentTransaction());
-
- // Add prepareTimestamp to the command response.
- auto timestamp = txnParticipant->prepareTransaction(opCtx);
- result.append("prepareTimestamp", timestamp);
- return true;
- }
-};
-
-MONGO_REGISTER_TEST_COMMAND(CmdPrepareTxn);
-
class CmdAbortTxn : public BasicCommand {
public:
CmdAbortTxn() : BasicCommand("abortTransaction") {}
diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript
index bf7ee5a5022..529511351ee 100644
--- a/src/mongo/db/s/SConscript
+++ b/src/mongo/db/s/SConscript
@@ -136,17 +136,6 @@ env.Library(
)
env.Library(
- target='sharded_transaction_types',
- source=[
- env.Idlc('prepare_transaction.idl')[0],
- ],
- LIBDEPS=[
- '$BUILD_DIR/mongo/base',
- '$BUILD_DIR/mongo/s/common_s',
- ],
-)
-
-env.Library(
target='type_shard_identity',
source=[
env.Idlc('add_shard_cmd.idl')[0],
@@ -321,7 +310,6 @@ env.Library(
'$BUILD_DIR/mongo/s/commands/cluster_commands_helpers',
'$BUILD_DIR/mongo/s/commands/shared_cluster_commands',
'balancer',
- 'sharded_transaction_types',
'sharding_runtime_d',
],
)
diff --git a/src/mongo/db/s/prepare_transaction.idl b/src/mongo/db/s/prepare_transaction.idl
deleted file mode 100644
index 5b1a78030eb..00000000000
--- a/src/mongo/db/s/prepare_transaction.idl
+++ /dev/null
@@ -1,31 +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"
-
-commands:
- prepareTransaction:
- description: "Parser for the 'prepareTransaction' command."
- strict: true
- namespace: ignored
- fields:
- coordinator:
- description: "The coordinator shard for this transaction."
- type: shard_id
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 a1c9ed05864..cd5c0a1c099 100644
--- a/src/mongo/db/s/txn_two_phase_commit_cmds.cpp
+++ b/src/mongo/db/s/txn_two_phase_commit_cmds.cpp
@@ -38,6 +38,52 @@
namespace mongo {
namespace {
+class CmdPrepareTxn : public BasicCommand {
+public:
+ CmdPrepareTxn() : BasicCommand("prepareTransaction") {}
+
+ AllowedOnSecondary secondaryAllowed(ServiceContext*) const override {
+ return AllowedOnSecondary::kNever;
+ }
+
+ virtual bool adminOnly() const {
+ return true;
+ }
+
+ bool supportsWriteConcern(const BSONObj& cmd) const override {
+ return true;
+ }
+
+ std::string help() const override {
+ return "Prepares a transaction. This is only expected to be called by mongos.";
+ }
+
+ Status checkAuthForOperation(OperationContext* opCtx,
+ const std::string& dbname,
+ const BSONObj& cmdObj) const override {
+ return Status::OK();
+ }
+
+ bool run(OperationContext* opCtx,
+ const std::string& dbname,
+ const BSONObj& cmdObj,
+ BSONObjBuilder& result) override {
+ auto txnParticipant = TransactionParticipant::get(opCtx);
+ uassert(ErrorCodes::CommandFailed,
+ "prepareTransaction must be run within a transaction",
+ txnParticipant);
+
+ uassert(ErrorCodes::NoSuchTransaction,
+ "Transaction isn't in progress",
+ txnParticipant->inMultiDocumentTransaction());
+
+ // Add prepareTimestamp to the command response.
+ auto timestamp = txnParticipant->prepareTransaction(opCtx);
+ result.append("prepareTimestamp", timestamp);
+ return true;
+ }
+} prepareTransactionCmd;
+
class VoteCommitTransactionCmd : public TypedCommand<VoteCommitTransactionCmd> {
public:
using Request = VoteCommitTransaction;
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 24c6b8842d1..f3029024c2d 100644
--- a/src/mongo/db/s/txn_two_phase_commit_cmds.idl
+++ b/src/mongo/db/s/txn_two_phase_commit_cmds.idl
@@ -28,6 +28,15 @@ structs:
type: shard_id
commands:
+ prepareTransaction:
+ description: "Parser for the 'prepareTransaction' command."
+ strict: true
+ namespace: ignored
+ fields:
+ coordinator:
+ description: "The coordinator shard for this transaction."
+ type: shard_id
+
voteCommitTransaction:
description: "Parser for the 'voteCommitTransaction' command."
namespace: ignored