summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Milkie <milkie@10gen.com>2014-08-29 16:34:24 -0400
committerEric Milkie <milkie@10gen.com>2014-08-29 17:17:00 -0400
commit0fbd416c565ec4af11990e64cab887af12fbf76f (patch)
tree2787feb1a82b00469c60de37a28767f806d06742
parent746e8835b0b841235b767628d6ae0382a85bdab0 (diff)
downloadmongo-0fbd416c565ec4af11990e64cab887af12fbf76f.tar.gz
SERVER-15089 oplogreader use HostAndPort to connect instead of strings
-rw-r--r--src/mongo/db/repl/bgsync.cpp2
-rw-r--r--src/mongo/db/repl/health.cpp2
-rw-r--r--src/mongo/db/repl/master_slave.cpp6
-rw-r--r--src/mongo/db/repl/oplogreader.cpp16
-rw-r--r--src/mongo/db/repl/oplogreader.h8
-rw-r--r--src/mongo/db/repl/rs_initialsync.cpp4
-rw-r--r--src/mongo/db/repl/sync.cpp2
7 files changed, 21 insertions, 19 deletions
diff --git a/src/mongo/db/repl/bgsync.cpp b/src/mongo/db/repl/bgsync.cpp
index 86cad555c4f..2ed63b2b512 100644
--- a/src/mongo/db/repl/bgsync.cpp
+++ b/src/mongo/db/repl/bgsync.cpp
@@ -393,7 +393,7 @@ namespace repl {
while ((target = theReplSet->getMemberToSyncTo()) != NULL) {
string current = target->fullName();
- if (!r.connect(current)) {
+ if (!r.connect(target->h())) {
LOG(2) << "replSet can't connect to " << current << " to read operations" << rsLog;
r.resetConnection();
theReplSet->veto(current);
diff --git a/src/mongo/db/repl/health.cpp b/src/mongo/db/repl/health.cpp
index 3351f2f8340..780a09d646f 100644
--- a/src/mongo/db/repl/health.cpp
+++ b/src/mongo/db/repl/health.cpp
@@ -140,7 +140,7 @@ namespace repl {
/** todo fix we might want an so timeout here */
OplogReader reader;
- if (reader.connect(m->fullName()) == false) {
+ if (reader.connect(m->h()) == false) {
ss << "couldn't connect to " << m->fullName();
return;
}
diff --git a/src/mongo/db/repl/master_slave.cpp b/src/mongo/db/repl/master_slave.cpp
index a66a2621385..5135f77509d 100644
--- a/src/mongo/db/repl/master_slave.cpp
+++ b/src/mongo/db/repl/master_slave.cpp
@@ -344,7 +344,8 @@ namespace repl {
invariant(txn->lockState()->isW());
Lock::TempRelease tempRelease(txn->lockState());
- if (!oplogReader.connect(hostName, getGlobalReplicationCoordinator()->getMyRID())) {
+ if (!oplogReader.connect(HostAndPort(hostName),
+ getGlobalReplicationCoordinator()->getMyRID())) {
msgassertedNoTrace( 14051 , "unable to connect to resync");
}
/* todo use getDatabaseNames() method here */
@@ -1020,7 +1021,8 @@ namespace repl {
return -1;
}
- if ( !oplogReader.connect(hostName, getGlobalReplicationCoordinator()->getMyRID()) ) {
+ if ( !oplogReader.connect(HostAndPort(hostName),
+ getGlobalReplicationCoordinator()->getMyRID()) ) {
LOG(4) << "repl: can't connect to sync source" << endl;
return -1;
}
diff --git a/src/mongo/db/repl/oplogreader.cpp b/src/mongo/db/repl/oplogreader.cpp
index 5037438b6f3..acb2eb71d7d 100644
--- a/src/mongo/db/repl/oplogreader.cpp
+++ b/src/mongo/db/repl/oplogreader.cpp
@@ -98,13 +98,13 @@ namespace repl {
readersCreatedStats.increment();
}
- bool OplogReader::commonConnect(const string& hostName) {
+ bool OplogReader::commonConnect(const HostAndPort& host) {
if( conn() == 0 ) {
_conn = shared_ptr<DBClientConnection>(new DBClientConnection(false,
0,
tcp_timeout));
string errmsg;
- if ( !_conn->connect(hostName.c_str(), errmsg) ||
+ if ( !_conn->connect(host, errmsg) ||
(getGlobalAuthorizationManager()->isAuthEnabled() &&
!replAuthenticate(_conn.get())) ) {
@@ -116,24 +116,24 @@ namespace repl {
return true;
}
- bool OplogReader::connect(const std::string& hostName) {
+ bool OplogReader::connect(const HostAndPort& host) {
if (conn()) {
return true;
}
- if (!commonConnect(hostName)) {
+ if (!commonConnect(host)) {
return false;
}
return true;
}
- bool OplogReader::connect(const std::string& hostName, const OID& myRID) {
+ bool OplogReader::connect(const HostAndPort& host, const OID& myRID) {
if (conn()) {
return true;
}
- if (!commonConnect(hostName)) {
+ if (!commonConnect(host)) {
return false;
}
@@ -144,12 +144,12 @@ namespace repl {
return true;
}
- bool OplogReader::connect(const mongo::OID& rid, const int from, const string& to) {
+ bool OplogReader::connect(const mongo::OID& rid, const int from, const HostAndPort& to) {
if (conn() != 0) {
return true;
}
if (commonConnect(to)) {
- log() << "handshake between " << from << " and " << to << endl;
+ log() << "handshake between " << from << " and " << to.toString() << endl;
return passthroughHandshake(rid, from);
}
return false;
diff --git a/src/mongo/db/repl/oplogreader.h b/src/mongo/db/repl/oplogreader.h
index 0660e081806..0ce08a19d62 100644
--- a/src/mongo/db/repl/oplogreader.h
+++ b/src/mongo/db/repl/oplogreader.h
@@ -74,11 +74,11 @@ namespace repl {
static const int tcp_timeout = 30;
/* ok to call if already connected */
- bool connect(const std::string& hostname);
+ bool connect(const HostAndPort& host);
- bool connect(const std::string& hostname, const OID& myRID);
+ bool connect(const HostAndPort& host, const OID& myRID);
- bool connect(const mongo::OID& rid, const int from, const std::string& to);
+ bool connect(const mongo::OID& rid, const int from, const HostAndPort& to);
void tailCheck();
@@ -156,7 +156,7 @@ namespace repl {
private:
/** @return true iff connection was successful */
- bool commonConnect(const std::string& hostName);
+ bool commonConnect(const HostAndPort& host);
bool passthroughHandshake(const mongo::OID& rid, const int f);
};
diff --git a/src/mongo/db/repl/rs_initialsync.cpp b/src/mongo/db/repl/rs_initialsync.cpp
index fa3dd087206..5f4262d893b 100644
--- a/src/mongo/db/repl/rs_initialsync.cpp
+++ b/src/mongo/db/repl/rs_initialsync.cpp
@@ -297,7 +297,7 @@ namespace repl {
minValid = r->getLastOp(rsoplog);
} catch ( SocketException & ) {
log() << "connection lost to " << source->h().toString() << "; is your tcp keepalive interval set appropriately?";
- if( !r->connect(source->h().toString()) ) {
+ if( !r->connect(source->h()) ) {
sethbmsg( str::stream() << "initial sync couldn't connect to " << source->h().toString() , 0);
throw;
}
@@ -380,7 +380,7 @@ namespace repl {
string sourceHostname = source->h().toString();
init.setHostname(sourceHostname);
OplogReader r;
- if( !r.connect(sourceHostname) ) {
+ if( !r.connect(source->h()) ) {
sethbmsg( str::stream() << "initial sync couldn't connect to " << source->h().toString() , 0);
sleepsecs(15);
return;
diff --git a/src/mongo/db/repl/sync.cpp b/src/mongo/db/repl/sync.cpp
index 7444b4f4526..20ff2f5d26e 100644
--- a/src/mongo/db/repl/sync.cpp
+++ b/src/mongo/db/repl/sync.cpp
@@ -69,7 +69,7 @@ namespace repl {
sleepsecs(retryCount * retryCount);
}
try {
- bool ok = missingObjReader.connect(hn);
+ bool ok = missingObjReader.connect(HostAndPort(hn));
if (!ok) {
warning() << "network problem detected while connecting to the "
<< "sync source, attempt " << retryCount << " of "