Skip to content

Commit

Permalink
better hostandport
Browse files Browse the repository at this point in the history
  • Loading branch information
dwight committed Jul 19, 2010
1 parent 87f8edd commit 80fbaf2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
8 changes: 6 additions & 2 deletions db/repl/health.cpp
Expand Up @@ -73,10 +73,14 @@ namespace mongo {
bool ok = h > 0;
s << td(h);
s << td(ago(hbinfo().upSince));
bool never = false;
{
string h;
time_t hb = hbinfo().lastHeartbeat;
if( hb == 0 ) h = "never";
if( hb == 0 ) {
h = "never";
never = true;
}
else h = ago(hb) + " ago";
s << td(h);
}
Expand All @@ -85,7 +89,7 @@ namespace mongo {
s << td( grey(hbinfo().lastHeartbeatMsg,!ok) );
stringstream q;
q << "/_replSetOplog?" << id();
s << td( a(q.str(), "", hbinfo().opTime.toString()) );
s << td( a(q.str(), "", never ? "?" : hbinfo().opTime.toString()) );
s << _tr();
}

Expand Down
4 changes: 2 additions & 2 deletions db/repl/rs_sync.cpp
Expand Up @@ -36,8 +36,8 @@ namespace mongo {

void ReplSetImpl::syncThread() {
while( 1 ) {
try {
// ...
try {
_syncThread();
}
catch(DBException& e) {
log() << "replSet syncThread: " << e.toString() << rsLog;
Expand Down
16 changes: 13 additions & 3 deletions util/hostandport.h
Expand Up @@ -49,7 +49,17 @@ namespace mongo {
/* uses real hostname instead of localhost */
static HostAndPort Me();

bool operator<(const HostAndPort& r) const { return _host < r._host || (_host==r._host&&_port<r._port); }
bool operator<(const HostAndPort& r) const {
if( _host < r._host )
return true;
if( _host == r._host )
return port() < r.port();
return false;
}

bool operator==(const HostAndPort& r) const {
return _host == r._host && port() == r.port();
}

/* returns true if the host/port combo identifies this process instance. */
bool isSelf() const;
Expand All @@ -62,8 +72,8 @@ namespace mongo {
operator string() const { return toString(); }

string host() const { return _host; }

int port() const { return _port >= 0 ? _port : cmdLine.port; }
int port() const { return _port >= 0 ? _port : CmdLine::DefaultDBPort; }

private:
// invariant (except full obj assignment):
Expand Down
2 changes: 1 addition & 1 deletion util/ramlog.h
Expand Up @@ -85,7 +85,7 @@ namespace mongo {
return html::green(line);
if( str::endsWith(s, " down\n") )
return html::yellow(line);
return html::blue(line);
return line; //html::blue(line);
}

return line;
Expand Down

0 comments on commit 80fbaf2

Please sign in to comment.