From 72b7023c275ed439af4c5834222c3ed780ee18d2 Mon Sep 17 00:00:00 2001 From: Eric Milkie Date: Wed, 25 Feb 2015 16:25:14 -0500 Subject: SERVER-17330 move handshake cmd to master/slave --- src/mongo/db/client.cpp | 47 +--------------------- src/mongo/db/client.h | 3 +- .../db/commands/write_commands/batch_executor.cpp | 1 - src/mongo/db/dbhelpers.h | 1 + src/mongo/db/repl/master_slave.cpp | 39 +++++++++++++++++- src/mongo/db/repl/scatter_gather_test.cpp | 1 + src/mongo/db/storage/mmap_v1/dur_journal.cpp | 1 + .../db/storage/mmap_v1/dur_journal_writer.cpp | 1 + 8 files changed, 45 insertions(+), 49 deletions(-) (limited to 'src/mongo/db') diff --git a/src/mongo/db/client.cpp b/src/mongo/db/client.cpp index 2290850686f..79ad6edc9e7 100644 --- a/src/mongo/db/client.cpp +++ b/src/mongo/db/client.cpp @@ -32,8 +32,6 @@ to an open socket (or logical connection if pooling on sockets) from a client. */ -#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault - #include "mongo/platform/basic.h" #include "mongo/db/client.h" @@ -57,7 +55,6 @@ #include "mongo/db/instance.h" #include "mongo/db/json.h" #include "mongo/db/lasterror.h" -#include "mongo/db/repl/handshake_args.h" #include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/db/storage_options.h" #include "mongo/s/chunk_version.h" @@ -67,7 +64,6 @@ #include "mongo/util/exit.h" #include "mongo/util/file_allocator.h" #include "mongo/util/mongoutils/str.h" -#include "mongo/util/log.h" namespace mongo { @@ -78,45 +74,6 @@ namespace mongo { namespace { - class HandshakeCmd : public Command { - public: - void help(stringstream& h) const { h << "internal"; } - HandshakeCmd() : Command("handshake") {} - virtual bool isWriteCommandForConfigServer() const { return false; } - virtual bool slaveOk() const { return true; } - virtual bool adminOnly() const { return false; } - virtual void addRequiredPrivileges(const std::string& dbname, - const BSONObj& cmdObj, - std::vector* out) { - ActionSet actions; - actions.addAction(ActionType::internal); - out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); - } - - virtual bool run(OperationContext* txn, - const string& ns, - BSONObj& cmdObj, - int options, - string& errmsg, - BSONObjBuilder& result, - bool fromRepl) { - - repl::HandshakeArgs handshake; - Status status = handshake.initialize(cmdObj); - if (!status.isOK()) { - return appendCommandStatus(result, status); - } - - // TODO(dannenberg) move this into actual processing for both version - txn->getClient()->setRemoteID(handshake.getRid()); - - status = repl::getGlobalReplicationCoordinator()->processHandshake(txn, handshake); - return appendCommandStatus(result, status); - } - - } handshakeCmd; - - /** * Create an appropriate new locker for the storage engine in use. Caller owns the return. */ @@ -581,7 +538,7 @@ namespace { } } } - } + } // namespace #define OPDEBUG_APPEND_NUMBER(x) if( x != -1 ) b.appendNumber( #x , (x) ) #define OPDEBUG_APPEND_BOOL(x) if( x ) b.appendBool( #x , (x) ) @@ -649,4 +606,4 @@ namespace { // This can be called in mongod, which is unfortunate. To fix this, // we can redesign how connection pooling works on mongod for sharded operations. } -} +} // namespace mongo diff --git a/src/mongo/db/client.h b/src/mongo/db/client.h index 55beb82ef4c..da62bca48d1 100644 --- a/src/mongo/db/client.h +++ b/src/mongo/db/client.h @@ -39,6 +39,7 @@ #include #include +#include "mongo/bson/optime.h" #include "mongo/db/catalog/database.h" #include "mongo/db/client_basic.h" #include "mongo/db/concurrency/d_concurrency.h" @@ -46,10 +47,8 @@ #include "mongo/db/namespace_string.h" #include "mongo/db/operation_context.h" #include "mongo/platform/unordered_set.h" -#include "mongo/stdx/functional.h" #include "mongo/util/concurrency/spin_lock.h" #include "mongo/util/concurrency/threadlocal.h" -#include "mongo/util/paths.h" namespace mongo { diff --git a/src/mongo/db/commands/write_commands/batch_executor.cpp b/src/mongo/db/commands/write_commands/batch_executor.cpp index 6ee3a36f63a..a23282cd56a 100644 --- a/src/mongo/db/commands/write_commands/batch_executor.cpp +++ b/src/mongo/db/commands/write_commands/batch_executor.cpp @@ -57,7 +57,6 @@ #include "mongo/db/query/plan_executor.h" #include "mongo/db/query/query_knobs.h" #include "mongo/db/repl/oplog.h" -#include "mongo/db/repl/repl_settings.h" #include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/db/server_parameters.h" #include "mongo/db/stats/counters.h" diff --git a/src/mongo/db/dbhelpers.h b/src/mongo/db/dbhelpers.h index e75a99aa9b6..9901ea470f4 100644 --- a/src/mongo/db/dbhelpers.h +++ b/src/mongo/db/dbhelpers.h @@ -28,6 +28,7 @@ #pragma once +#include #include #include "mongo/db/client.h" diff --git a/src/mongo/db/repl/master_slave.cpp b/src/mongo/db/repl/master_slave.cpp index ae90609016e..c1ef47d9c1c 100644 --- a/src/mongo/db/repl/master_slave.cpp +++ b/src/mongo/db/repl/master_slave.cpp @@ -42,7 +42,6 @@ #include "mongo/db/repl/master_slave.h" -#include #include #include #include @@ -58,6 +57,7 @@ #include "mongo/db/dbhelpers.h" #include "mongo/db/ops/update.h" #include "mongo/db/query/internal_plans.h" +#include "mongo/db/repl/handshake_args.h" #include "mongo/db/repl/oplog.h" #include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/db/repl/sync.h" @@ -349,6 +349,43 @@ namespace repl { replAllDead = 0; } + class HandshakeCmd : public Command { + public: + void help(stringstream& h) const { h << "internal"; } + HandshakeCmd() : Command("handshake") {} + virtual bool isWriteCommandForConfigServer() const { return false; } + virtual bool slaveOk() const { return true; } + virtual bool adminOnly() const { return false; } + virtual void addRequiredPrivileges(const std::string& dbname, + const BSONObj& cmdObj, + std::vector* out) { + ActionSet actions; + actions.addAction(ActionType::internal); + out->push_back(Privilege(ResourcePattern::forClusterResource(), actions)); + } + + virtual bool run(OperationContext* txn, + const string& ns, + BSONObj& cmdObj, + int options, + string& errmsg, + BSONObjBuilder& result, + bool fromRepl) { + + HandshakeArgs handshake; + Status status = handshake.initialize(cmdObj); + if (!status.isOK()) { + return appendCommandStatus(result, status); + } + + txn->getClient()->setRemoteID(handshake.getRid()); + + status = getGlobalReplicationCoordinator()->processHandshake(txn, handshake); + return appendCommandStatus(result, status); + } + + } handshakeCmd; + bool replHandshake(DBClientConnection *conn, const OID& myRID) { string myname = getHostName(); diff --git a/src/mongo/db/repl/scatter_gather_test.cpp b/src/mongo/db/repl/scatter_gather_test.cpp index 270aa53a499..e878ab38f62 100644 --- a/src/mongo/db/repl/scatter_gather_test.cpp +++ b/src/mongo/db/repl/scatter_gather_test.cpp @@ -35,6 +35,7 @@ #include "mongo/db/repl/replication_executor.h" #include "mongo/db/repl/scatter_gather_algorithm.h" #include "mongo/db/repl/scatter_gather_runner.h" +#include "mongo/stdx/functional.h" #include "mongo/unittest/unittest.h" namespace mongo { diff --git a/src/mongo/db/storage/mmap_v1/dur_journal.cpp b/src/mongo/db/storage/mmap_v1/dur_journal.cpp index 24f457eddbc..4dd2a39e39f 100644 --- a/src/mongo/db/storage/mmap_v1/dur_journal.cpp +++ b/src/mongo/db/storage/mmap_v1/dur_journal.cpp @@ -57,6 +57,7 @@ #include "mongo/util/mmap.h" #include "mongo/util/mongoutils/str.h" #include "mongo/util/net/listen.h" // getelapsedtimemillis +#include "mongo/util/paths.h" #include "mongo/util/progress_meter.h" #include "mongo/util/timer.h" diff --git a/src/mongo/db/storage/mmap_v1/dur_journal_writer.cpp b/src/mongo/db/storage/mmap_v1/dur_journal_writer.cpp index 13db027bbe2..56a9d827671 100644 --- a/src/mongo/db/storage/mmap_v1/dur_journal_writer.cpp +++ b/src/mongo/db/storage/mmap_v1/dur_journal_writer.cpp @@ -39,6 +39,7 @@ #include "mongo/db/storage/mmap_v1/dur_journal.h" #include "mongo/db/storage/mmap_v1/dur_recover.h" #include "mongo/db/storage/mmap_v1/dur_stats.h" +#include "mongo/stdx/functional.h" #include "mongo/util/log.h" namespace mongo { -- cgit v1.2.1