Permalink
Browse files

rs towards slaveDelay 162

  • Loading branch information...
dwight committed Aug 18, 2010
1 parent 7841b07 commit bc9997faef19bdcb145365ce34bdf7aeaa4b37d8
Showing with 18 additions and 4 deletions.
  1. +1 −1 bson/bsonelement.h
  2. +1 −0 db/repl/consensus.cpp
  3. +7 −1 db/repl/rs.cpp
  4. +4 −0 db/repl/rs_config.cpp
  5. +5 −2 db/repl/rs_config.h
View
@@ -511,7 +511,7 @@ class BSONElement {
}
}
- /** Retrieve int value for the element safely. Zero returned if not a number. */
+ /** Retrieve int value for the element safely. Zero returned if not a number. Converted to int if another numeric type. */
inline int BSONElement::numberInt() const {
switch( type() ) {
case NumberDouble:
View
@@ -333,6 +333,7 @@ namespace mongo {
void Consensus::electSelf() {
assert( !rs.lockedByMe() );
assert( !rs.myConfig().arbiterOnly );
+ assert( rs.myConfig().slaveDelay == 0 );
try {
_electSelf();
}
View
@@ -113,7 +113,11 @@ namespace mongo {
hosts.push_back(m->h().toString());
}
else if( !m->config().arbiterOnly ) {
- passives.push_back(m->h().toString());
+ if( m->config().slaveDelay ) {
+ /* hmmm - we don't list these as they are stale. */
+ } else {
+ passives.push_back(m->h().toString());
+ }
}
else {
arbiters.push_back(m->h().toString());
@@ -151,6 +155,8 @@ namespace mongo {
}
if( myConfig().arbiterOnly )
b.append("arbiterOnly", true);
+ if( myConfig().slaveDelay )
+ b.append("slaveDelay", myConfig().slaveDelay);
}
/** @param cfgString <setname>/<seedhost1>,<seedhost2> */
View
@@ -81,6 +81,7 @@ namespace mongo {
if( votes != 1 ) b << "votes" << votes;
if( priority != 1.0 ) b << "priority" << priority;
if( arbiterOnly ) b << "arbiterOnly" << true;
+ if( slaveDelay ) b << "arbiterOnly" << slaveDelay;
return b.obj();
}
@@ -115,6 +116,8 @@ namespace mongo {
mchk(priority >= 0 && priority <= 1000);
mchk(votes >= 0 && votes <= 100);
uassert(13419, "this version of mongod only supports priorities 0 and 1", priority == 0 || priority == 1);
+ uassert(13437, "slaveDelay requires priority be zero", slaveDelay == 0 || priority == 0);
+ uassert(13438, "bad slaveDelay value", slaveDelay >= 0 && slaveDelay <= 3600 * 24 * 366);
}
/** @param o old config
@@ -243,6 +246,7 @@ namespace mongo {
if( m.h.isLocalHost() )
localhosts++;
m.arbiterOnly = mobj.getBoolField("arbiterOnly");
+ m.slaveDelay = mobj["slaveDelay"].numberInt();
if( mobj.hasElement("priority") )
m.priority = mobj["priority"].Number();
if( mobj.hasElement("votes") )
View
@@ -41,22 +41,25 @@ namespace mongo {
bool ok() const { return _ok; }
struct MemberCfg {
- MemberCfg() : _id(-1), votes(1), priority(1.0), arbiterOnly(false) { }
+ MemberCfg() : _id(-1), votes(1), priority(1.0), arbiterOnly(false), slaveDelay(0) { }
int _id; /* ordinal */
unsigned votes; /* how many votes this node gets. default 1. */
HostAndPort h;
double priority; /* 0 means can never be primary */
bool arbiterOnly;
+ int slaveDelay; /* seconds. int rather than unsigned for convenient to/front bson conversion. */
+
void check() const; /* check validity, assert if not. */
BSONObj asBson() const;
bool potentiallyHot() const {
return !arbiterOnly && priority > 0;
}
bool operator==(const MemberCfg& r) const {
- return _id==r._id && votes == r.votes && h == r.h && priority == r.priority && arbiterOnly == r.arbiterOnly;
+ return _id==r._id && votes == r.votes && h == r.h && priority == r.priority && arbiterOnly == r.arbiterOnly && slaveDelay == r.slaveDelay;
}
bool operator!=(const MemberCfg& r) const { return !(*this == r); }
};
+
vector<MemberCfg> members;
string _id;
int version;

0 comments on commit bc9997f

Please sign in to comment.