summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2015-12-30 18:03:52 -0500
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2016-01-05 09:51:27 -0500
commit3a1c3daecc80ffecba3a1ab9fc49e770ace3ea8f (patch)
treec721ab53313ba02e31bc40c414dfb0460f4394d4
parentb3c4511611635692a46da21b7f9fc0e5131d1ef8 (diff)
downloadmongo-3a1c3daecc80ffecba3a1ab9fc49e770ace3ea8f.tar.gz
SERVER-22055 Remove unused client functionality
-rw-r--r--src/mongo/client/dbclient.cpp40
-rw-r--r--src/mongo/client/dbclient_rs.cpp13
-rw-r--r--src/mongo/client/dbclient_rs.h10
-rw-r--r--src/mongo/client/dbclientinterface.h115
-rw-r--r--src/mongo/client/remote_command_runner_impl.cpp2
-rw-r--r--src/mongo/client/syncclusterconnection.cpp7
-rw-r--r--src/mongo/client/syncclusterconnection.h2
-rw-r--r--src/mongo/db/dbdirectclient.cpp4
-rw-r--r--src/mongo/db/dbdirectclient.h2
-rw-r--r--src/mongo/dbtests/mock/mock_dbclient_connection.cpp9
-rw-r--r--src/mongo/dbtests/mock/mock_dbclient_connection.h7
-rw-r--r--src/mongo/s/commands/commands_public.cpp134
-rw-r--r--src/mongo/s/strategy.cpp50
-rw-r--r--src/mongo/s/strategy.h16
14 files changed, 134 insertions, 277 deletions
diff --git a/src/mongo/client/dbclient.cpp b/src/mongo/client/dbclient.cpp
index 11f650abccb..c682b1684b2 100644
--- a/src/mongo/client/dbclient.cpp
+++ b/src/mongo/client/dbclient.cpp
@@ -1182,21 +1182,17 @@ unsigned long long DBClientConnection::query(stdx::function<void(DBClientCursorB
}
void DBClientBase::insert(const string& ns, BSONObj obj, int flags) {
- Message toSend;
-
BufBuilder b;
int reservedFlags = 0;
if (flags & InsertOption_ContinueOnError)
reservedFlags |= Reserved_InsertOption_ContinueOnError;
- if (flags & WriteOption_FromWriteback)
- reservedFlags |= Reserved_FromWriteback;
-
b.appendNum(reservedFlags);
b.appendStr(ns);
obj.appendSelfToBufBuilder(b);
+ Message toSend;
toSend.setData(dbInsert, b.buf(), b.len());
say(toSend);
@@ -1204,52 +1200,34 @@ void DBClientBase::insert(const string& ns, BSONObj obj, int flags) {
// TODO: Merge with other insert implementation?
void DBClientBase::insert(const string& ns, const vector<BSONObj>& v, int flags) {
- Message toSend;
-
BufBuilder b;
int reservedFlags = 0;
if (flags & InsertOption_ContinueOnError)
reservedFlags |= Reserved_InsertOption_ContinueOnError;
- if (flags & WriteOption_FromWriteback) {
- reservedFlags |= Reserved_FromWriteback;
- flags ^= WriteOption_FromWriteback;
- }
-
b.appendNum(reservedFlags);
b.appendStr(ns);
for (vector<BSONObj>::const_iterator i = v.begin(); i != v.end(); ++i)
i->appendSelfToBufBuilder(b);
+ Message toSend;
toSend.setData(dbInsert, b.buf(), b.len());
say(toSend);
}
-void DBClientBase::remove(const string& ns, Query obj, bool justOne) {
- int flags = 0;
- if (justOne)
- flags |= RemoveOption_JustOne;
- remove(ns, obj, flags);
-}
-
void DBClientBase::remove(const string& ns, Query obj, int flags) {
- Message toSend;
-
BufBuilder b;
- int reservedFlags = 0;
- if (flags & WriteOption_FromWriteback) {
- reservedFlags |= WriteOption_FromWriteback;
- flags ^= WriteOption_FromWriteback;
- }
+ const int reservedFlags = 0;
b.appendNum(reservedFlags);
b.appendStr(ns);
b.appendNum(flags);
obj.obj.appendSelfToBufBuilder(b);
+ Message toSend;
toSend.setData(dbDelete, b.buf(), b.len());
say(toSend);
@@ -1267,13 +1245,8 @@ void DBClientBase::update(const string& ns, Query query, BSONObj obj, bool upser
void DBClientBase::update(const string& ns, Query query, BSONObj obj, int flags) {
BufBuilder b;
- int reservedFlags = 0;
- if (flags & WriteOption_FromWriteback) {
- reservedFlags |= Reserved_FromWriteback;
- flags ^= WriteOption_FromWriteback;
- }
-
- b.appendNum(reservedFlags); // reserved
+ const int reservedFlags = 0;
+ b.appendNum(reservedFlags);
b.appendStr(ns);
b.appendNum(flags);
@@ -1511,7 +1484,6 @@ bool DBClientConnection::call(Message& toSend,
uasserted(10278,
str::stream() << "dbclient error communicating with server: "
<< getServerAddress());
-
return false;
}
} catch (SocketException&) {
diff --git a/src/mongo/client/dbclient_rs.cpp b/src/mongo/client/dbclient_rs.cpp
index 022f13e041f..d392ba214df 100644
--- a/src/mongo/client/dbclient_rs.cpp
+++ b/src/mongo/client/dbclient_rs.cpp
@@ -324,7 +324,7 @@ DBClientConnection* DBClientReplicaSet::checkMaster() {
_master->setRequestMetadataWriter(getRequestMetadataWriter());
_master->setReplyMetadataReader(getReplyMetadataReader());
- _auth(_master.get());
+ _authConnection(_master.get());
return _master.get();
}
@@ -348,7 +348,7 @@ bool DBClientReplicaSet::checkLastHost(const ReadPreferenceSetting* readPref) {
return true;
}
-void DBClientReplicaSet::_auth(DBClientConnection* conn) {
+void DBClientReplicaSet::_authConnection(DBClientConnection* conn) {
for (map<string, BSONObj>::const_iterator i = _auths.begin(); i != _auths.end(); ++i) {
try {
conn->auth(i->second);
@@ -712,7 +712,7 @@ DBClientConnection* DBClientReplicaSet::selectNodeUsingTags(
_lastSlaveOkConn->setReplyMetadataReader(getReplyMetadataReader());
if (_authPooledSecondaryConn) {
- _auth(_lastSlaveOkConn.get());
+ _authConnection(_lastSlaveOkConn.get());
} else {
// Mongos pooled connections are authenticated through
// ShardingConnectionHook::onCreate().
@@ -973,7 +973,7 @@ bool DBClientReplicaSet::call(Message& toSend,
*actualServer = conn->getServerAddress();
}
- return conn->call(toSend, response, assertOk);
+ return conn->call(toSend, response, assertOk, nullptr);
} catch (const DBException& dbExcep) {
LOG(1) << "can't call replica set node " << _lastSlaveOkHost << ": "
<< causedBy(dbExcep) << endl;
@@ -996,7 +996,7 @@ bool DBClientReplicaSet::call(Message& toSend,
if (actualServer)
*actualServer = m->getServerAddress();
- if (!m->call(toSend, response, assertOk))
+ if (!m->call(toSend, response, assertOk, nullptr))
return false;
if (ns) {
@@ -1062,4 +1062,5 @@ void DBClientReplicaSet::resetSlaveOkConn() {
_lastSlaveOkHost = HostAndPort();
}
-}
+
+} // namespace mongo
diff --git a/src/mongo/client/dbclient_rs.h b/src/mongo/client/dbclient_rs.h
index 9b9d3568077..be3eaccf26a 100644
--- a/src/mongo/client/dbclient_rs.h
+++ b/src/mongo/client/dbclient_rs.h
@@ -196,13 +196,7 @@ public:
int getMaxWireVersion() final;
// ---- low level ------
- virtual bool call(Message& toSend,
- Message& response,
- bool assertOk = true,
- std::string* actualServer = 0);
- virtual bool callRead(Message& toSend, Message& response) {
- return checkMaster()->callRead(toSend, response);
- }
+ virtual bool call(Message& toSend, Message& response, bool assertOk, std::string* actualServer);
/**
* Returns whether a query or command can be sent to secondaries based on the query object
@@ -270,7 +264,7 @@ private:
*/
void invalidateLastSlaveOkCache();
- void _auth(DBClientConnection* conn);
+ void _authConnection(DBClientConnection* conn);
/**
* Calls logout on the connection for all known database this DBClientRS instance has
diff --git a/src/mongo/client/dbclientinterface.h b/src/mongo/client/dbclientinterface.h
index 1dc383b1c30..a4e23c3f7e5 100644
--- a/src/mongo/client/dbclientinterface.h
+++ b/src/mongo/client/dbclientinterface.h
@@ -137,14 +137,6 @@ enum InsertOptions {
InsertOption_ContinueOnError = 1 << 0
};
-/**
- * Start from *top* of bits, these are generic write options that apply to all
- */
-enum WriteOptions {
- /** logical writeback option */
- WriteOption_FromWriteback = 1 << 31
-};
-
//
// For legacy reasons, the reserved field pre-namespace of certain types of messages is used
// to store options as opposed to the flags after the namespace. This should be transparent to
@@ -153,7 +145,6 @@ enum WriteOptions {
enum ReservedOptions {
Reserved_InsertOption_ContinueOnError = 1 << 0,
- Reserved_FromWriteback = 1 << 1
};
class DBClientCursor;
@@ -394,37 +385,6 @@ std::string nsGetDB(const std::string& ns);
std::string nsGetCollection(const std::string& ns);
/**
- interface that handles communication with the db
- */
-class DBConnector {
-public:
- virtual ~DBConnector() {}
- /** actualServer is set to the actual server where they call went if there was a choice
- * (SlaveOk) */
- virtual bool call(Message& toSend,
- Message& response,
- bool assertOk = true,
- std::string* actualServer = 0) = 0;
- virtual void say(Message& toSend, bool isRetry = false, std::string* actualServer = 0) = 0;
- /* used by QueryOption_Exhaust. To use that your subclass must implement this. */
- virtual bool recv(Message& m) {
- verify(false);
- return false;
- }
- // In general, for lazy queries, we'll need to say, recv, then checkResponse
- virtual void checkResponse(const char* data,
- int nReturned,
- bool* retry = NULL,
- std::string* targetHost = NULL) {
- if (retry)
- *retry = false;
- if (targetHost)
- *targetHost = "";
- }
- virtual bool lazySupported() const = 0;
-};
-
-/**
The interface that any db connection should implement
*/
class DBClientInterface {
@@ -443,8 +403,6 @@ public:
virtual void insert(const std::string& ns, const std::vector<BSONObj>& v, int flags = 0) = 0;
- virtual void remove(const std::string& ns, Query query, bool justOne = 0) = 0;
-
virtual void remove(const std::string& ns, Query query, int flags) = 0;
virtual void update(const std::string& ns,
@@ -493,7 +451,7 @@ protected:
DB "commands"
Basically just invocations of connection.$cmd.findOne({...});
*/
-class DBClientWithCommands : public DBClientInterface, public DBConnector {
+class DBClientWithCommands : public DBClientInterface {
public:
/** controls how chatty the client is about network errors & such. See log.h */
logger::LogSeverity _logLevel;
@@ -517,6 +475,38 @@ public:
void setClientRPCProtocols(rpc::ProtocolSet clientProtocols);
/**
+ * actualServer is set to the actual server where they call went if there was a choice (for
+ * example SlaveOk).
+ */
+ virtual bool call(Message& toSend,
+ Message& response,
+ bool assertOk = true,
+ std::string* actualServer = nullptr) = 0;
+
+ virtual void say(Message& toSend,
+ bool isRetry = false,
+ std::string* actualServer = nullptr) = 0;
+
+ /* used by QueryOption_Exhaust. To use that your subclass must implement this. */
+ virtual bool recv(Message& m) {
+ verify(false);
+ return false;
+ }
+
+ // In general, for lazy queries, we'll need to say, recv, then checkResponse
+ virtual void checkResponse(const char* data,
+ int nReturned,
+ bool* retry = nullptr,
+ std::string* targetHost = nullptr) {
+ if (retry)
+ *retry = false;
+ if (targetHost)
+ *targetHost = "";
+ }
+
+ virtual bool lazySupported() const = 0;
+
+ /**
* Sets a RequestMetadataWriter on this connection.
*
* TODO: support multiple metadata writers.
@@ -715,14 +705,6 @@ public:
*/
BSONObj getPrevError();
- /** Reset the previous error state for this connection (accessed via getLastError and
- getPrevError). Useful when performing several operations at once and then checking
- for an error after attempting all operations.
- */
- bool resetError() {
- return simpleCommand("admin", 0, "reseterror");
- }
-
/** Delete the specified collection.
* @param info An optional output parameter that receives the result object the database
* returns from the drop command. May be null if the caller doesn't need that info.
@@ -741,13 +723,6 @@ public:
return res;
}
- /** Perform a repair and compaction of the specified database. May take a long time to run.
- * Disk space must be available equal to the size of the database while repairing.
- */
- bool repairDatabase(const std::string& dbname, BSONObj* info = 0) {
- return simpleCommand(dbname, info, "repairDatabase");
- }
-
/** Copy database from one server or name to another server or name.
Generally, you should dropDatabase() first as otherwise the copied information will MERGE
@@ -1050,13 +1025,7 @@ public:
virtual void update(const std::string& ns, Query query, BSONObj obj, int flags);
- /**
- remove matching objects from the database
- @param justOne if this true, then once a single match is found will stop
- */
- virtual void remove(const std::string& ns, Query q, bool justOne = 0);
-
- virtual void remove(const std::string& ns, Query query, int flags);
+ virtual void remove(const std::string& ns, Query query, int flags = 0);
virtual bool isFailed() const = 0;
@@ -1067,8 +1036,6 @@ public:
virtual void killCursor(long long cursorID);
- virtual bool callRead(Message& toSend, Message& response) = 0;
-
virtual ConnectionString::ConnectionType type() const = 0;
virtual double getSoTimeout() const = 0;
@@ -1081,11 +1048,6 @@ public:
}; // DBClientBase
-class ConnectException : public UserException {
-public:
- ConnectException(std::string msg) : UserException(9000, msg) {}
-};
-
/**
A basic connection to the database.
This is the main entry point for talking to a simple Mongo setup
@@ -1237,19 +1199,13 @@ public:
return _serverAddress;
}
- virtual bool callRead(Message& toSend, Message& response) {
- return call(toSend, response);
- }
virtual void say(Message& toSend, bool isRetry = false, std::string* actualServer = 0);
virtual bool recv(Message& m);
virtual void checkResponse(const char* data,
int nReturned,
bool* retry = NULL,
std::string* host = NULL);
- virtual bool call(Message& toSend,
- Message& response,
- bool assertOk = true,
- std::string* actualServer = 0);
+ virtual bool call(Message& toSend, Message& response, bool assertOk, std::string* actualServer);
virtual ConnectionString::ConnectionType type() const {
return ConnectionString::MASTER;
}
@@ -1278,7 +1234,6 @@ protected:
int _minWireVersion{0};
int _maxWireVersion{0};
- friend class SyncClusterConnection;
virtual void _auth(const BSONObj& params);
std::unique_ptr<MessagingPort> _port;
diff --git a/src/mongo/client/remote_command_runner_impl.cpp b/src/mongo/client/remote_command_runner_impl.cpp
index 65865525f38..e856173a314 100644
--- a/src/mongo/client/remote_command_runner_impl.cpp
+++ b/src/mongo/client/remote_command_runner_impl.cpp
@@ -97,7 +97,7 @@ StatusWith<RemoteCommandResponse> runDownconvertedCommand(DBClientConnection* co
Message responseMsg;
try {
- conn->call(requestMsg, responseMsg);
+ conn->call(requestMsg, responseMsg, true, nullptr);
} catch (...) {
return exceptionToStatus();
}
diff --git a/src/mongo/client/syncclusterconnection.cpp b/src/mongo/client/syncclusterconnection.cpp
index d8239ebb38f..52ed06592ec 100644
--- a/src/mongo/client/syncclusterconnection.cpp
+++ b/src/mongo/client/syncclusterconnection.cpp
@@ -220,11 +220,6 @@ void SyncClusterConnection::_connect(const std::string& hostStr) {
_conns.push_back(c);
}
-bool SyncClusterConnection::callRead(Message& toSend, Message& response) {
- // TODO: need to save state of which one to go back to somehow...
- return _conns[0]->callRead(toSend, response);
-}
-
bool SyncClusterConnection::runCommand(const std::string& dbname,
const BSONObj& cmd,
BSONObj& info,
@@ -580,7 +575,7 @@ bool SyncClusterConnection::call(Message& toSend,
for (size_t i = 0; i < _conns.size(); i++) {
try {
- bool ok = _conns[i]->call(toSend, response, assertOk);
+ bool ok = _conns[i]->call(toSend, response, assertOk, nullptr);
if (ok) {
if (actualServer)
*actualServer = _connAddresses[i];
diff --git a/src/mongo/client/syncclusterconnection.h b/src/mongo/client/syncclusterconnection.h
index af5f6f6d8e8..40373d4ae19 100644
--- a/src/mongo/client/syncclusterconnection.h
+++ b/src/mongo/client/syncclusterconnection.h
@@ -148,8 +148,6 @@ public:
int w = 0,
int wtimeout = 0);
- virtual bool callRead(Message& toSend, Message& response);
-
virtual ConnectionString::ConnectionType type() const {
return ConnectionString::SYNC;
}
diff --git a/src/mongo/db/dbdirectclient.cpp b/src/mongo/db/dbdirectclient.cpp
index a36df61ffe5..ed642c3a4b4 100644
--- a/src/mongo/db/dbdirectclient.cpp
+++ b/src/mongo/db/dbdirectclient.cpp
@@ -100,10 +100,6 @@ int DBDirectClient::getMaxWireVersion() {
return WireSpec::instance().maxWireVersionIncoming;
}
-bool DBDirectClient::callRead(Message& toSend, Message& response) {
- return call(toSend, response);
-}
-
ConnectionString::ConnectionType DBDirectClient::type() const {
return ConnectionString::MASTER;
}
diff --git a/src/mongo/db/dbdirectclient.h b/src/mongo/db/dbdirectclient.h
index 50fa46a6f9d..d4d187ff91c 100644
--- a/src/mongo/db/dbdirectclient.h
+++ b/src/mongo/db/dbdirectclient.h
@@ -81,8 +81,6 @@ public:
virtual void say(Message& toSend, bool isRetry = false, std::string* actualServer = 0);
- virtual bool callRead(Message& toSend, Message& response);
-
virtual unsigned long long count(const std::string& ns,
const BSONObj& query = BSONObj(),
int options = 0,
diff --git a/src/mongo/dbtests/mock/mock_dbclient_connection.cpp b/src/mongo/dbtests/mock/mock_dbclient_connection.cpp
index a9af06bd087..5dce3443100 100644
--- a/src/mongo/dbtests/mock/mock_dbclient_connection.cpp
+++ b/src/mongo/dbtests/mock/mock_dbclient_connection.cpp
@@ -169,10 +169,6 @@ void MockDBClientConnection::insert(const string& ns, const vector<BSONObj>& obj
}
}
-void MockDBClientConnection::remove(const string& ns, Query query, bool justOne) {
- remove(ns, query, (justOne ? RemoveOption_JustOne : 0));
-}
-
void MockDBClientConnection::remove(const string& ns, Query query, int flags) {
_remoteServer->remove(ns, query, flags);
}
@@ -181,11 +177,6 @@ void MockDBClientConnection::killCursor(long long cursorID) {
verify(false); // unimplemented
}
-bool MockDBClientConnection::callRead(mongo::Message& toSend, mongo::Message& response) {
- verify(false); // unimplemented
- return false;
-}
-
bool MockDBClientConnection::call(mongo::Message& toSend,
mongo::Message& response,
bool assertOk,
diff --git a/src/mongo/dbtests/mock/mock_dbclient_connection.h b/src/mongo/dbtests/mock/mock_dbclient_connection.h
index 7c05c17e15d..21e2bdc3c83 100644
--- a/src/mongo/dbtests/mock/mock_dbclient_connection.h
+++ b/src/mongo/dbtests/mock/mock_dbclient_connection.h
@@ -88,8 +88,6 @@ public:
virtual void insert(const std::string& ns, const std::vector<BSONObj>& objList, int flags = 0);
- virtual void remove(const std::string& ns, Query query, bool justOne = false);
-
virtual void remove(const std::string& ns, Query query, int flags = 0);
//
@@ -122,11 +120,10 @@ public:
//
void killCursor(long long cursorID);
- bool callRead(mongo::Message& toSend, mongo::Message& response);
bool call(mongo::Message& toSend,
mongo::Message& response,
- bool assertOk = true,
- std::string* actualServer = 0);
+ bool assertOk,
+ std::string* actualServer);
void say(mongo::Message& toSend, bool isRetry = false, std::string* actualServer = 0);
bool lazySupported() const;
diff --git a/src/mongo/s/commands/commands_public.cpp b/src/mongo/s/commands/commands_public.cpp
index c5e7f38b67c..6737fe47674 100644
--- a/src/mongo/s/commands/commands_public.cpp
+++ b/src/mongo/s/commands/commands_public.cpp
@@ -1,32 +1,30 @@
-// s/commands_public.cpp
-
/**
-* Copyright (C) 2008 10gen 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.
-*/
+ * Copyright (C) 2008-2015 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
@@ -65,7 +63,6 @@
namespace mongo {
-using boost::intrusive_ptr;
using std::unique_ptr;
using std::shared_ptr;
using std::list;
@@ -77,9 +74,8 @@ using std::string;
using std::stringstream;
using std::vector;
-namespace dbgrid_pub_cmds {
-
namespace {
+
bool cursorCommandPassthrough(OperationContext* txn,
shared_ptr<DBConfig> conf,
const BSONObj& cmdObj,
@@ -123,7 +119,6 @@ bool cursorCommandPassthrough(OperationContext* txn,
return true;
}
-} // namespace
class PublicGridCommand : public Command {
public:
@@ -215,7 +210,6 @@ public:
}
};
-
class NotAllowedOnShardedCollectionCmd : public PublicGridCommand {
public:
NotAllowedOnShardedCollectionCmd(const char* n) : PublicGridCommand(n) {}
@@ -240,7 +234,7 @@ public:
}
};
-// ----
+// MongoS commands implementation
class DropIndexesCmd : public AllShardsCollectionCommand {
public:
@@ -868,7 +862,6 @@ public:
} convertToCappedCmd;
-
class GroupCmd : public NotAllowedOnShardedCollectionCmd {
public:
GroupCmd() : NotAllowedOnShardedCollectionCmd("group") {}
@@ -894,30 +887,65 @@ public:
ExplainCommon::Verbosity verbosity,
const rpc::ServerSelectionMetadata& serverSelectionMetadata,
BSONObjBuilder* out) const {
- const string fullns = parseNs(dbname, cmdObj);
+ // We will time how long it takes to run the commands on the shards.
+ Timer timer;
- BSONObjBuilder explainCmdBob;
+ BSONObj command;
int options = 0;
- ClusterExplain::wrapAsExplain(
- cmdObj, verbosity, serverSelectionMetadata, &explainCmdBob, &options);
- // We will time how long it takes to run the commands on the shards.
- Timer timer;
+ {
+ BSONObjBuilder explainCmdBob;
+ ClusterExplain::wrapAsExplain(
+ cmdObj, verbosity, serverSelectionMetadata, &explainCmdBob, &options);
+ command = explainCmdBob.obj();
+ }
- Strategy::CommandResult singleResult;
- Status commandStat = Strategy::commandOpUnsharded(
- txn, dbname, explainCmdBob.obj(), options, fullns, &singleResult);
- if (!commandStat.isOK()) {
- return commandStat;
+ const NamespaceString nss(parseNs(dbname, cmdObj));
+
+ // Note that this implementation will not handle targeting retries and fails when the
+ // sharding metadata is too stale
+ auto status = grid.catalogCache()->getDatabase(txn, nss.db().toString());
+ if (!status.isOK()) {
+ return Status(status.getStatus().code(),
+ stream() << "Passthrough command failed: " << command.toString()
+ << " on ns " << nss.ns() << ". Caused by "
+ << causedBy(status.getStatus()));
}
- long long millisElapsed = timer.millis();
+ shared_ptr<DBConfig> conf = status.getValue();
+ if (conf->isSharded(nss.ns())) {
+ return Status(ErrorCodes::IllegalOperation,
+ stream() << "Passthrough command failed: " << command.toString()
+ << " on ns " << nss.ns()
+ << ". Cannot run on sharded namespace.");
+ }
- vector<Strategy::CommandResult> shardResults;
- shardResults.push_back(singleResult);
+ const auto primaryShard = grid.shardRegistry()->getShard(txn, conf->getPrimaryId());
+
+ BSONObj shardResult;
+ try {
+ ShardConnection conn(primaryShard->getConnString(), "");
+
+ // TODO: this can throw a stale config when mongos is not up-to-date -- fix.
+ if (!conn->runCommand(nss.db().toString(), command, shardResult, options)) {
+ conn.done();
+ return Status(ErrorCodes::OperationFailed,
+ stream() << "Passthrough command failed: " << command << " on ns "
+ << nss.ns() << "; result: " << shardResult);
+ }
+ conn.done();
+ } catch (const DBException& ex) {
+ return ex.toStatus();
+ }
+
+ // Fill out the command result.
+ Strategy::CommandResult cmdResult;
+ cmdResult.shardTargetId = conf->getPrimaryId();
+ cmdResult.result = shardResult;
+ cmdResult.target = primaryShard->getConnString();
return ClusterExplain::buildExplainResult(
- txn, shardResults, ClusterExplain::kSingleShard, millisElapsed, out);
+ txn, {cmdResult}, ClusterExplain::kSingleShard, timer.millis(), out);
}
} groupCmd;
@@ -1360,7 +1388,6 @@ public:
}
} applyOpsCmd;
-
class CompactCmd : public PublicGridCommand {
public:
CompactCmd() : PublicGridCommand("compact") {}
@@ -1507,7 +1534,6 @@ public:
return Status::OK();
}
-
virtual bool run(OperationContext* txn,
const string& dbname,
BSONObj& cmdObj,
@@ -1517,8 +1543,8 @@ public:
result << "options" << QueryOption_AllSupportedForSharding;
return true;
}
-} availableQueryOptionsCmd;
-} // namespace pub_grid_cmds
+} availableQueryOptionsCmd;
+} // namespace
} // namespace mongo
diff --git a/src/mongo/s/strategy.cpp b/src/mongo/s/strategy.cpp
index 3cd57de4fa2..84fb002839c 100644
--- a/src/mongo/s/strategy.cpp
+++ b/src/mongo/s/strategy.cpp
@@ -336,56 +336,6 @@ void Strategy::commandOp(OperationContext* txn,
}
}
-Status Strategy::commandOpUnsharded(OperationContext* txn,
- const std::string& db,
- const BSONObj& command,
- int options,
- const std::string& versionedNS,
- CommandResult* cmdResult) {
- // Note that this implementation will not handle targeting retries and fails when the
- // sharding metadata is too stale
- auto status = grid.catalogCache()->getDatabase(txn, db);
- if (!status.isOK()) {
- mongoutils::str::stream ss;
- ss << "Passthrough command failed: " << command.toString() << " on ns " << versionedNS
- << ". Caused by " << causedBy(status.getStatus());
- return Status(ErrorCodes::IllegalOperation, ss);
- }
-
- shared_ptr<DBConfig> conf = status.getValue();
- if (conf->isSharded(versionedNS)) {
- mongoutils::str::stream ss;
- ss << "Passthrough command failed: " << command.toString() << " on ns " << versionedNS
- << ". Cannot run on sharded namespace.";
- return Status(ErrorCodes::IllegalOperation, ss);
- }
-
- const auto primaryShard = grid.shardRegistry()->getShard(txn, conf->getPrimaryId());
-
- BSONObj shardResult;
- try {
- ShardConnection conn(primaryShard->getConnString(), "");
-
- // TODO: this can throw a stale config when mongos is not up-to-date -- fix.
- if (!conn->runCommand(db, command, shardResult, options)) {
- conn.done();
- return Status(ErrorCodes::OperationFailed,
- str::stream() << "Passthrough command failed: " << command << " on ns "
- << versionedNS << "; result: " << shardResult);
- }
- conn.done();
- } catch (const DBException& ex) {
- return ex.toStatus();
- }
-
- // Fill out the command result.
- cmdResult->shardTargetId = conf->getPrimaryId();
- cmdResult->result = shardResult;
- cmdResult->target = primaryShard->getConnString();
-
- return Status::OK();
-}
-
void Strategy::getMore(OperationContext* txn, Request& request) {
const char* ns = request.getns();
const int ntoreturn = request.d().pullInt();
diff --git a/src/mongo/s/strategy.h b/src/mongo/s/strategy.h
index 49206ff6d27..961387c8db4 100644
--- a/src/mongo/s/strategy.h
+++ b/src/mongo/s/strategy.h
@@ -96,22 +96,6 @@ public:
std::vector<CommandResult>* results);
/**
- * Some commands can only be run in a sharded configuration against a namespace that has
- * not been sharded. Use this method to execute such commands.
- *
- * Does *not* retry or retarget if the metadata is stale.
- *
- * On success, fills in 'shardResult' with output from the namespace's primary shard. This
- * output may itself indicate an error status on the shard.
- */
- static Status commandOpUnsharded(OperationContext* txn,
- const std::string& db,
- const BSONObj& command,
- int options,
- const std::string& versionedNS,
- CommandResult* shardResult);
-
- /**
* Executes a command represented in the Request on the sharded cluster.
*
* DEPRECATED: should not be used by new code.