diff options
author | Andy Schwerin <schwerin@mongodb.com> | 2014-07-02 13:00:15 -0400 |
---|---|---|
committer | Andy Schwerin <schwerin@mongodb.com> | 2014-07-02 19:17:55 -0400 |
commit | e8b6969143e1d218a105c64716203fd7b74137d4 (patch) | |
tree | 183e583bb4ad005c0801839323ac0d9a7d8aebe4 | |
parent | 8ada5660746aa5aa351cc36e8d793cbc353c4fad (diff) | |
download | mongo-e8b6969143e1d218a105c64716203fd7b74137d4.tar.gz |
SERVER-14419 Correctly parse the "masterHost" argument to Cloner::go into a ConnectionString, not a HostAndPort.
The argument represents a ConnectionString, but we parse it into a HostAndPort
when doing isSelf checks. This was an error before that led checks to succeed
incorrectly, but fails with the new HostAndPort parsing code from SERVER-14419.
-rw-r--r-- | src/mongo/db/cloner.cpp | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp index 52c96a142c3..fb79ebd4c07 100644 --- a/src/mongo/db/cloner.cpp +++ b/src/mongo/db/cloner.cpp @@ -359,15 +359,31 @@ namespace mongo { } massert( 10289 , "useReplAuth is not written to replication log", !opts.useReplAuth || !opts.logForRepl ); + const ConnectionString cs = ConnectionString::parse(masterHost, errmsg); + if (!cs.isValid()) { + if (errCode) + *errCode = ErrorCodes::FailedToParse; + return false; + } + + bool masterSameProcess = false; + std::vector<HostAndPort> csServers = cs.getServers(); + for (std::vector<HostAndPort>::const_iterator iter = csServers.begin(); + iter != csServers.end(); ++iter) { + #if !defined(_WIN32) && !defined(__sunos__) - // isSelf() only does the necessary comparisons on os x and linux (SERVER-14165) - bool masterSameProcess = repl::isSelf(HostAndPort(masterHost)); + // isSelf() only does the necessary comparisons on os x and linux (SERVER-14165) + if (!repl::isSelf(*iter)) + continue; #else - stringstream a,b; - a << "localhost:" << serverGlobalParams.port; - b << "127.0.0.1:" << serverGlobalParams.port; - bool masterSameProcess = (a.str() == masterHost || b.str() == masterHost); + if (iter->port() != serverGlobalParams.port) + continue; + if (iter->host() != "localhost" && iter->host() != "127.0.0.1") + continue; #endif + masterSameProcess = true; + break; + } if (masterSameProcess) { if (opts.fromDB == toDBName) { @@ -384,7 +400,6 @@ namespace mongo { // nothing to do } else if ( !masterSameProcess ) { - ConnectionString cs = ConnectionString::parse( masterHost, errmsg ); auto_ptr<DBClientBase> con( cs.connect( errmsg )); if ( !con.get() ) return false; |