mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
rs
This commit is contained in:
parent
c5d40feed1
commit
7c1dcb6c1a
@ -39,6 +39,21 @@ namespace mongo {
|
||||
|
||||
static const int VETO = -10000;
|
||||
|
||||
class VoteException : public std::exception {
|
||||
};
|
||||
|
||||
const time_t LeaseTime = 30;
|
||||
|
||||
void ReplSet::Consensus::yea(unsigned memberId) {
|
||||
Atomic<LastYea>::tran t(ly);
|
||||
LastYea &ly = t.ref();
|
||||
time_t now = time(0);
|
||||
if( ly.when + LeaseTime >= now )
|
||||
throw VoteException();
|
||||
ly.when = now;
|
||||
ly.who = memberId;
|
||||
}
|
||||
|
||||
void ReplSet::Consensus::_electSelf() {
|
||||
ReplSet::Member& me = *rs._self;
|
||||
BSONObj electCmd = BSON(
|
||||
|
@ -84,6 +84,13 @@ namespace mongo {
|
||||
|
||||
class Consensus {
|
||||
ReplSet &rs;
|
||||
struct LastYea {
|
||||
LastYea() : when(0), who(0xffffffff) { }
|
||||
time_t when;
|
||||
unsigned who;
|
||||
};
|
||||
Atomic<LastYea> ly;
|
||||
void yea(unsigned memberId);
|
||||
void _electSelf();
|
||||
public:
|
||||
Consensus(ReplSet *t) : rs(*t) { }
|
||||
|
@ -66,8 +66,8 @@ namespace mongo {
|
||||
class tran : private scoped_lock {
|
||||
Atomic<T>& _a;
|
||||
public:
|
||||
tran(Atomic<T>& a) : scoped_lock(_atomicMutex) { }
|
||||
T& ref() { return _a; }
|
||||
tran(Atomic<T>& a) : scoped_lock(_atomicMutex), _a(a) { }
|
||||
T& ref() { return _a.val; }
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user