diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2015-05-12 16:11:19 -0400 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2015-05-12 17:56:22 -0400 |
commit | e2118354911a6313a9f849e23cf29e40c1a1b236 (patch) | |
tree | 9a3bff1407d7371a322da8cfaf4503cbacea9393 /src | |
parent | 6d7fdcb385e481aea784de2eb515f3d27b46675c (diff) | |
download | mongo-e2118354911a6313a9f849e23cf29e40c1a1b236.tar.gz |
SERVER-17754 Cleanup unused internal client code
This change removes some unused code from the internal C++ client.
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/client/dbclient.cpp | 110 | ||||
-rw-r--r-- | src/mongo/client/dbclientinterface.h | 91 | ||||
-rw-r--r-- | src/mongo/dbtests/commandtests.cpp | 1 | ||||
-rw-r--r-- | src/mongo/shell/bench.cpp | 2 |
4 files changed, 27 insertions, 177 deletions
diff --git a/src/mongo/client/dbclient.cpp b/src/mongo/client/dbclient.cpp index 89d0a814bc5..6bf7283de2b 100644 --- a/src/mongo/client/dbclient.cpp +++ b/src/mongo/client/dbclient.cpp @@ -39,7 +39,6 @@ #include "mongo/client/sasl_client_authenticate.h" #include "mongo/config.h" #include "mongo/db/auth/internal_user_auth.h" -#include "mongo/db/jsobj.h" #include "mongo/db/json.h" #include "mongo/db/namespace_string.h" #include "mongo/rpc/get_status_from_command_result.h" @@ -62,10 +61,29 @@ namespace mongo { using std::stringstream; using std::vector; - AtomicInt64 DBClientBase::ConnectionIdSequence; +namespace { const char* const saslCommandUserSourceFieldName = "userSource"; +#ifdef MONGO_CONFIG_SSL + static SimpleMutex s_mtx("SSLManager"); + static SSLManagerInterface* s_sslMgr(NULL); + + SSLManagerInterface* sslManager() { + SimpleMutex::scoped_lock lk(s_mtx); + if (s_sslMgr) { + return s_sslMgr; + } + + s_sslMgr = getSSLManager(); + return s_sslMgr; + } +#endif + +} // namespace + + AtomicInt64 DBClientBase::ConnectionIdSequence; + const BSONField<BSONObj> Query::ReadPrefField("$readPreference"); const BSONField<string> Query::ReadPrefModeField("mode"); const BSONField<BSONArray> Query::ReadPrefTagsField("tags"); @@ -651,50 +669,6 @@ namespace mongo { return runCommand("admin", b.done(), *info); } - bool DBClientWithCommands::setDbProfilingLevel(const string &dbname, ProfilingLevel level, BSONObj *info ) { - BSONObj o; - if ( info == 0 ) info = &o; - - if ( level ) { - // Create system.profile collection. If it already exists this does nothing. - // TODO: move this into the db instead of here so that all - // drivers don't have to do this. - string ns = dbname + ".system.profile"; - createCollection(ns.c_str(), 1024 * 1024, true, 0, info); - } - - BSONObjBuilder b; - b.append("profile", (int) level); - return runCommand(dbname, b.done(), *info); - } - - BSONObj getprofilingcmdobj = fromjson("{\"profile\":-1}"); - - bool DBClientWithCommands::getDbProfilingLevel(const string &dbname, ProfilingLevel& level, BSONObj *info) { - BSONObj o; - if ( info == 0 ) info = &o; - if ( runCommand(dbname, getprofilingcmdobj, *info) ) { - level = (ProfilingLevel) info->getIntField("was"); - return true; - } - return false; - } - - DBClientWithCommands::MROutput DBClientWithCommands::MRInline (BSON("inline" << 1)); - - BSONObj DBClientWithCommands::mapreduce(const string &ns, const string &jsmapf, const string &jsreducef, BSONObj query, MROutput output) { - BSONObjBuilder b; - b.append("mapreduce", nsGetCollection(ns)); - b.appendCode("map", jsmapf); - b.appendCode("reduce", jsreducef); - if( !query.isEmpty() ) - b.append("query", query); - b.append("out", output.out); - BSONObj info; - runCommand(nsGetDB(ns), b.done(), info); - return info; - } - bool DBClientWithCommands::eval(const string &dbname, const string &jscode, BSONObj& info, BSONElement& retValue, BSONObj *args) { BSONObjBuilder b; b.appendCode("$eval", jscode); @@ -1271,7 +1245,6 @@ namespace mongo { LOG(_logLevel) << "dropIndex failed: " << info << endl; uassert( 10007 , "dropIndex failed" , 0 ); } - resetIndexCache(); } void DBClientWithCommands::dropIndexes( const string& ns ) { @@ -1282,11 +1255,9 @@ namespace mongo { BSON( "deleteIndexes" << nsToCollectionSubstring(ns) << "index" << "*"), info ) ); - resetIndexCache(); } void DBClientWithCommands::reIndex( const string& ns ) { - resetIndexCache(); BSONObj info; uassert(18908, str::stream() << "reIndex failed: " << info, @@ -1318,11 +1289,10 @@ namespace mongo { return ss.str(); } - bool DBClientWithCommands::ensureIndex( const string &ns, + void DBClientWithCommands::ensureIndex( const string &ns, BSONObj keys, bool unique, const string & name, - bool cache, bool background, int version, int ttl ) { @@ -1352,21 +1322,10 @@ namespace mongo { if( background ) toSave.appendBool( "background", true ); - if ( _seenIndexes.count( cacheKey ) ) - return 0; - - if ( cache ) - _seenIndexes.insert( cacheKey ); - if ( ttl > 0 ) toSave.append( "expireAfterSeconds", ttl ); - insert( NamespaceString( ns ).getSystemIndexesCollection() , toSave.obj() ); - return 1; - } - - void DBClientWithCommands::resetIndexCache() { - _seenIndexes.clear(); + insert(NamespaceString(ns).getSystemIndexesCollection(), toSave.obj()); } /* -- DBClientCursor ---------------------------------------------- */ @@ -1515,35 +1474,10 @@ namespace mongo { _failed = true; } -#ifdef MONGO_CONFIG_SSL - static SimpleMutex s_mtx("SSLManager"); - static SSLManagerInterface* s_sslMgr(NULL); - - SSLManagerInterface* DBClientConnection::sslManager() { - SimpleMutex::scoped_lock lk(s_mtx); - if (s_sslMgr) - return s_sslMgr; - s_sslMgr = getSSLManager(); - - return s_sslMgr; - } -#endif - AtomicInt32 DBClientConnection::_numConnections; bool DBClientConnection::_lazyKillCursor = true; - bool serverAlive( const string &uri ) { - DBClientConnection c(false, 20); // potentially the connection to server could fail while we're checking if it's alive - so use timeouts - string err; - if ( !c.connect( HostAndPort(uri), err ) ) - return false; - if ( !c.simpleCommand( "admin", 0, "ping" ) ) - return false; - return true; - } - - /** @return the database name portion of an ns string */ string nsGetDB( const string &ns ) { string::size_type pos = ns.find( "." ); diff --git a/src/mongo/client/dbclientinterface.h b/src/mongo/client/dbclientinterface.h index 330e71058db..0117b2302b0 100644 --- a/src/mongo/client/dbclientinterface.h +++ b/src/mongo/client/dbclientinterface.h @@ -1,9 +1,5 @@ -/** @file dbclientinterface.h - - Core MongoDB C++ driver interfaces are defined here. -*/ - -/* Copyright 2009 10gen Inc. +/** + * 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, @@ -32,18 +28,14 @@ #pragma once -#include <boost/thread/lock_guard.hpp> #include <boost/noncopyable.hpp> #include <boost/scoped_ptr.hpp> #include "mongo/base/string_data.h" #include "mongo/client/connection_string.h" #include "mongo/client/read_preference.h" -#include "mongo/config.h" #include "mongo/db/jsobj.h" -#include "mongo/logger/log_severity.h" #include "mongo/platform/atomic_word.h" -#include "mongo/platform/cstdint.h" #include "mongo/stdx/functional.h" #include "mongo/util/mongoutils/str.h" #include "mongo/util/net/message.h" @@ -421,7 +413,6 @@ namespace mongo { Basically just invocations of connection.$cmd.findOne({...}); */ class DBClientWithCommands : public DBClientInterface { - std::set<std::string> _seenIndexes; public: /** controls how chatty the client is about network errors & such. See log.h */ logger::LogSeverity _logLevel; @@ -599,7 +590,6 @@ namespace mongo { } bool res = runCommand( db.c_str() , BSON( "drop" << coll ) , *info ); - resetIndexCache(); return res; } @@ -631,56 +621,6 @@ namespace mongo { */ bool copyDatabase(const std::string &fromdb, const std::string &todb, const std::string &fromhost = "", BSONObj *info = 0); - /** The Mongo database provides built-in performance profiling capabilities. Uset setDbProfilingLevel() - to enable. Profiling information is then written to the system.profile collection, which one can - then query. - */ - enum ProfilingLevel { - ProfileOff = 0, - ProfileSlow = 1, // log very slow (>100ms) operations - ProfileAll = 2 - - }; - bool setDbProfilingLevel(const std::string &dbname, ProfilingLevel level, BSONObj *info = 0); - bool getDbProfilingLevel(const std::string &dbname, ProfilingLevel& level, BSONObj *info = 0); - - /** This implicitly converts from char*, string, and BSONObj to be an argument to mapreduce - You shouldn't need to explicitly construct this - */ - struct MROutput { - MROutput(const char* collection) : out(BSON("replace" << collection)) {} - MROutput(const std::string& collection) : out(BSON("replace" << collection)) {} - MROutput(const BSONObj& obj) : out(obj) {} - - BSONObj out; - }; - static MROutput MRInline; - - /** Run a map/reduce job on the server. - - See http://dochub.mongodb.org/core/mapreduce - - ns namespace (db+collection name) of input data - jsmapf javascript map function code - jsreducef javascript reduce function code. - query optional query filter for the input - output either a std::string collection name or an object representing output type - if not specified uses inline output type - - returns a result object which contains: - { result : <collection_name>, - numObjects : <number_of_objects_scanned>, - timeMillis : <job_time>, - ok : <1_if_ok>, - [, err : <errmsg_if_error>] - } - - For example one might call: - result.getField("ok").trueValue() - on the result to check if ok. - */ - BSONObj mapreduce(const std::string &ns, const std::string &jsmapf, const std::string &jsreducef, BSONObj query = BSONObj(), MROutput output = MRInline); - /** Run javascript code on the database server. dbname database SavedContext in which the code runs. The javascript variable 'db' will be assigned to this database when the function is invoked. @@ -759,31 +699,21 @@ namespace mongo { bool exists( const std::string& ns ); /** Create an index if it does not already exist. - ensureIndex calls are remembered so it is safe/fast to call this function many - times in your code. @param ns collection to be indexed @param keys the "key pattern" for the index. e.g., { name : 1 } @param unique if true, indicates that key uniqueness should be enforced for this index @param name if not specified, it will be created from the keys automatically (which is recommended) - @param cache if set to false, the index cache for the connection won't remember this call @param background build index in the background (see mongodb docs for details) @param v index version. leave at default value. (unit tests set this parameter.) @param ttl. The value of how many seconds before data should be removed from a collection. - @return whether or not sent message to db. - should be true on first call, false on subsequent unless resetIndexCache was called */ - virtual bool ensureIndex( const std::string &ns, + virtual void ensureIndex( const std::string &ns, BSONObj keys, bool unique = false, const std::string &name = "", - bool cache = true, bool background = false, int v = -1, int ttl = 0 ); - /** - clears the index cache, so the subsequent call to ensureIndex for any index will go to the server - */ - virtual void resetIndexCache(); virtual std::list<BSONObj> getIndexSpecs( const std::string &ns, int options = 0 ); @@ -801,9 +731,7 @@ namespace mongo { /** Erase / drop an entire database */ virtual bool dropDatabase(const std::string &dbname, BSONObj *info = 0) { - bool ret = simpleCommand(dbname, info, "dropDatabase"); - resetIndexCache(); - return ret; + return simpleCommand(dbname, info, "dropDatabase"); } virtual std::string toString() const = 0; @@ -1012,7 +940,6 @@ namespace mongo { virtual void killCursor( long long cursorID ) = 0; virtual bool callRead( Message& toSend , Message& response ) = 0; - // virtual bool callWrite( Message& toSend , Message& response ) = 0; // TODO: add this if needed virtual ConnectionString::ConnectionType type() const = 0; @@ -1026,8 +953,6 @@ namespace mongo { }; // DBClientBase - class DBClientReplicaSet; - class ConnectException : public UserException { public: ConnectException(std::string msg) : UserException(9000,msg) { } @@ -1176,10 +1101,6 @@ namespace mongo { static AtomicInt32 _numConnections; static bool _lazyKillCursor; // lazy means we piggy back kill cursors on next op -#ifdef MONGO_CONFIG_SSL - SSLManagerInterface* sslManager(); -#endif - private: /** @@ -1194,10 +1115,6 @@ namespace mongo { std::string _parentReplSetName; }; - /** pings server to check if it's up - */ - bool serverAlive( const std::string &uri ); - BSONElement getErrField( const BSONObj& result ); bool hasErrField( const BSONObj& result ); diff --git a/src/mongo/dbtests/commandtests.cpp b/src/mongo/dbtests/commandtests.cpp index f6e87de5885..59e02c1b01d 100644 --- a/src/mongo/dbtests/commandtests.cpp +++ b/src/mongo/dbtests/commandtests.cpp @@ -135,7 +135,6 @@ namespace SymbolArgument { log() << result.jsonString(); ASSERT(ok); } - db.resetIndexCache(); } }; diff --git a/src/mongo/shell/bench.cpp b/src/mongo/shell/bench.cpp index 027df17a42b..62ee26be6a9 100644 --- a/src/mongo/shell/bench.cpp +++ b/src/mongo/shell/bench.cpp @@ -647,7 +647,7 @@ namespace mongo { } } else if ( op == "createIndex" ) { - conn->ensureIndex( ns , e["key"].Obj() , false , "" , false ); + conn->ensureIndex(ns, e["key"].Obj(), false, "", false); } else if ( op == "dropIndex" ) { conn->dropIndex( ns , e["key"].Obj() ); |