From 0c09bf00d7fdadc80215f7cd4829271c2e6a0dc8 Mon Sep 17 00:00:00 2001 From: Ben Caimano Date: Tue, 20 Oct 2020 22:12:53 +0000 Subject: SERVER-50508 Rename ConnectionType::MASTER to ConnectionType::kStandalone --- src/mongo/client/connection_string.cpp | 86 ++++++++++++---------- src/mongo/client/connection_string.h | 57 ++++++++++---- src/mongo/client/connection_string_connect.cpp | 12 +-- src/mongo/client/connection_string_test.cpp | 2 +- src/mongo/client/connpool.cpp | 4 +- src/mongo/client/dbclient_connection.h | 2 +- src/mongo/client/dbclient_cursor.cpp | 2 +- src/mongo/client/dbclient_rs.h | 2 +- src/mongo/client/mongo_uri.cpp | 13 ++-- src/mongo/client/mongo_uri.h | 12 ++- src/mongo/client/mongo_uri_test.cpp | 66 ++++++++--------- .../remote_command_targeter_factory_impl.cpp | 10 +-- .../client/remote_command_targeter_factory_impl.h | 6 +- src/mongo/client/replica_set_monitor_manager.cpp | 2 +- src/mongo/db/dbdirectclient.cpp | 2 +- .../sharding_catalog_manager_add_shard_test.cpp | 4 +- .../sharding_catalog_manager_shard_operations.cpp | 11 +-- src/mongo/db/s/sharding_initialization_mongod.cpp | 14 ++-- .../db/s/sharding_initialization_mongod_test.cpp | 24 +++--- .../s/sharding_initialization_op_observer_test.cpp | 6 +- src/mongo/db/s/sharding_mongod_test_fixture.cpp | 13 ++-- src/mongo/db/s/type_shard_identity.cpp | 4 +- src/mongo/dbtests/clienttests.cpp | 4 +- src/mongo/dbtests/mock/mock_conn_registry.cpp | 2 +- .../dbtests/mock/mock_dbclient_connection.cpp | 2 +- src/mongo/dbtests/mock/mock_remote_db_server.cpp | 2 +- src/mongo/rpc/op_msg_integration_test.cpp | 2 +- src/mongo/s/client/shard_registry.cpp | 10 +-- src/mongo/s/client/sharding_connection_hook.cpp | 4 +- src/mongo/s/mongos_main.cpp | 6 +- src/mongo/s/mongos_options.cpp | 3 +- src/mongo/s/query/cluster_find.cpp | 2 +- .../s/request_types/add_shard_request_type.cpp | 4 +- src/mongo/s/sharding_router_test_fixture.cpp | 4 +- src/mongo/scripting/mozjs/mongo.cpp | 2 +- 35 files changed, 223 insertions(+), 178 deletions(-) (limited to 'src') diff --git a/src/mongo/client/connection_string.cpp b/src/mongo/client/connection_string.cpp index f3dd2fd192c..df126ba4a22 100644 --- a/src/mongo/client/connection_string.cpp +++ b/src/mongo/client/connection_string.cpp @@ -38,30 +38,32 @@ namespace mongo { -ConnectionString::ConnectionString(const HostAndPort& server) : _type(MASTER) { +ConnectionString::ConnectionString(const HostAndPort& server) : _type(ConnectionType::kStandalone) { _servers.push_back(server); _finishInit(); } -ConnectionString::ConnectionString(StringData setName, std::vector servers) - : _type(SET), _servers(std::move(servers)), _setName(setName.toString()) { +ConnectionString::ConnectionString(StringData replicaSetName, std::vector servers) + : _type(ConnectionType::kReplicaSet), + _servers(std::move(servers)), + _replicaSetName(replicaSetName.toString()) { _finishInit(); } // TODO: unify c-tors ConnectionString::ConnectionString(ConnectionType type, const std::string& s, - const std::string& setName) { + const std::string& replicaSetName) { _type = type; - _setName = setName; + _replicaSetName = replicaSetName; _fillServers(s); _finishInit(); } ConnectionString::ConnectionString(ConnectionType type, std::vector servers, - const std::string& setName) - : _type(type), _servers(std::move(servers)), _setName(setName) { + const std::string& replicaSetName) + : _type(type), _servers(std::move(servers)), _replicaSetName(replicaSetName) { _finishInit(); } @@ -72,16 +74,20 @@ ConnectionString::ConnectionString(const std::string& s, ConnectionType connType } ConnectionString::ConnectionString(ConnectionType connType) : _type(connType), _string("") { - invariant(_type == LOCAL); + invariant(_type == ConnectionType::kLocal); } -ConnectionString ConnectionString::forReplicaSet(StringData setName, +ConnectionString ConnectionString::forReplicaSet(StringData replicaSetName, std::vector servers) { - return ConnectionString(setName, std::move(servers)); + return ConnectionString(replicaSetName, std::move(servers)); +} + +ConnectionString ConnectionString::forStandalones(std::vector servers) { + return ConnectionString(ConnectionType::kStandalone, std::move(servers), ""); } ConnectionString ConnectionString::forLocal() { - return ConnectionString(LOCAL); + return ConnectionString(ConnectionType::kLocal); } // TODO: rewrite parsing make it more reliable @@ -93,15 +99,15 @@ void ConnectionString::_fillServers(std::string s) { // if (s.find('$') == 0) { - _type = CUSTOM; + _type = ConnectionType::kCustom; } std::string::size_type idx = s.find('/'); if (idx != std::string::npos) { - _setName = s.substr(0, idx); + _replicaSetName = s.substr(0, idx); s = s.substr(idx + 1); - if (_type != CUSTOM) - _type = SET; + if (_type != ConnectionType::kCustom) + _type = ConnectionType::kReplicaSet; } while ((idx = s.find(',')) != std::string::npos) { @@ -111,22 +117,22 @@ void ConnectionString::_fillServers(std::string s) { _servers.push_back(HostAndPort(s)); - if (_servers.size() == 1 && _type == INVALID) { - _type = MASTER; + if (_servers.size() == 1 && _type == ConnectionType::kInvalid) { + _type = ConnectionType::kStandalone; } } void ConnectionString::_finishInit() { switch (_type) { - case MASTER: + case ConnectionType::kStandalone: uassert(ErrorCodes::FailedToParse, - "Cannot specify a replica set name for a ConnectionString of type MASTER", - _setName.empty()); + "Cannot specify a replica set name for a standalone ConnectionString", + _replicaSetName.empty()); break; - case SET: + case ConnectionType::kReplicaSet: uassert(ErrorCodes::FailedToParse, "Must specify set name for replica set ConnectionStrings", - !_setName.empty()); + !_replicaSetName.empty()); uassert(ErrorCodes::FailedToParse, "Replica set ConnectionStrings must have at least one server specified", _servers.size() >= 1); @@ -139,16 +145,16 @@ void ConnectionString::_finishInit() { // Needed here as well b/c the parsing logic isn't used in all constructors // TODO: Refactor so that the parsing logic *is* used in all constructors - if (_type == MASTER && _servers.size() > 0) { + if (_type == ConnectionType::kStandalone && _servers.size() > 0) { if (_servers[0].host().find('$') == 0) { - _type = CUSTOM; + _type = ConnectionType::kCustom; } } std::stringstream ss; - if (_type == SET) { - ss << _setName << "/"; + if (_type == ConnectionType::kReplicaSet) { + ss << _replicaSetName << "/"; } for (unsigned i = 0; i < _servers.size(); i++) { @@ -177,15 +183,15 @@ bool ConnectionString::operator==(const ConnectionString& other) const { } switch (_type) { - case INVALID: + case ConnectionType::kInvalid: return true; - case MASTER: + case ConnectionType::kStandalone: return _servers[0] == other._servers[0]; - case SET: - return _setName == other._setName && _servers == other._servers; - case CUSTOM: + case ConnectionType::kReplicaSet: + return _replicaSetName == other._replicaSetName && _servers == other._servers; + case ConnectionType::kCustom: return _string == other._string; - case LOCAL: + case ConnectionType::kLocal: return true; } @@ -201,7 +207,7 @@ StatusWith ConnectionString::parse(const std::string& url) { // Replica set if (i != std::string::npos && i != 0) { - return ConnectionString(SET, url.substr(i + 1), url.substr(0, i)); + return ConnectionString(ConnectionType::kReplicaSet, url.substr(i + 1), url.substr(0, i)); } const int numCommas = str::count(url, ','); @@ -233,15 +239,15 @@ ConnectionString ConnectionString::deserialize(StringData url) { std::string ConnectionString::typeToString(ConnectionType type) { switch (type) { - case INVALID: + case ConnectionType::kInvalid: return "invalid"; - case MASTER: - return "master"; - case SET: - return "set"; - case CUSTOM: + case ConnectionType::kStandalone: + return "standalone"; + case ConnectionType::kReplicaSet: + return "replicaSet"; + case ConnectionType::kCustom: return "custom"; - case LOCAL: + case ConnectionType::kLocal: return "local"; } diff --git a/src/mongo/client/connection_string.h b/src/mongo/client/connection_string.h index 98b66bef986..77f5f73a277 100644 --- a/src/mongo/client/connection_string.h +++ b/src/mongo/client/connection_string.h @@ -52,7 +52,7 @@ class MongoURI; * samples: * server * server:port - * foo/server:port,server:port SET + * foo/server:port,server:port kReplicaSet * * Typical use: * @@ -62,14 +62,20 @@ class MongoURI; */ class ConnectionString { public: - enum ConnectionType { INVALID, MASTER, SET, CUSTOM, LOCAL }; + enum class ConnectionType { kInvalid = 0, kStandalone, kReplicaSet, kCustom, kLocal }; ConnectionString() = default; /** * Constructs a connection string representing a replica set. */ - static ConnectionString forReplicaSet(StringData setName, std::vector servers); + static ConnectionString forReplicaSet(StringData replicaSetName, + std::vector servers); + + /** + * Constructs a connection string representing a list of standalone servers. + */ + static ConnectionString forStandalones(std::vector servers); /** * Constructs a local connection string. @@ -77,34 +83,42 @@ public: static ConnectionString forLocal(); /** - * Creates a MASTER connection string with the specified server. + * Creates a standalone connection string with the specified server. */ explicit ConnectionString(const HostAndPort& server); /** - * Creates a connection string from an unparsed list of servers, type, and setName. + * Creates a connection string from an unparsed list of servers, type, and replicaSetName. */ - ConnectionString(ConnectionType type, const std::string& s, const std::string& setName); + ConnectionString(ConnectionType type, const std::string& s, const std::string& replicaSetName); /** - * Creates a connection string from a pre-parsed list of servers, type, and setName. + * Creates a connection string from a pre-parsed list of servers, type, and replicaSetName. */ ConnectionString(ConnectionType type, std::vector servers, - const std::string& setName); + const std::string& replicaSetName); ConnectionString(const std::string& s, ConnectionType connType); bool isValid() const { - return _type != INVALID; + return _type != ConnectionType::kInvalid; + } + + explicit operator bool() const { + return isValid(); } const std::string& toString() const { return _string; } + const std::string& getReplicaSetName() const { + return _replicaSetName; + } + const std::string& getSetName() const { - return _setName; + return getReplicaSetName(); } const std::vector& getServers() const { @@ -187,22 +201,25 @@ public: private: /** - * Creates a SET connection string with the specified set name and servers. + * Creates a replica set connection string with the specified name and servers. */ - ConnectionString(StringData setName, std::vector servers); + ConnectionString(StringData replicaSetName, std::vector servers); /** - * Creates a connection string with the specified type. Used for creating LOCAL strings. + * Creates a connection string with the specified type. + * + * This ctor is mostly used to create ConnectionStrings to the current node with + * ConnectionType::kLocal. */ explicit ConnectionString(ConnectionType connType); void _fillServers(std::string s); void _finishInit(); - ConnectionType _type{INVALID}; + ConnectionType _type{ConnectionType::kInvalid}; std::vector _servers; std::string _string; - std::string _setName; + std::string _replicaSetName; static Mutex _connectHookMutex; static ConnectionHook* _connectHook; @@ -218,4 +235,14 @@ inline StringBuilder& operator<<(StringBuilder& sb, const ConnectionString& cs) return sb; } +inline std::ostream& operator<<(std::ostream& ss, const ConnectionString::ConnectionType& ct) { + ss << ConnectionString::typeToString(ct); + return ss; +} + +inline StringBuilder& operator<<(StringBuilder& sb, const ConnectionString::ConnectionType& ct) { + sb << ConnectionString::typeToString(ct); + return sb; +} + } // namespace mongo diff --git a/src/mongo/client/connection_string_connect.cpp b/src/mongo/client/connection_string_connect.cpp index 735fc47d2af..ae4bf55d6fd 100644 --- a/src/mongo/client/connection_string_connect.cpp +++ b/src/mongo/client/connection_string_connect.cpp @@ -58,7 +58,7 @@ std::unique_ptr ConnectionString::connect( } switch (_type) { - case MASTER: { + case ConnectionType::kStandalone: { for (const auto& server : _servers) { auto c = std::make_unique( true, 0, newURI, DBClientConnection::HandshakeValidationHook(), apiParameters); @@ -78,8 +78,8 @@ std::unique_ptr ConnectionString::connect( return nullptr; } - case SET: { - auto set = std::make_unique(_setName, + case ConnectionType::kReplicaSet: { + auto set = std::make_unique(_replicaSetName, _servers, applicationName, socketTimeout, @@ -93,7 +93,7 @@ std::unique_ptr ConnectionString::connect( return std::move(set); } - case CUSTOM: { + case ConnectionType::kCustom: { // Lock in case other things are modifying this at the same time stdx::lock_guard lk(_connectHookMutex); @@ -118,8 +118,8 @@ std::unique_ptr ConnectionString::connect( return replacementConn; } - case LOCAL: - case INVALID: + case ConnectionType::kLocal: + case ConnectionType::kInvalid: MONGO_UNREACHABLE; } diff --git a/src/mongo/client/connection_string_test.cpp b/src/mongo/client/connection_string_test.cpp index fe09c3912de..355a62c0910 100644 --- a/src/mongo/client/connection_string_test.cpp +++ b/src/mongo/client/connection_string_test.cpp @@ -38,7 +38,7 @@ namespace { using unittest::assertGet; -TEST(ConnectionString, EqualityOperatorMaster) { +TEST(ConnectionString, EqualityOperatorStandalone) { const auto cs = assertGet(ConnectionString::parse("TestHostA:12345")); ASSERT(cs == assertGet(ConnectionString::parse("TestHostA:12345"))); ASSERT_FALSE(cs != assertGet(ConnectionString::parse("TestHostA:12345"))); diff --git a/src/mongo/client/connpool.cpp b/src/mongo/client/connpool.cpp index 6adf8c75645..f742a8dcef8 100644 --- a/src/mongo/client/connpool.cpp +++ b/src/mongo/client/connpool.cpp @@ -80,7 +80,7 @@ using std::vector; PoolForHost::PoolForHost() : _created(0), _minValidCreationTimeMicroSec(0), - _type(ConnectionString::INVALID), + _type(ConnectionString::ConnectionType::kInvalid), _maxPoolSize(kPoolSizeUnlimited), _maxInUse(kDefaultMaxInUse), _checkedOut(0), @@ -701,7 +701,7 @@ void ScopedDbConnection::_setSocketTimeout() { if (!_conn) return; - if (_conn->type() == ConnectionString::MASTER) + if (_conn->type() == ConnectionString::ConnectionType::kStandalone) static_cast(_conn)->setSoTimeout(_socketTimeoutSecs); } diff --git a/src/mongo/client/dbclient_connection.h b/src/mongo/client/dbclient_connection.h index cff4082d09e..3d80c9c371b 100644 --- a/src/mongo/client/dbclient_connection.h +++ b/src/mongo/client/dbclient_connection.h @@ -244,7 +244,7 @@ public: bool assertOk, std::string* actualServer) override; ConnectionString::ConnectionType type() const override { - return ConnectionString::MASTER; + return ConnectionString::ConnectionType::kStandalone; } void setSoTimeout(double timeout); double getSoTimeout() const override { diff --git a/src/mongo/client/dbclient_cursor.cpp b/src/mongo/client/dbclient_cursor.cpp index 34fa4f0f272..8031febcffa 100644 --- a/src/mongo/client/dbclient_cursor.cpp +++ b/src/mongo/client/dbclient_cursor.cpp @@ -503,7 +503,7 @@ void DBClientCursor::attach(AScopedConnection* conn) { verify(conn); verify(conn->get()); - if (conn->get()->type() == ConnectionString::SET) { + if (conn->get()->type() == ConnectionString::ConnectionType::kReplicaSet) { if (_lazyHost.size() > 0) _scopedHost = _lazyHost; else if (_client) diff --git a/src/mongo/client/dbclient_rs.h b/src/mongo/client/dbclient_rs.h index 64a9ddffb03..733eddb0dc3 100644 --- a/src/mongo/client/dbclient_rs.h +++ b/src/mongo/client/dbclient_rs.h @@ -203,7 +203,7 @@ public: std::string getServerAddress() const override; ConnectionString::ConnectionType type() const override { - return ConnectionString::SET; + return ConnectionString::ConnectionType::kReplicaSet; } bool lazySupported() const override { return true; diff --git a/src/mongo/client/mongo_uri.cpp b/src/mongo/client/mongo_uri.cpp index 08454c6b3f7..e2b0af43b7c 100644 --- a/src/mongo/client/mongo_uri.cpp +++ b/src/mongo/client/mongo_uri.cpp @@ -456,12 +456,12 @@ MongoURI MongoURI::parseImpl(StringData url) { auto options = addTXTOptions(parseOptions(connectionOptions, url), canonicalHost, url, isSeedlist); - // If a replica set option was specified, store it in the 'setName' field. + // If a replica set option was specified, store it in the 'replicaSetName' field. auto optIter = options.find("replicaSet"); - std::string setName; + std::string replicaSetName; if (optIter != end(options)) { - setName = optIter->second; - invariant(!setName.empty()); + replicaSetName = optIter->second; + invariant(!replicaSetName.empty()); } // If an appName option was specified, validate that is 128 bytes or less. @@ -500,8 +500,9 @@ MongoURI MongoURI::parseImpl(StringData url) { } } - ConnectionString cs( - setName.empty() ? ConnectionString::MASTER : ConnectionString::SET, servers, setName); + auto cs = replicaSetName.empty() + ? ConnectionString::forStandalones(std::move(servers)) + : ConnectionString::forReplicaSet(replicaSetName, std::move(servers)); return MongoURI(std::move(cs), username, password, diff --git a/src/mongo/client/mongo_uri.h b/src/mongo/client/mongo_uri.h index 26546ed7af5..4a7ca89126a 100644 --- a/src/mongo/client/mongo_uri.h +++ b/src/mongo/client/mongo_uri.h @@ -208,6 +208,10 @@ public: return _connectString.isValid(); } + explicit operator bool() const { + return isValid(); + } + const ConnectionString& connectionString() const { return _connectString; } @@ -216,10 +220,14 @@ public: return _connectString.toString(); } - const std::string& getSetName() const { + const std::string& getReplicaSetName() const { return _connectString.getSetName(); } + const std::string& getSetName() const { + return getReplicaSetName(); + } + const std::vector& getServers() const { return _connectString.getServers(); } @@ -240,7 +248,7 @@ public: // If you are trying to clone a URI (including its options/auth information) for a single // server (say a member of a replica-set), you can pass in its HostAndPort information to - // get a new URI with the same info, except type() will be MASTER and getServers() will + // get a new URI with the same info, except type() will be kStandalone and getServers() will // be the single host you pass in. MongoURI cloneURIForServer(HostAndPort hostAndPort, StringData applicationName) const { auto out = *this; diff --git a/src/mongo/client/mongo_uri_test.cpp b/src/mongo/client/mongo_uri_test.cpp index b7f1df41482..f8c3027fb20 100644 --- a/src/mongo/client/mongo_uri_test.cpp +++ b/src/mongo/client/mongo_uri_test.cpp @@ -105,8 +105,8 @@ void compareOptions(size_t lineNumber, << " data on line: " << lineNumber << uri; } -const ConnectionString::ConnectionType kMaster = ConnectionString::MASTER; -const ConnectionString::ConnectionType kSet = ConnectionString::SET; +const ConnectionString::ConnectionType kMaster = ConnectionString::ConnectionType::kStandalone; +const ConnectionString::ConnectionType kReplicaSet = ConnectionString::ConnectionType::kReplicaSet; const URITestCase validCases[] = { @@ -155,7 +155,7 @@ const URITestCase validCases[] = { {"mongodb://user:pwd@127.0.0.1,127.0.0.2/dbname?a=b&replicaSet=replName", "user", "pwd", - kSet, + kReplicaSet, "replName", 2, {{"a", "b"}, {"replicaSet", "replName"}}, @@ -166,7 +166,7 @@ const URITestCase validCases[] = { "dbname?a=b&replicaSet=replName", "needs encoding%#!<>", "pwd", - kSet, + kReplicaSet, "replName", 2, {{"a", "b"}, {"replicaSet", "replName"}}, @@ -177,7 +177,7 @@ const URITestCase validCases[] = { "db@name?a=b&replicaSet=replName", "needs encoding%#!<>", "pwd", - kSet, + kReplicaSet, "replName", 2, {{"a", "b"}, {"replicaSet", "replName"}}, @@ -188,7 +188,7 @@ const URITestCase validCases[] = { "dbname?a=b&replicaSet=replName", "user", "needs encoding%#!<>", - kSet, + kReplicaSet, "replName", 2, {{"a", "b"}, {"replicaSet", "replName"}}, @@ -198,7 +198,7 @@ const URITestCase validCases[] = { {"mongodb://user:pwd@127.0.0.1,127.0.0.2/dbname?a=b&replicaSet=needs%20encoding%25%23!%3C%3E", "user", "pwd", - kSet, + kReplicaSet, "needs encoding%#!<>", 2, {{"a", "b"}, {"replicaSet", "needs encoding%#!<>"}}, @@ -208,7 +208,7 @@ const URITestCase validCases[] = { {"mongodb://user:pwd@127.0.0.1,127.0.0.2/needsencoding%40hello?a=b&replicaSet=replName", "user", "pwd", - kSet, + kReplicaSet, "replName", 2, {{"a", "b"}, {"replicaSet", "replName"}}, @@ -218,7 +218,7 @@ const URITestCase validCases[] = { {"mongodb://user:pwd@127.0.0.1,127.0.0.2/?replicaSet=replName", "user", "pwd", - kSet, + kReplicaSet, "replName", 2, {{"replicaSet", "replName"}}, @@ -228,7 +228,7 @@ const URITestCase validCases[] = { {"mongodb://user@127.0.0.1,127.0.0.2/?replicaSet=replName", "user", "", - kSet, + kReplicaSet, "replName", 2, {{"replicaSet", "replName"}}, @@ -238,7 +238,7 @@ const URITestCase validCases[] = { {"mongodb://user@127.0.0.1,127.0.0.2/?replicaset=replName", "user", "", - kSet, + kReplicaSet, "replName", 2, {{"replicaSet", "replName"}}, @@ -248,7 +248,7 @@ const URITestCase validCases[] = { {"mongodb://127.0.0.1,127.0.0.2/dbName?foo=a&c=b&replicaSet=replName", "", "", - kSet, + kReplicaSet, "replName", 2, {{"foo", "a"}, {"c", "b"}, {"replicaSet", "replName"}}, @@ -258,7 +258,7 @@ const URITestCase validCases[] = { {"mongodb://user:pwd@127.0.0.1:1234,127.0.0.2:1234/?replicaSet=replName", "user", "pwd", - kSet, + kReplicaSet, "replName", 2, {{"replicaSet", "replName"}}, @@ -268,7 +268,7 @@ const URITestCase validCases[] = { {"mongodb://user@127.0.0.1:1234,127.0.0.2:1234/?replicaSet=replName", "user", "", - kSet, + kReplicaSet, "replName", 2, {{"replicaSet", "replName"}}, @@ -278,7 +278,7 @@ const URITestCase validCases[] = { {"mongodb://127.0.0.1:1234,127.0.0.1:1234/dbName?foo=a&c=b&replicaSet=replName", "", "", - kSet, + kReplicaSet, "replName", 2, {{"foo", "a"}, {"c", "b"}, {"replicaSet", "replName"}}, @@ -316,7 +316,7 @@ const URITestCase validCases[] = { {"mongodb://user:pwd@[::1],127.0.0.2/?replicaSet=replName", "user", "pwd", - kSet, + kReplicaSet, "replName", 2, {{"replicaSet", "replName"}}, @@ -326,7 +326,7 @@ const URITestCase validCases[] = { {"mongodb://user@[::1],127.0.0.2/?replicaSet=replName", "user", "", - kSet, + kReplicaSet, "replName", 2, {{"replicaSet", "replName"}}, @@ -336,7 +336,7 @@ const URITestCase validCases[] = { {"mongodb://[::1],127.0.0.2/dbName?foo=a&c=b&replicaSet=replName", "", "", - kSet, + kReplicaSet, "replName", 2, {{"foo", "a"}, {"c", "b"}, {"replicaSet", "replName"}}, @@ -346,7 +346,7 @@ const URITestCase validCases[] = { {"mongodb://user:pwd@[::1]:1234,127.0.0.2:1234/?replicaSet=replName", "user", "pwd", - kSet, + kReplicaSet, "replName", 2, {{"replicaSet", "replName"}}, @@ -356,7 +356,7 @@ const URITestCase validCases[] = { {"mongodb://user@[::1]:1234,127.0.0.2:1234/?replicaSet=replName", "user", "", - kSet, + kReplicaSet, "replName", 2, {{"replicaSet", "replName"}}, @@ -366,7 +366,7 @@ const URITestCase validCases[] = { {"mongodb://[::1]:1234,[::1]:1234/dbName?foo=a&c=b&replicaSet=replName", "", "", - kSet, + kReplicaSet, "replName", 2, {{"foo", "a"}, {"c", "b"}, {"replicaSet", "replName"}}, @@ -404,7 +404,7 @@ const URITestCase validCases[] = { {"mongodb://user:pwd@[::1],127.0.0.2/?replicaSet=replName", "user", "pwd", - kSet, + kReplicaSet, "replName", 2, {{"replicaSet", "replName"}}, @@ -414,7 +414,7 @@ const URITestCase validCases[] = { {"mongodb://user@[::1],127.0.0.2/?replicaSet=replName", "user", "", - kSet, + kReplicaSet, "replName", 2, {{"replicaSet", "replName"}}, @@ -424,7 +424,7 @@ const URITestCase validCases[] = { {"mongodb://[::1],127.0.0.2/dbName?foo=a&c=b&replicaSet=replName", "", "", - kSet, + kReplicaSet, "replName", 2, {{"foo", "a"}, {"c", "b"}, {"replicaSet", "replName"}}, @@ -434,7 +434,7 @@ const URITestCase validCases[] = { {"mongodb://user:pwd@[::1]:1234,127.0.0.2:1234/?replicaSet=replName", "user", "pwd", - kSet, + kReplicaSet, "replName", 2, {{"replicaSet", "replName"}}, @@ -444,7 +444,7 @@ const URITestCase validCases[] = { {"mongodb://user@[::1]:1234,127.0.0.2:1234/?replicaSet=replName", "user", "", - kSet, + kReplicaSet, "replName", 2, {{"replicaSet", "replName"}}, @@ -454,7 +454,7 @@ const URITestCase validCases[] = { {"mongodb://[::1]:1234,[::1]:1234/dbName?foo=a&c=b&replicaSet=replName", "", "", - kSet, + kReplicaSet, "replName", 2, {{"foo", "a"}, {"c", "b"}, {"replicaSet", "replName"}}, @@ -486,7 +486,7 @@ const URITestCase validCases[] = { {"mongodb://%2Ftmp%2Fmongodb-27017.sock,%2Ftmp%2Fmongodb-27018.sock/?replicaSet=replName", "", "", - kSet, + kReplicaSet, "replName", 2, {{"replicaSet", "replName"}}, @@ -609,7 +609,7 @@ void testValidURIFormat(URITestCase testCase) { ASSERT_EQ(testCase.uname, result.getUser()); ASSERT_EQ(testCase.password, result.getPassword()); ASSERT_EQ(testCase.type, result.type()); - ASSERT_EQ(testCase.setname, result.getSetName()); + ASSERT_EQ(testCase.setname, result.getReplicaSetName()); ASSERT_EQ(testCase.numservers, result.getServers().size()); compareOptions(0, testCase.URI, result.getOptions(), testCase.options); ASSERT_EQ(testCase.database, result.getDatabase()); @@ -657,8 +657,8 @@ TEST(MongoURI, CloneURIForServer) { ASSERT_OK(sw_uri.getStatus()); auto uri = sw_uri.getValue(); - ASSERT_EQ(uri.type(), kSet); - ASSERT_EQ(uri.getSetName(), "rs1"); + ASSERT_EQ(uri.type(), kReplicaSet); + ASSERT_EQ(uri.getReplicaSetName(), "rs1"); ASSERT_EQ(uri.getServers().size(), static_cast(3)); auto& uriOptions = uri.getOptions(); @@ -667,7 +667,7 @@ TEST(MongoURI, CloneURIForServer) { auto clonedURI = uri.cloneURIForServer(HostAndPort{"localhost:27020"}, StringData()); ASSERT_EQ(clonedURI.type(), kMaster); - ASSERT_TRUE(clonedURI.getSetName().empty()); + ASSERT_TRUE(clonedURI.getReplicaSetName().empty()); ASSERT_EQ(clonedURI.getServers().size(), static_cast(1)); auto& clonedURIOptions = clonedURI.getOptions(); ASSERT_EQ(clonedURIOptions.at("ssl"), "true"); @@ -754,7 +754,7 @@ TEST(MongoURI, specTests) { if (!replsetElement.eoo()) { ASSERT_EQ(replsetElement.type(), String); setName = replsetElement.String(); - connectionType = kSet; + connectionType = kReplicaSet; } for (auto&& field : optionsElement.Obj()) { diff --git a/src/mongo/client/remote_command_targeter_factory_impl.cpp b/src/mongo/client/remote_command_targeter_factory_impl.cpp index a0a1df7b6a7..c140a184a31 100644 --- a/src/mongo/client/remote_command_targeter_factory_impl.cpp +++ b/src/mongo/client/remote_command_targeter_factory_impl.cpp @@ -48,16 +48,16 @@ RemoteCommandTargeterFactoryImpl::~RemoteCommandTargeterFactoryImpl() = default; std::unique_ptr RemoteCommandTargeterFactoryImpl::create( const ConnectionString& connStr) { switch (connStr.type()) { - case ConnectionString::MASTER: - case ConnectionString::CUSTOM: + case ConnectionString::ConnectionType::kStandalone: + case ConnectionString::ConnectionType::kCustom: invariant(connStr.getServers().size() == 1); return std::make_unique(connStr.getServers().front()); - case ConnectionString::SET: + case ConnectionString::ConnectionType::kReplicaSet: return std::make_unique(connStr.getSetName(), connStr.getServers()); // These connections should never be seen - case ConnectionString::INVALID: - case ConnectionString::LOCAL: + case ConnectionString::ConnectionType::kInvalid: + case ConnectionString::ConnectionType::kLocal: MONGO_UNREACHABLE; } MONGO_UNREACHABLE; diff --git a/src/mongo/client/remote_command_targeter_factory_impl.h b/src/mongo/client/remote_command_targeter_factory_impl.h index df8494576db..235947402a7 100644 --- a/src/mongo/client/remote_command_targeter_factory_impl.h +++ b/src/mongo/client/remote_command_targeter_factory_impl.h @@ -35,9 +35,9 @@ namespace mongo { /** * Targeter factory that instantiates remote command targeters based on the type of the - * connection. It will return RemoteCommandTargeterStandalone for a single node (MASTER) or - * custom (CUSTOM) connection string and RemoteCommandTargeterRS for a SET connection string. - * All other connection strings are not supported and will cause a failed invariant error. + * connection. It will return RemoteCommandTargeterStandalone for a single node (kStandalone) or + * custom (kCustom) connection string and RemoteCommandTargeterRS for a kReplicaSet connection + * string. All other connection strings are not supported and will cause a failed invariant error. */ class RemoteCommandTargeterFactoryImpl final : public RemoteCommandTargeterFactory { public: diff --git a/src/mongo/client/replica_set_monitor_manager.cpp b/src/mongo/client/replica_set_monitor_manager.cpp index 0a1b1818215..732c8867b67 100644 --- a/src/mongo/client/replica_set_monitor_manager.cpp +++ b/src/mongo/client/replica_set_monitor_manager.cpp @@ -170,7 +170,7 @@ shared_ptr ReplicaSetMonitorManager::getOrCreateMonitor( } shared_ptr ReplicaSetMonitorManager::getOrCreateMonitor(const MongoURI& uri) { - invariant(uri.type() == ConnectionString::SET); + invariant(uri.type() == ConnectionString::ConnectionType::kReplicaSet); stdx::lock_guard lk(_mutex); uassert(ErrorCodes::ShutdownInProgress, str::stream() << "Unable to get monitor for '" << uri << "' due to shutdown", diff --git a/src/mongo/db/dbdirectclient.cpp b/src/mongo/db/dbdirectclient.cpp index bb1f5553906..04910a0faad 100644 --- a/src/mongo/db/dbdirectclient.cpp +++ b/src/mongo/db/dbdirectclient.cpp @@ -110,7 +110,7 @@ bool DBDirectClient::isReplicaSetMember() const { } ConnectionString::ConnectionType DBDirectClient::type() const { - return ConnectionString::MASTER; + return ConnectionString::ConnectionType::kStandalone; } double DBDirectClient::getSoTimeout() const { diff --git a/src/mongo/db/s/config/sharding_catalog_manager_add_shard_test.cpp b/src/mongo/db/s/config/sharding_catalog_manager_add_shard_test.cpp index 777b23622ee..a7b48597d72 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_add_shard_test.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_add_shard_test.cpp @@ -521,8 +521,8 @@ TEST_F(AddShardTest, StandaloneGenerateName) { TEST_F(AddShardTest, AddSCCCConnectionStringAsShard) { std::unique_ptr targeter( std::make_unique()); - auto invalidConn = - ConnectionString("host1:12345,host2:12345,host3:12345", ConnectionString::INVALID); + auto invalidConn = ConnectionString("host1:12345,host2:12345,host3:12345", + ConnectionString::ConnectionType::kInvalid); targeter->setConnectionStringReturnValue(invalidConn); auto future = launchAsync([this, invalidConn] { diff --git a/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp index b82c0b908e5..3fdb7828254 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp @@ -236,7 +236,8 @@ StatusWith> ShardingCatalogManager::_checkIfShardExis if (proposedShardConnectionString.type() != existingShardConnStr.type()) { return false; } - if (proposedShardConnectionString.type() == ConnectionString::SET && + if (proposedShardConnectionString.type() == + ConnectionString::ConnectionType::kReplicaSet && proposedShardConnectionString.getSetName() != existingShardConnStr.getSetName()) { return false; } @@ -246,8 +247,8 @@ StatusWith> ShardingCatalogManager::_checkIfShardExis return true; }; - if (existingShardConnStr.type() == ConnectionString::SET && - proposedShardConnectionString.type() == ConnectionString::SET && + if (existingShardConnStr.type() == ConnectionString::ConnectionType::kReplicaSet && + proposedShardConnectionString.type() == ConnectionString::ConnectionType::kReplicaSet && existingShardConnStr.getSetName() == proposedShardConnectionString.getSetName()) { // An existing shard has the same replica set name as the shard being added. // If the options aren't the same, then this is an error, @@ -533,7 +534,7 @@ StatusWith ShardingCatalogManager::addShard( const std::string* shardProposedName, const ConnectionString& shardConnectionString, const long long maxSize) { - if (shardConnectionString.type() == ConnectionString::INVALID) { + if (!shardConnectionString) { return {ErrorCodes::BadValue, "Invalid connection string"}; } @@ -565,7 +566,7 @@ StatusWith ShardingCatalogManager::addShard( auto targeter = shard->getTargeter(); auto stopMonitoringGuard = makeGuard([&] { - if (shardConnectionString.type() == ConnectionString::SET) { + if (shardConnectionString.type() == ConnectionString::ConnectionType::kReplicaSet) { // This is a workaround for the case were we could have some bad shard being // requested to be added and we put that bad connection string on the global replica set // monitor registry. It needs to be cleaned up so that when a correct replica set is diff --git a/src/mongo/db/s/sharding_initialization_mongod.cpp b/src/mongo/db/s/sharding_initialization_mongod.cpp index 65265781d1e..777985d1eb4 100644 --- a/src/mongo/db/s/sharding_initialization_mongod.cpp +++ b/src/mongo/db/s/sharding_initialization_mongod.cpp @@ -442,7 +442,9 @@ void ShardingInitializationMongoD::initializeFromShardIdentity( uassert(40372, "", shardingState->clusterId() == shardIdentity.getClusterId()); auto prevConfigsvrConnStr = shardRegistry->getConfigServerConnectionString(); - uassert(40373, "", prevConfigsvrConnStr.type() == ConnectionString::SET); + uassert(40373, + "", + prevConfigsvrConnStr.type() == ConnectionString::ConnectionType::kReplicaSet); uassert(40374, "", prevConfigsvrConnStr.getSetName() == configSvrConnStr.getSetName()); return; @@ -531,9 +533,9 @@ void initializeGlobalShardingStateForMongoD(OperationContext* opCtx, }; ShardFactory::BuildersMap buildersMap{ - {ConnectionString::SET, std::move(setBuilder)}, - {ConnectionString::MASTER, std::move(masterBuilder)}, - {ConnectionString::LOCAL, std::move(localBuilder)}, + {ConnectionString::ConnectionType::kReplicaSet, std::move(setBuilder)}, + {ConnectionString::ConnectionType::kStandalone, std::move(masterBuilder)}, + {ConnectionString::ConnectionType::kLocal, std::move(localBuilder)}, }; auto shardFactory = @@ -571,9 +573,7 @@ void initializeGlobalShardingStateForMongoD(OperationContext* opCtx, catCache->invalidateEntriesThatReferenceShard(removedShard); }}; - uassert(ErrorCodes::BadValue, - "Unrecognized connection string.", - configCS.type() != ConnectionString::INVALID); + uassert(ErrorCodes::BadValue, "Unrecognized connection string.", configCS); auto shardRegistry = std::make_unique( std::move(shardFactory), configCS, std::move(shardRemovalHooks)); diff --git a/src/mongo/db/s/sharding_initialization_mongod_test.cpp b/src/mongo/db/s/sharding_initialization_mongod_test.cpp index a724a245f84..44b90529a89 100644 --- a/src/mongo/db/s/sharding_initialization_mongod_test.cpp +++ b/src/mongo/db/s/sharding_initialization_mongod_test.cpp @@ -172,7 +172,7 @@ TEST_F(ShardingInitializationMongoDTest, ValidShardIdentitySucceeds) { ShardIdentityType shardIdentity; shardIdentity.setConfigsvrConnectionString( - ConnectionString(ConnectionString::SET, "a:1,b:2", "config")); + ConnectionString(ConnectionString::ConnectionType::kReplicaSet, "a:1,b:2", "config")); shardIdentity.setShardName(kShardName); shardIdentity.setClusterId(OID::gen()); @@ -189,7 +189,7 @@ TEST_F(ShardingInitializationMongoDTest, InitWhilePreviouslyInErrorStateWillStay ShardIdentityType shardIdentity; shardIdentity.setConfigsvrConnectionString( - ConnectionString(ConnectionString::SET, "a:1,b:2", "config")); + ConnectionString(ConnectionString::ConnectionType::kReplicaSet, "a:1,b:2", "config")); shardIdentity.setShardName(kShardName); shardIdentity.setClusterId(OID::gen()); @@ -222,7 +222,7 @@ TEST_F(ShardingInitializationMongoDTest, InitializeAgainWithMatchingShardIdentit auto clusterID = OID::gen(); ShardIdentityType shardIdentity; shardIdentity.setConfigsvrConnectionString( - ConnectionString(ConnectionString::SET, "a:1,b:2", "config")); + ConnectionString(ConnectionString::ConnectionType::kReplicaSet, "a:1,b:2", "config")); shardIdentity.setShardName(kShardName); shardIdentity.setClusterId(clusterID); @@ -230,7 +230,7 @@ TEST_F(ShardingInitializationMongoDTest, InitializeAgainWithMatchingShardIdentit ShardIdentityType shardIdentity2; shardIdentity2.setConfigsvrConnectionString( - ConnectionString(ConnectionString::SET, "a:1,b:2", "config")); + ConnectionString(ConnectionString::ConnectionType::kReplicaSet, "a:1,b:2", "config")); shardIdentity2.setShardName(kShardName); shardIdentity2.setClusterId(clusterID); @@ -255,7 +255,7 @@ TEST_F(ShardingInitializationMongoDTest, InitializeAgainWithMatchingReplSetNameS auto clusterID = OID::gen(); ShardIdentityType shardIdentity; shardIdentity.setConfigsvrConnectionString( - ConnectionString(ConnectionString::SET, "a:1,b:2", "config")); + ConnectionString(ConnectionString::ConnectionType::kReplicaSet, "a:1,b:2", "config")); shardIdentity.setShardName(kShardName); shardIdentity.setClusterId(clusterID); @@ -263,7 +263,7 @@ TEST_F(ShardingInitializationMongoDTest, InitializeAgainWithMatchingReplSetNameS ShardIdentityType shardIdentity2; shardIdentity2.setConfigsvrConnectionString( - ConnectionString(ConnectionString::SET, "b:2,c:3", "config")); + ConnectionString(ConnectionString::ConnectionType::kReplicaSet, "b:2,c:3", "config")); shardIdentity2.setShardName(kShardName); shardIdentity2.setClusterId(clusterID); @@ -319,7 +319,7 @@ TEST_F(ShardingInitializationMongoDTest, serverGlobalParams.overrideShardIdentity = [] { ShardIdentityType shardIdentity; shardIdentity.setConfigsvrConnectionString( - ConnectionString(ConnectionString::SET, "a:1,b:2", "config")); + ConnectionString(ConnectionString::ConnectionType::kReplicaSet, "a:1,b:2", "config")); shardIdentity.setShardName(kShardName); shardIdentity.setClusterId(OID::gen()); ASSERT_OK(shardIdentity.validate()); @@ -363,7 +363,7 @@ TEST_F(ShardingInitializationMongoDTest, serverGlobalParams.overrideShardIdentity = [] { ShardIdentityType shardIdentity; shardIdentity.setConfigsvrConnectionString( - ConnectionString(ConnectionString::SET, "a:1,b:2", "config")); + ConnectionString(ConnectionString::ConnectionType::kReplicaSet, "a:1,b:2", "config")); shardIdentity.setShardName(kShardName); shardIdentity.setClusterId(OID::gen()); ASSERT_OK(shardIdentity.validate()); @@ -406,7 +406,7 @@ TEST_F(ShardingInitializationMongoDTest, serverGlobalParams.overrideShardIdentity = [] { ShardIdentityType shardIdentity; shardIdentity.setConfigsvrConnectionString( - ConnectionString(ConnectionString::SET, "a:1,b:2", "config")); + ConnectionString(ConnectionString::ConnectionType::kReplicaSet, "a:1,b:2", "config")); shardIdentity.setShardName(kShardName); shardIdentity.setClusterId(OID::gen()); ASSERT_OK(shardIdentity.validate()); @@ -469,8 +469,8 @@ TEST_F(ShardingInitializationMongoDTest, BSONObj validShardIdentity = [&] { ShardIdentityType shardIdentity; - shardIdentity.setConfigsvrConnectionString( - ConnectionString(ConnectionString::SET, "a:1,b:2", "config")); + shardIdentity.setConfigsvrConnectionString(ConnectionString( + ConnectionString::ConnectionType::kReplicaSet, "a:1,b:2", "config")); shardIdentity.setShardName(kShardName); shardIdentity.setClusterId(OID::gen()); ASSERT_OK(shardIdentity.validate()); @@ -516,7 +516,7 @@ TEST_F(ShardingInitializationMongoDTest, BSONObj validShardIdentity = [&] { ShardIdentityType shardIdentity; shardIdentity.setConfigsvrConnectionString( - ConnectionString(ConnectionString::SET, "a:1,b:2", "config")); + ConnectionString(ConnectionString::ConnectionType::kReplicaSet, "a:1,b:2", "config")); shardIdentity.setShardName(kShardName); shardIdentity.setClusterId(OID::gen()); ASSERT_OK(shardIdentity.validate()); diff --git a/src/mongo/db/s/sharding_initialization_op_observer_test.cpp b/src/mongo/db/s/sharding_initialization_op_observer_test.cpp index 563a6325454..019394f91e9 100644 --- a/src/mongo/db/s/sharding_initialization_op_observer_test.cpp +++ b/src/mongo/db/s/sharding_initialization_op_observer_test.cpp @@ -90,7 +90,7 @@ private: TEST_F(ShardingInitializationOpObserverTest, GlobalInitGetsCalledAfterWriteCommits) { ShardIdentityType shardIdentity; shardIdentity.setConfigsvrConnectionString( - ConnectionString(ConnectionString::SET, "a:1,b:2", "config")); + ConnectionString(ConnectionString::ConnectionType::kReplicaSet, "a:1,b:2", "config")); shardIdentity.setShardName(kShardName); shardIdentity.setClusterId(OID::gen()); @@ -102,7 +102,7 @@ TEST_F(ShardingInitializationOpObserverTest, GlobalInitGetsCalledAfterWriteCommi TEST_F(ShardingInitializationOpObserverTest, GlobalInitDoesntGetCalledIfWriteAborts) { ShardIdentityType shardIdentity; shardIdentity.setConfigsvrConnectionString( - ConnectionString(ConnectionString::SET, "a:1,b:2", "config")); + ConnectionString(ConnectionString::ConnectionType::kReplicaSet, "a:1,b:2", "config")); shardIdentity.setShardName(kShardName); shardIdentity.setClusterId(OID::gen()); @@ -128,7 +128,7 @@ TEST_F(ShardingInitializationOpObserverTest, GlobalInitDoesntGetCalledIfWriteAbo TEST_F(ShardingInitializationOpObserverTest, GlobalInitDoesntGetsCalledIfNSIsNotForShardIdentity) { ShardIdentityType shardIdentity; shardIdentity.setConfigsvrConnectionString( - ConnectionString(ConnectionString::SET, "a:1,b:2", "config")); + ConnectionString(ConnectionString::ConnectionType::kReplicaSet, "a:1,b:2", "config")); shardIdentity.setShardName(kShardName); shardIdentity.setClusterId(OID::gen()); diff --git a/src/mongo/db/s/sharding_mongod_test_fixture.cpp b/src/mongo/db/s/sharding_mongod_test_fixture.cpp index 78bd0f861ae..d0ccaa291f8 100644 --- a/src/mongo/db/s/sharding_mongod_test_fixture.cpp +++ b/src/mongo/db/s/sharding_mongod_test_fixture.cpp @@ -192,14 +192,15 @@ std::unique_ptr ShardingMongodTestFixture::makeShardRegistry( return std::make_unique(shardId, connStr, targeterFactoryPtr->create(connStr)); }; - ShardFactory::BuilderCallable masterBuilder = [targeterFactoryPtr]( - const ShardId& shardId, - const ConnectionString& connStr) { + ShardFactory::BuilderCallable standaloneBuilder = [targeterFactoryPtr]( + const ShardId& shardId, + const ConnectionString& connStr) { return std::make_unique(shardId, connStr, targeterFactoryPtr->create(connStr)); }; - ShardFactory::BuildersMap buildersMap{{ConnectionString::SET, std::move(setBuilder)}, - {ConnectionString::MASTER, std::move(masterBuilder)}}; + ShardFactory::BuildersMap buildersMap{ + {ConnectionString::ConnectionType::kReplicaSet, std::move(setBuilder)}, + {ConnectionString::ConnectionType::kStandalone, std::move(standaloneBuilder)}}; // Only config servers use ShardLocal for now. if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) { @@ -209,7 +210,7 @@ std::unique_ptr ShardingMongodTestFixture::makeShardRegistry( }; buildersMap.insert( std::pair( - ConnectionString::LOCAL, std::move(localBuilder))); + ConnectionString::ConnectionType::kLocal, std::move(localBuilder))); } auto shardFactory = diff --git a/src/mongo/db/s/type_shard_identity.cpp b/src/mongo/db/s/type_shard_identity.cpp index 773333f59e5..673636f01b1 100644 --- a/src/mongo/db/s/type_shard_identity.cpp +++ b/src/mongo/db/s/type_shard_identity.cpp @@ -52,7 +52,7 @@ StatusWith ShardIdentityType::fromShardIdentityDocument(const ShardIdentity::parse(IDLParserErrorContext("ShardIdentity"), shardIdentityBSON); const auto& configsvrConnStr = shardIdentity.getConfigsvrConnectionString(); - if (configsvrConnStr.type() != ConnectionString::SET) { + if (configsvrConnStr.type() != ConnectionString::ConnectionType::kReplicaSet) { return Status(ErrorCodes::UnsupportedFormat, str::stream() << "config server connection string can only be replica sets: " @@ -67,7 +67,7 @@ StatusWith ShardIdentityType::fromShardIdentityDocument(const Status ShardIdentityType::validate() const { const auto& configsvrConnStr = getConfigsvrConnectionString(); - if (configsvrConnStr.type() != ConnectionString::SET) { + if (configsvrConnStr.type() != ConnectionString::ConnectionType::kReplicaSet) { return {ErrorCodes::UnsupportedFormat, str::stream() << "config connection string can only be replica sets, got " << ConnectionString::typeToString(configsvrConnStr.type())}; diff --git a/src/mongo/dbtests/clienttests.cpp b/src/mongo/dbtests/clienttests.cpp index f17326bfbf3..e847a3b2fad 100644 --- a/src/mongo/dbtests/clienttests.cpp +++ b/src/mongo/dbtests/clienttests.cpp @@ -232,8 +232,8 @@ class ConnectionStringTests { public: void run() { { - ConnectionString s("a/b,c,d", ConnectionString::SET); - ASSERT_EQUALS(ConnectionString::SET, s.type()); + ConnectionString s("a/b,c,d", ConnectionString::ConnectionType::kReplicaSet); + ASSERT_EQUALS(ConnectionString::ConnectionType::kReplicaSet, s.type()); ASSERT_EQUALS("a", s.getSetName()); vector v = s.getServers(); ASSERT_EQUALS(3U, v.size()); diff --git a/src/mongo/dbtests/mock/mock_conn_registry.cpp b/src/mongo/dbtests/mock/mock_conn_registry.cpp index 1847aeaa01f..37d9df06ceb 100644 --- a/src/mongo/dbtests/mock/mock_conn_registry.cpp +++ b/src/mongo/dbtests/mock/mock_conn_registry.cpp @@ -107,7 +107,7 @@ std::unique_ptr MockConnRegistry::MockConnHook::connect( auto conn = _registry->connect(hostName); if (!conn->connect(hostName.c_str(), StringData(), errmsg)) { - // mimic ConnectionString::connect for MASTER type connection to return NULL + // mimic ConnectionString::connect for kStandalone type connection to return NULL // if the destination is unreachable. return nullptr; } diff --git a/src/mongo/dbtests/mock/mock_dbclient_connection.cpp b/src/mongo/dbtests/mock/mock_dbclient_connection.cpp index 55d428a94c5..ec17681e12e 100644 --- a/src/mongo/dbtests/mock/mock_dbclient_connection.cpp +++ b/src/mongo/dbtests/mock/mock_dbclient_connection.cpp @@ -173,7 +173,7 @@ std::unique_ptr MockDBClientConnection::query( } mongo::ConnectionString::ConnectionType MockDBClientConnection::type() const { - return mongo::ConnectionString::CUSTOM; + return mongo::ConnectionString::ConnectionType::kCustom; } unsigned long long MockDBClientConnection::query( diff --git a/src/mongo/dbtests/mock/mock_remote_db_server.cpp b/src/mongo/dbtests/mock/mock_remote_db_server.cpp index e6c766baa24..9c3fe249327 100644 --- a/src/mongo/dbtests/mock/mock_remote_db_server.cpp +++ b/src/mongo/dbtests/mock/mock_remote_db_server.cpp @@ -230,7 +230,7 @@ mongo::BSONArray MockRemoteDBServer::query(MockRemoteDBServer::InstanceID id, } mongo::ConnectionString::ConnectionType MockRemoteDBServer::type() const { - return mongo::ConnectionString::CUSTOM; + return mongo::ConnectionString::ConnectionType::kCustom; } size_t MockRemoteDBServer::getCmdCount() const { diff --git a/src/mongo/rpc/op_msg_integration_test.cpp b/src/mongo/rpc/op_msg_integration_test.cpp index 78bbe3d17db..3c3c46ed63b 100644 --- a/src/mongo/rpc/op_msg_integration_test.cpp +++ b/src/mongo/rpc/op_msg_integration_test.cpp @@ -196,7 +196,7 @@ TEST(OpMsg, CloseConnectionOnFireAndForgetNotWritablePrimaryError) { const auto connStr = unittest::getFixtureConnectionString(); // This test only works against a replica set. - if (connStr.type() != ConnectionString::SET) { + if (connStr.type() != ConnectionString::ConnectionType::kReplicaSet) { return; } diff --git a/src/mongo/s/client/shard_registry.cpp b/src/mongo/s/client/shard_registry.cpp index b19f5d7d77b..4bb4e11a2c0 100644 --- a/src/mongo/s/client/shard_registry.cpp +++ b/src/mongo/s/client/shard_registry.cpp @@ -383,8 +383,8 @@ void ShardRegistry::_removeReplicaSet(const std::string& setName) { void ShardRegistry::updateReplSetHosts(const ConnectionString& givenConnString, ConnectionStringUpdateType updateType) { - invariant(givenConnString.type() == ConnectionString::SET || - givenConnString.type() == ConnectionString::CUSTOM); // For dbtests + invariant(givenConnString.type() == ConnectionString::ConnectionType::kReplicaSet || + givenConnString.type() == ConnectionString::ConnectionType::kCustom); // For dbtests auto setName = givenConnString.getSetName(); @@ -830,10 +830,10 @@ void ShardRegistryData::_addShard(std::shared_ptr shard) { "Adding new shard to shard registry", "shardId"_attr = shard->getId(), "shardConnectionString"_attr = connString); - if (connString.type() == ConnectionString::SET) { + if (connString.type() == ConnectionString::ConnectionType::kReplicaSet) { _rsLookup[connString.getSetName()] = shard; - } else if (connString.type() == ConnectionString::CUSTOM) { - // CUSTOM connection strings (ie "$dummy:10000) become DBDirectClient connections which + } else if (connString.type() == ConnectionString::ConnectionType::kCustom) { + // kCustom connection strings (ie "$dummy:10000) become DBDirectClient connections which // always return "localhost" as their response to getServerAddress(). This is just for // making dbtest work. _shardIdLookup[ShardId("localhost")] = shard; diff --git a/src/mongo/s/client/sharding_connection_hook.cpp b/src/mongo/s/client/sharding_connection_hook.cpp index 3d153a8012b..0a7374a240e 100644 --- a/src/mongo/s/client/sharding_connection_hook.cpp +++ b/src/mongo/s/client/sharding_connection_hook.cpp @@ -49,7 +49,7 @@ ShardingConnectionHook::ShardingConnectionHook(std::unique_ptrtype() == ConnectionString::INVALID) { + if (conn->type() == ConnectionString::ConnectionType::kInvalid) { uasserted(ErrorCodes::BadValue, str::stream() << "Unrecognized connection string."); } @@ -72,7 +72,7 @@ void ShardingConnectionHook::onCreate(DBClientBase* conn) { }); - if (conn->type() == ConnectionString::MASTER) { + if (conn->type() == ConnectionString::ConnectionType::kStandalone) { BSONObj isMasterResponse; if (!conn->runCommand("admin", BSON("ismaster" << 1), isMasterResponse)) { uassertStatusOK(getStatusFromCommandResult(isMasterResponse)); diff --git a/src/mongo/s/mongos_main.cpp b/src/mongo/s/mongos_main.cpp index 4dfdc0414b1..e3475550b8e 100644 --- a/src/mongo/s/mongos_main.cpp +++ b/src/mongo/s/mongos_main.cpp @@ -416,8 +416,8 @@ Status initializeSharding(OperationContext* opCtx) { }; ShardFactory::BuildersMap buildersMap{ - {ConnectionString::SET, std::move(setBuilder)}, - {ConnectionString::MASTER, std::move(masterBuilder)}, + {ConnectionString::ConnectionType::kReplicaSet, std::move(setBuilder)}, + {ConnectionString::ConnectionType::kStandalone, std::move(masterBuilder)}, }; auto shardFactory = @@ -439,7 +439,7 @@ Status initializeSharding(OperationContext* opCtx) { catCache->invalidateEntriesThatReferenceShard(removedShard); }}; - if (mongosGlobalParams.configdbs.type() == ConnectionString::INVALID) { + if (!mongosGlobalParams.configdbs) { return {ErrorCodes::BadValue, "Unrecognized connection string."}; } diff --git a/src/mongo/s/mongos_options.cpp b/src/mongo/s/mongos_options.cpp index 4205b63954a..2ab56d4e191 100644 --- a/src/mongo/s/mongos_options.cpp +++ b/src/mongo/s/mongos_options.cpp @@ -137,7 +137,8 @@ Status storeMongosOptions(const moe::Environment& params) { return configdbConnectionString.getStatus(); } - if (configdbConnectionString.getValue().type() != ConnectionString::SET) { + if (configdbConnectionString.getValue().type() != + ConnectionString::ConnectionType::kReplicaSet) { return Status(ErrorCodes::BadValue, str::stream() << "configdb supports only replica set connection string"); } diff --git a/src/mongo/s/query/cluster_find.cpp b/src/mongo/s/query/cluster_find.cpp index 395f8080acd..cc81dd0df0c 100644 --- a/src/mongo/s/query/cluster_find.cpp +++ b/src/mongo/s/query/cluster_find.cpp @@ -196,7 +196,7 @@ std::vector> constructRequestsForShards( std::vector> requests; for (const auto& shardId : shardIds) { const auto shard = uassertStatusOK(shardRegistry->getShard(opCtx, shardId)); - invariant(!shard->isConfig() || shard->getConnString().type() != ConnectionString::INVALID); + invariant(!shard->isConfig() || shard->getConnString()); BSONObjBuilder cmdBuilder; qrToForward->asFindCommand(&cmdBuilder); diff --git a/src/mongo/s/request_types/add_shard_request_type.cpp b/src/mongo/s/request_types/add_shard_request_type.cpp index 95ce8b0c8bb..7afaba2874c 100644 --- a/src/mongo/s/request_types/add_shard_request_type.cpp +++ b/src/mongo/s/request_types/add_shard_request_type.cpp @@ -88,8 +88,8 @@ StatusWith AddShardRequest::parseInternalFields(const BSONObj& } ConnectionString connString = std::move(swConnString.getValue()); - if (connString.type() != ConnectionString::MASTER && - connString.type() != ConnectionString::SET) { + if (connString.type() != ConnectionString::ConnectionType::kStandalone && + connString.type() != ConnectionString::ConnectionType::kReplicaSet) { return {ErrorCodes::FailedToParse, stream() << "Invalid connection string " << connString.toString()}; } diff --git a/src/mongo/s/sharding_router_test_fixture.cpp b/src/mongo/s/sharding_router_test_fixture.cpp index db4a4a3bb29..084a376c59a 100644 --- a/src/mongo/s/sharding_router_test_fixture.cpp +++ b/src/mongo/s/sharding_router_test_fixture.cpp @@ -157,8 +157,8 @@ ShardingTestFixture::ShardingTestFixture() }; ShardFactory::BuildersMap buildersMap{ - {ConnectionString::SET, std::move(setBuilder)}, - {ConnectionString::MASTER, std::move(masterBuilder)}, + {ConnectionString::ConnectionType::kReplicaSet, std::move(setBuilder)}, + {ConnectionString::ConnectionType::kStandalone, std::move(masterBuilder)}, }; auto shardFactory = diff --git a/src/mongo/scripting/mozjs/mongo.cpp b/src/mongo/scripting/mozjs/mongo.cpp index 6849e636391..deddb13466d 100644 --- a/src/mongo/scripting/mozjs/mongo.cpp +++ b/src/mongo/scripting/mozjs/mongo.cpp @@ -763,7 +763,7 @@ void MongoBase::Functions::isReplicaSetConnection::call(JSContext* cx, JS::CallA uasserted(ErrorCodes::BadValue, "isReplicaSetConnection takes no args"); } - args.rval().setBoolean(conn->type() == ConnectionString::ConnectionType::SET); + args.rval().setBoolean(conn->type() == ConnectionString::ConnectionType::kReplicaSet); } void MongoBase::Functions::_markNodeAsFailed::call(JSContext* cx, JS::CallArgs args) { -- cgit v1.2.1