mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 01:21:03 +01:00
sr
This commit is contained in:
parent
08f3c69688
commit
2f2f486639
@ -56,9 +56,9 @@ namespace mongo {
|
||||
|
||||
private:
|
||||
void down() {
|
||||
m->health = 0.0;
|
||||
if( m->upSince ) {
|
||||
m->upSince = 0;
|
||||
m->_health = 0.0;
|
||||
if( m->_upSince ) {
|
||||
m->_upSince = 0;
|
||||
log() << "replSet " << m->fullName() << " is now down" << endl;
|
||||
}
|
||||
}
|
||||
@ -77,23 +77,23 @@ namespace mongo {
|
||||
try {
|
||||
BSONObj info;
|
||||
bool ok = conn.runCommand("admin", cmd, info);
|
||||
m->lastHeartbeat = time(0);
|
||||
m->_lastHeartbeat = time(0);
|
||||
if( ok ) {
|
||||
if( m->upSince == 0 ) {
|
||||
if( m->_upSince == 0 ) {
|
||||
log() << "replSet " << m->fullName() << " is now up" << endl;
|
||||
m->upSince = m->lastHeartbeat;
|
||||
m->_upSince = m->_lastHeartbeat;
|
||||
}
|
||||
m->health = 1.0;
|
||||
m->lastHeartbeatErrMsg.set("");
|
||||
m->_health = 1.0;
|
||||
m->_lastHeartbeatErrMsg.set("");
|
||||
}
|
||||
else {
|
||||
down();
|
||||
m->lastHeartbeatErrMsg.set(info.getStringField("errmsg"));
|
||||
m->_lastHeartbeatErrMsg.set(info.getStringField("errmsg"));
|
||||
}
|
||||
}
|
||||
catch(...) {
|
||||
down();
|
||||
m->lastHeartbeatErrMsg.set("connect/transport error");
|
||||
m->_lastHeartbeatErrMsg.set("connect/transport error");
|
||||
}
|
||||
sleepsecs(2);
|
||||
}
|
||||
@ -113,10 +113,10 @@ namespace mongo {
|
||||
while( m ) {
|
||||
BSONObjBuilder bb;
|
||||
bb.append("name", m->fullName());
|
||||
bb.append("health", m->health);
|
||||
bb.append("uptime", (unsigned) (m->upSince ? (time(0)-m->upSince) : 0));
|
||||
bb.appendDate("lastHeartbeat", m->lastHeartbeat);
|
||||
bb.append("errmsg", m->lastHeartbeatErrMsg.get());
|
||||
bb.append("health", m->health());
|
||||
bb.append("uptime", (unsigned) (m->upSince() ? (time(0)-m->upSince()) : 0));
|
||||
bb.appendDate("lastHeartbeat", m->lastHeartbeat());
|
||||
bb.append("errmsg", m->_lastHeartbeatErrMsg.get());
|
||||
v.push_back(bb.obj());
|
||||
m = m->next();
|
||||
}
|
||||
|
@ -69,27 +69,32 @@ namespace mongo {
|
||||
// void addMemberIfMissing(const HostAndPort& p);
|
||||
|
||||
struct MemberInfo : public List1<MemberInfo>::Base {
|
||||
MemberInfo(string h, int p) : port(p), host(h) {
|
||||
dead = false;
|
||||
lastHeartbeat = 0;
|
||||
upSince = 0;
|
||||
health = -1.0;
|
||||
MemberInfo(string h, int p) : _port(p), _host(h) {
|
||||
_dead = false;
|
||||
_lastHeartbeat = 0;
|
||||
_upSince = 0;
|
||||
_health = -1.0;
|
||||
}
|
||||
|
||||
bool dead;
|
||||
const int port;
|
||||
const string host;
|
||||
double health;
|
||||
time_t lastHeartbeat;
|
||||
time_t upSince;
|
||||
DiagStr lastHeartbeatErrMsg;
|
||||
|
||||
string fullName() {
|
||||
if( port < 0 ) return host;
|
||||
string fullName() const {
|
||||
if( _port < 0 ) return _host;
|
||||
stringstream ss;
|
||||
ss << host << ':' << port;
|
||||
ss << _host << ':' << _port;
|
||||
return ss.str();
|
||||
}
|
||||
double health() const { return _health; }
|
||||
time_t upSince() const { return _upSince; }
|
||||
time_t lastHeartbeat() const { return _lastHeartbeat; }
|
||||
private:
|
||||
friend class FeedbackThread; // feedbackthread is the primary writer to these objects
|
||||
|
||||
bool _dead;
|
||||
const int _port;
|
||||
const string _host;
|
||||
double _health;
|
||||
time_t _lastHeartbeat;
|
||||
time_t _upSince;
|
||||
public:
|
||||
DiagStr _lastHeartbeatErrMsg;
|
||||
};
|
||||
/* all members of the set EXCEPT SELF. */
|
||||
List1<MemberInfo> _members;
|
||||
|
Loading…
Reference in New Issue
Block a user