summaryrefslogtreecommitdiff
path: root/src/mongo/client/connection_string.cpp
diff options
context:
space:
mode:
authorMisha Tyulenev <misha@mongodb.com>2016-03-10 17:30:44 -0500
committerMisha Tyulenev <misha@mongodb.com>2016-03-10 18:18:38 -0500
commiteaef6254d3bcb27657de670ec1b9c797965e7c82 (patch)
tree09d29bd80943025732ebd3139deeea0191d8e171 /src/mongo/client/connection_string.cpp
parent41a738c7629cd52b357b0bce6650182219ae9088 (diff)
downloadmongo-eaef6254d3bcb27657de670ec1b9c797965e7c82.tar.gz
SERVER-22320 remove SYNC option and SyncClusterConnection
Diffstat (limited to 'src/mongo/client/connection_string.cpp')
-rw-r--r--src/mongo/client/connection_string.cpp70
1 files changed, 24 insertions, 46 deletions
diff --git a/src/mongo/client/connection_string.cpp b/src/mongo/client/connection_string.cpp
index 69b3f952039..18ee8ea1234 100644
--- a/src/mongo/client/connection_string.cpp
+++ b/src/mongo/client/connection_string.cpp
@@ -47,6 +47,7 @@ ConnectionString::ConnectionString(StringData setName, std::vector<HostAndPort>
_finishInit();
}
+// TODO: unify c-tors
ConnectionString::ConnectionString(ConnectionType type,
const std::string& s,
const std::string& setName) {
@@ -63,18 +64,9 @@ ConnectionString::ConnectionString(ConnectionType type,
_finishInit();
}
-ConnectionString::ConnectionString(const std::string& s, ConnectionType favoredMultipleType) {
+ConnectionString::ConnectionString(const std::string& s, ConnectionType connType)
+ : _type(connType) {
_fillServers(s);
-
- if (_type != INVALID) {
- // set already
- } else if (_servers.size() == 1) {
- _type = MASTER;
- } else {
- _type = favoredMultipleType;
- verify(_type == SET || _type == SYNC);
- }
-
_finishInit();
}
@@ -83,6 +75,7 @@ ConnectionString ConnectionString::forReplicaSet(StringData setName,
return ConnectionString(setName, std::move(servers));
}
+// TODO: rewrite parsing make it more reliable
void ConnectionString::_fillServers(std::string s) {
//
// Custom-handled servers/replica sets start with '$'
@@ -90,34 +83,38 @@ void ConnectionString::_fillServers(std::string s) {
// (also disallows $replicaSetName hosts)
//
- if (s.find('$') == 0)
+ if (s.find('$') == 0) {
_type = CUSTOM;
+ }
- {
- std::string::size_type idx = s.find('/');
- if (idx != std::string::npos) {
- _setName = s.substr(0, idx);
- s = s.substr(idx + 1);
- if (_type != CUSTOM)
- _type = SET;
- }
+ std::string::size_type idx = s.find('/');
+ if (idx != std::string::npos) {
+ _setName = s.substr(0, idx);
+ s = s.substr(idx + 1);
+ if (_type != CUSTOM)
+ _type = SET;
}
- std::string::size_type idx;
while ((idx = s.find(',')) != std::string::npos) {
_servers.push_back(HostAndPort(s.substr(0, idx)));
s = s.substr(idx + 1);
}
+
_servers.push_back(HostAndPort(s));
+
+ if (_servers.size() == 1 && _type == INVALID) {
+ _type = MASTER;
+ }
}
void ConnectionString::_finishInit() {
switch (_type) {
case MASTER:
+ verify(_setName.empty());
verify(_servers.size() == 1);
break;
case SET:
- verify(_setName.size());
+ verify(!_setName.empty());
verify(_servers.size() >= 1); // 1 is ok since we can derive
break;
default:
@@ -149,6 +146,7 @@ void ConnectionString::_finishInit() {
_string = ss.str();
}
+// TODO: SERVER-23014
bool ConnectionString::sameLogicalEndpoint(const ConnectionString& other) const {
if (_type != other._type) {
return false;
@@ -161,26 +159,6 @@ bool ConnectionString::sameLogicalEndpoint(const ConnectionString& other) const
return _servers[0] == other._servers[0];
case SET:
return _setName == other._setName;
- case SYNC:
- // The servers all have to be the same in each, but not in the same order.
- if (_servers.size() != other._servers.size()) {
- return false;
- }
-
- for (unsigned i = 0; i < _servers.size(); i++) {
- bool found = false;
- for (unsigned j = 0; j < other._servers.size(); j++) {
- if (_servers[i] == other._servers[j]) {
- found = true;
- break;
- }
- }
-
- if (!found)
- return false;
- }
-
- return true;
case CUSTOM:
return _string == other._string;
}
@@ -209,9 +187,11 @@ StatusWith<ConnectionString> ConnectionString::parse(const std::string& url) {
return ConnectionString(singleHost);
}
- // Sharding config server
if (numCommas == 2) {
- return ConnectionString(SYNC, url, "");
+ return Status(ErrorCodes::FailedToParse,
+ str::stream() << "mirrored config server connections are not supported; for "
+ "config server replica sets be sure to use the replica set "
+ "connection string");
}
return Status(ErrorCodes::FailedToParse, str::stream() << "invalid url [" << url << "]");
@@ -225,8 +205,6 @@ std::string ConnectionString::typeToString(ConnectionType type) {
return "master";
case SET:
return "set";
- case SYNC:
- return "sync";
case CUSTOM:
return "custom";
}