Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mongodb/mongo
Browse files Browse the repository at this point in the history
  • Loading branch information
erh committed Aug 9, 2010
2 parents a4dc528 + 45f777c commit dc1796d
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 5 deletions.
11 changes: 11 additions & 0 deletions db/repl/consensus.cpp
Expand Up @@ -83,6 +83,17 @@ namespace mongo {
return vUp * 2 > totalVotes();
}

bool Consensus::shouldRelinquish() const {
int vUp = rs._self->config().votes;
const long long T = rs.config().ho.heartbeatTimeoutMillis * rs.config().ho.heartbeatConnRetries;
for( Member *m = rs.head(); m; m=m->next() ) {
long long dt = m->hbinfo().timeDown();
if( dt < T )
vUp += m->config().votes;
}
return !( vUp * 2 > totalVotes() );
}

static const int VETO = -10000;

const time_t LeaseTime = 30;
Expand Down
2 changes: 1 addition & 1 deletion db/repl/health.h
Expand Up @@ -27,7 +27,7 @@ namespace mongo {
HealthOptions() {
heartbeatSleepMillis = 2000;
heartbeatTimeoutMillis = 10000;
heartbeatConnRetries = 3;
heartbeatConnRetries = 2;
}

bool isDefault() const { return *this == HealthOptions(); }
Expand Down
10 changes: 9 additions & 1 deletion db/repl/heartbeat.cpp
Expand Up @@ -40,6 +40,13 @@ namespace mongo {
// hacky
string *discoveredSeed = 0;

long long HeartbeatInfo::timeDown() const {
if( up() ) return 0;
if( downSince == 0 )
return 0; // still waiting on first heartbeat
return jsTime() - downSince;
}

/* { replSetHeartbeat : <setname> } */
class CmdReplSetHeartbeat : public ReplSetCommand {
public:
Expand Down Expand Up @@ -205,8 +212,9 @@ namespace mongo {
private:
void down(HeartbeatInfo& mem, string msg) {
mem.health = 0.0;
if( mem.upSince ) {
if( mem.upSince || mem.downSince == 0 ) {
mem.upSince = 0;
mem.downSince = jsTime();
log() << "replSet info " << h.toString() << " is now down (or slow to respond)" << rsLog;
}
mem.lastHeartbeatMsg = msg;
Expand Down
2 changes: 1 addition & 1 deletion db/repl/manager.cpp
Expand Up @@ -136,7 +136,7 @@ namespace mongo {
return;
}

if( !rs->elect.aMajoritySeemsToBeUp() ) {
if( rs->elect.shouldRelinquish() ) {
log() << "replSet can't see a majority of the set, relinquishing primary" << rsLog;
rs->relinquish();
}
Expand Down
1 change: 1 addition & 0 deletions db/repl/rs.h
Expand Up @@ -102,6 +102,7 @@ namespace mongo {

int totalVotes() const;
bool aMajoritySeemsToBeUp() const;
bool shouldRelinquish() const;
void electSelf();
void electCmdReceived(BSONObj, BSONObjBuilder*);
void multiCommand(BSONObj cmd, list<Target>& L);
Expand Down
6 changes: 5 additions & 1 deletion db/repl/rs_member.h
Expand Up @@ -61,25 +61,29 @@ namespace mongo {
class HeartbeatInfo {
unsigned _id;
public:
HeartbeatInfo() : _id(0xffffffff),hbstate(MemberState::RS_UNKNOWN),health(-1.0),skew(INT_MIN) { }
HeartbeatInfo() : _id(0xffffffff),hbstate(MemberState::RS_UNKNOWN),health(-1.0),downSince(0),skew(INT_MIN) { }
HeartbeatInfo(unsigned id);
bool up() const { return health > 0; }
unsigned id() const { return _id; }
MemberState hbstate;
double health;
time_t upSince;
long long downSince;
time_t lastHeartbeat;
string lastHeartbeatMsg;
OpTime opTime;
int skew;

long long timeDown() const; // ms

/* true if changed in a way of interest to the repl set manager. */
bool changed(const HeartbeatInfo& old) const;
};

inline HeartbeatInfo::HeartbeatInfo(unsigned id) : _id(id) {
hbstate = MemberState::RS_UNKNOWN;
health = -1.0;
downSince = 0;
lastHeartbeat = upSince = 0;
skew = INT_MIN;
}
Expand Down
2 changes: 1 addition & 1 deletion db/repl/rs_sync.cpp
Expand Up @@ -275,7 +275,7 @@ namespace mongo {
r.tailCheck();
if( !r.haveCursor() ) {
log() << "replSet TEMP end syncTail pass with " << hn << rsLog;
// TODO : reuse our cnonection to the primary.
// TODO : reuse our connection to the primary.
return;
}
if( box.getPrimary() != primary )
Expand Down

0 comments on commit dc1796d

Please sign in to comment.