Skip to content

Commit

Permalink
defensive
Browse files Browse the repository at this point in the history
  • Loading branch information
dwight committed Jul 17, 2011
1 parent 1ab3f66 commit bf0e20d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
6 changes: 5 additions & 1 deletion db/repl/rs_config.cpp
Expand Up @@ -440,7 +440,7 @@ namespace mongo {

for (set<MemberCfg *>::iterator cfg = (*sgs).second->m.begin();
!foundMe && cfg != (*sgs).second->m.end(); cfg++) {
(*cfg)->groups.insert((*sgs).second);
(*cfg)->groupsw(this).insert((*sgs).second);
}
}

Expand Down Expand Up @@ -575,6 +575,7 @@ namespace mongo {
}

ReplSetConfig::ReplSetConfig(BSONObj cfg, bool force) {
_constructed = false;
clear();
from(cfg);
if( force ) {
Expand All @@ -584,9 +585,11 @@ namespace mongo {
if( version < 1 )
version = 1;
_ok = true;
_constructed = true;
}

ReplSetConfig::ReplSetConfig(const HostAndPort& h) {
_constructed = false;
clear();
int level = 2;
DEV level = 0;
Expand Down Expand Up @@ -662,6 +665,7 @@ namespace mongo {
checkRsConfig();
_ok = true;
log(level) << "replSet load config ok from " << (h.isSelf() ? "self" : h.toString()) << rsLog;
_constructed = true;
}

}
17 changes: 13 additions & 4 deletions db/repl/rs_config.h
Expand Up @@ -21,6 +21,7 @@
#pragma once

#include "../../util/net/hostandport.h"
#include "../../util/concurrency/race.h"
#include "health.h"

namespace mongo {
Expand All @@ -29,7 +30,6 @@ namespace mongo {

class ReplSetConfig {
enum { EMPTYCONFIG = -2 };
private:
struct TagSubgroup;
public:
/**
Expand Down Expand Up @@ -62,13 +62,21 @@ namespace mongo {
bool hidden; /* if set, don't advertise to drives in isMaster. for non-primaries (priority 0) */
bool buildIndexes; /* if false, do not create any non-_id indexes */
set<string> tags; /* tagging for data center, rack, etc. */
set<TagSubgroup*> groups; // the subgroups this member belongs to

private:
set<TagSubgroup*> _groups; // the subgroups this member belongs to
public:
const set<TagSubgroup*>& groups() const {
return _groups;
}
set<TagSubgroup*>& groupsw(ReplSetConfig *c) {
assert(!c->_constructed);
return _groups;
}
void check() const; /* check validity, assert if not. */
BSONObj asBson() const;
bool potentiallyHot() const { return !arbiterOnly && priority > 0; }
void updateGroups(const OpTime& last) {
for (set<TagSubgroup*>::iterator it = groups.begin(); it != groups.end(); it++) {
for (set<TagSubgroup*>::iterator it = groups().begin(); it != groups().end(); it++) {
((TagSubgroup*)(*it))->updateLast(last);
}
}
Expand Down Expand Up @@ -107,6 +115,7 @@ namespace mongo {

BSONObj asBson() const;

bool _constructed;
private:
bool _ok;
void from(BSONObj);
Expand Down
32 changes: 32 additions & 0 deletions util/concurrency/race.h
Expand Up @@ -21,6 +21,38 @@ namespace mongo {

#if defined(_DEBUG)

namespace race {

class CodePoint {
public:
string lastName;
unsigned lastTid;
string file;
CodePoint(string f) : lastTid(0), file(f) { }
};
class Check {
public:
Check(CodePoint& p) {
unsigned t = GetCurrentThreadId();
if( p.lastTid == 0 ) {
p.lastTid = t;
p.lastName = getThreadName();
}
else if( t != p.lastTid ) {
log() << "\n\n\n\n\nRACE? error assert\n " << p.file << '\n'
<< " " << p.lastName
<< " " << getThreadName() << "\n\n" << endl;
mongoAbort("racecheck");
}
};
};

#define RACECHECK \
static race::CodePoint __cp(__FILE__); \
race::Check __ck(__cp);

}

class CodeBlock {
volatile int n;
unsigned tid;
Expand Down

0 comments on commit bf0e20d

Please sign in to comment.