0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

rs cleaning

This commit is contained in:
Dwight Merriman 2010-05-06 21:50:52 -04:00
parent 2ffc37dce5
commit d9bdbeef93
5 changed files with 40 additions and 31 deletions

View File

@ -36,7 +36,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shell", "shell", "{407B4B88
..\shell\utils.h = ..\shell\utils.h
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "other source files", "other source files", "{12B11474-2D74-48C3-BB3D-F03249BEA88F}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "other files", "other files", "{12B11474-2D74-48C3-BB3D-F03249BEA88F}"
ProjectSection(SolutionItems) = preProject
..\SConstruct = ..\SConstruct
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mongod", "db.vcxproj", "{215B2D68-0A70-4D10-8E75-B31010C62A91}"
EndProject

View File

@ -21,39 +21,41 @@
namespace mongo {
class E : public BackgroundJob {
void run() {
log() << "not done" << endl;
}
public:
ReplSet::Member *_m;
};
bool ReplSet::aMajoritySeemsToBeUp() const {
Member *m = head();
unsigned vTot = 0;
unsigned vUp = 0;
do {
bool ReplSet::Consensus::aMajoritySeemsToBeUp() const {
Member *m =rs.head();
unsigned vTot = 0, vUp = 0;
for( Member *m = rs.head(); m; m=m->next() ) {
vTot += m->config().votes;
if( m->up() )
vTot += m->config().votes;
m = m->next();
} while( m );
vUp += m->up() ? m->config().votes : 0;
}
return vUp * 2 > vTot;
}
typedef shared_ptr<E> eptr;
void ReplSet::electSelf() {
list<BackgroundJob*> _jobs;
void ReplSet::Consensus::electSelf() {
class E : public BackgroundJob {
void run() {
log() << "not done" << endl;
try {
ScopedConn c(m->fullName());
//c.runCommand(
}
catch(DBException&) {
}
}
public:
ReplSet::Member *m;
};
typedef shared_ptr<E> eptr;
list<eptr> jobs;
for( Member *m = head(); m; m=m->next() ) {
eptr e( new E() );
e->_m = m;
jobs.push_back(e);
_jobs.push_back(e.get());
list<BackgroundJob*> _jobs;
for( Member *m = rs.head(); m; m=m->next() ) if( m->up() ) {
E *e = new E();
e->m = m;
jobs.push_back(eptr(e)); _jobs.push_back(e);
e->go();
}
BackgroundJob::wait(_jobs);
BackgroundJob::wait(_jobs,5);
}
}

View File

@ -143,7 +143,7 @@ namespace mongo {
void ReplSet::summarizeAsHtml(stringstream& s) const {
s << table(0, false);
s << tr("Set name:", _name);
s << tr("Majority up:", aMajoritySeemsToBeUp()?"yes":"no" );
s << tr("Majority up:", elect.aMajoritySeemsToBeUp()?"yes":"no" );
s << _table();
const char *h[] = {"Member", "Up", "Uptime",

View File

@ -37,7 +37,7 @@ namespace mongo {
}
*/
/** @param cfgString <setname>/<seedhost1>,<seedhost2> */
ReplSet::ReplSet(string cfgString) : fatal(false), _self(0) {
ReplSet::ReplSet(string cfgString) : fatal(false), _self(0), elect(this) {
const char *p = cfgString.c_str();
const char *slash = strchr(p, '/');

View File

@ -76,8 +76,12 @@ namespace mongo {
void finishLoadingConfig(vector<ReplSetConfig>& v);
void setFrom(ReplSetConfig& c);
bool aMajoritySeemsToBeUp() const;
void electSelf();
struct Consensus {
ReplSet &rs;
Consensus(ReplSet *t) : rs(*t) { }
bool aMajoritySeemsToBeUp() const;
void electSelf();
} elect;
public:
struct Member : public List1<Member>::Base {