Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:mongodb/mongo
Browse files Browse the repository at this point in the history
  • Loading branch information
dwight authored and dwight committed Apr 28, 2011
2 parents 87ab46c + ef042e4 commit eb964f1
Show file tree
Hide file tree
Showing 38 changed files with 225 additions and 81 deletions.
2 changes: 1 addition & 1 deletion buildscripts/smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def start(self):
utils.ensureDir(dir_name)
argv = [mongod_executable, "--port", str(self.port), "--dbpath", dir_name]
if self.kwargs.get('small_oplog'):
argv += ["--master", "--oplogSize", "128"]
argv += ["--master", "--oplogSize", "256"]
if self.slave:
argv += ['--slave', '--source', 'localhost:' + str(srcport)]
print "running " + " ".join(argv)
Expand Down
2 changes: 1 addition & 1 deletion client/dbclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ namespace mongo {
*/
bool isFailed() const { return _failed; }

MessagingPort& port() { return *p; }
MessagingPort& port() { assert(p); return *p; }

string toStringLong() const {
stringstream ss;
Expand Down
40 changes: 20 additions & 20 deletions client/dbclient_rs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace mongo {


ReplicaSetMonitor::ReplicaSetMonitor( const string& name , const vector<HostAndPort>& servers )
: _lock( "ReplicaSetMonitor instance" ) , _checkConnectionLock( "ReplicaSetMonitor check connection lock" ), _name( name ) , _master(-1) {
: _lock( "ReplicaSetMonitor instance" ) , _checkConnectionLock( "ReplicaSetMonitor check connection lock" ), _name( name ) , _master(-1), _nextSlave(0) {

uassert( 13642 , "need at least 1 node for a replica set" , servers.size() > 0 );

Expand Down Expand Up @@ -221,19 +221,19 @@ namespace mongo {
}

HostAndPort ReplicaSetMonitor::getSlave() {
int x = rand() % _nodes.size();

{
scoped_lock lk( _lock );
for ( unsigned i=0; i<_nodes.size(); i++ ) {
int p = ( i + x ) % _nodes.size();
if ( p == _master )
_nextSlave = ( _nextSlave + 1 ) % _nodes.size();
if ( _nextSlave == _master )
continue;
if ( _nodes[p].ok )
return _nodes[p].addr;
if ( _nodes[ _nextSlave ].ok )
return _nodes[ _nextSlave ].addr;
}
}

return _nodes[0].addr;
return _nodes[ 0 ].addr;
}

/**
Expand Down Expand Up @@ -309,7 +309,7 @@ namespace mongo {
BSONObj o;
c->isMaster(isMaster, &o);

log( ! verbose ) << "ReplicaSetMonitor::_checkConnection: " << c->toString() << ' ' << o << '\n';
log( ! verbose ) << "ReplicaSetMonitor::_checkConnection: " << c->toString() << ' ' << o << endl;

// add other nodes
string maybePrimary;
Expand Down Expand Up @@ -530,12 +530,12 @@ namespace mongo {
// we're ok sending to a slave
// we'll try 2 slaves before just using master
// checkSlave will try a different slave automatically after a failure
for ( int i=0; i<2; i++ ) {
for ( int i=0; i<3; i++ ) {
try {
return checkSlave()->query(ns,query,nToReturn,nToSkip,fieldsToReturn,queryOptions,batchSize);
}
catch ( DBException & ) {
LOG(1) << "can't query replica set slave: " << _slaveHost << endl;
catch ( DBException &e ) {
LOG(1) << "can't query replica set slave " << i << " : " << _slaveHost << causedBy( e ) << endl;
}
}
}
Expand All @@ -548,12 +548,12 @@ namespace mongo {
// we're ok sending to a slave
// we'll try 2 slaves before just using master
// checkSlave will try a different slave automatically after a failure
for ( int i=0; i<2; i++ ) {
for ( int i=0; i<3; i++ ) {
try {
return checkSlave()->findOne(ns,query,fieldsToReturn,queryOptions);
}
catch ( DBException & ) {
LOG(1) << "can't query replica set slave: " << _slaveHost << endl;
catch ( DBException &e ) {
LOG(1) << "can't findone replica set slave " << i << " : " << _slaveHost << causedBy( e ) << endl;
}
}
}
Expand Down Expand Up @@ -581,12 +581,12 @@ namespace mongo {
DbMessage dm( toSend );
QueryMessage qm( dm );
if ( qm.queryOptions & QueryOption_SlaveOk ) {
for ( int i=0; i<2; i++ ) {
for ( int i=0; i<3; i++ ) {
try {
return checkSlave()->callLazy( toSend );
}
catch ( DBException & ) {
log(1) << "can't query replica set slave: " << _slaveHost << endl;
catch ( DBException &e ) {
LOG(1) << "can't callLazy replica set slave " << i << " : " << _slaveHost << causedBy( e ) << endl;
}
}
}
Expand All @@ -601,15 +601,15 @@ namespace mongo {
DbMessage dm( toSend );
QueryMessage qm( dm );
if ( qm.queryOptions & QueryOption_SlaveOk ) {
for ( int i=0; i<2; i++ ) {
for ( int i=0; i<3; i++ ) {
try {
DBClientConnection* s = checkSlave();
if ( actualServer )
*actualServer = s->getServerAddress();
return s->call( toSend , response , assertOk );
}
catch ( DBException & ) {
log(1) << "can't query replica set slave: " << _slaveHost << endl;
catch ( DBException &e ) {
LOG(1) << "can't call replica set slave " << i << " : " << _slaveHost << causedBy( e ) << endl;
if ( actualServer )
*actualServer = "";
}
Expand Down
2 changes: 1 addition & 1 deletion client/dbclient_rs.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ namespace mongo {
vector<Node> _nodes;

int _master; // which node is the current master. -1 means no master is known

int _nextSlave; // which node is the current slave

static mongo::mutex _setsLock; // protects _sets
static map<string,ReplicaSetMonitorPtr> _sets; // set name to Monitor
Expand Down
29 changes: 29 additions & 0 deletions client/examples/clientTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,5 +246,34 @@ int main( int argc, const char **argv ) {
//MONGO_PRINT(out);
}

{
// test timeouts

DBClientConnection conn( true , 0 , 2 );
if ( ! conn.connect( string( "127.0.0.1:" ) + port , errmsg ) ) {
cout << "couldn't connect : " << errmsg << endl;
throw -11;
}
conn.insert( "test.totest" , BSON( "x" << 1 ) );
BSONObj res;

bool gotError = false;
assert( conn.eval( "test" , "return db.totest.findOne().x" , res ) );
try {
conn.eval( "test" , "sleep(5000); return db.totest.findOne().x" , res );
}
catch ( std::exception& e ) {
gotError = true;
log() << e.what() << endl;
}
assert( gotError );
// sleep so the server isn't locked anymore
sleepsecs( 4 );

assert( conn.eval( "test" , "return db.totest.findOne().x" , res ) );


}

cout << "client test finished!" << endl;
}
5 changes: 5 additions & 0 deletions db/db.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,10 @@
<ClCompile Include="mongommf.cpp" />
<ClCompile Include="oplog.cpp" />
<ClCompile Include="projection.cpp" />
<ClCompile Include="querypattern.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="repl.cpp" />
<ClCompile Include="repl\consensus.cpp" />
<ClCompile Include="repl\heartbeat.cpp" />
Expand Down Expand Up @@ -658,6 +662,7 @@
<ClInclude Include="namespace-inl.h" />
<ClInclude Include="oplogreader.h" />
<ClInclude Include="projection.h" />
<ClInclude Include="queryutil.h" />
<ClInclude Include="repl.h" />
<ClInclude Include="replpair.h" />
<ClInclude Include="repl\connections.h" />
Expand Down
2 changes: 2 additions & 0 deletions db/db.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
<ClCompile Include="repl\rs_config.cpp" />
<ClCompile Include="security_key.cpp" />
<ClCompile Include="..\util\file_allocator.cpp" />
<ClCompile Include="querypattern.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\client\dbclientcursor.h" />
Expand Down Expand Up @@ -293,6 +294,7 @@
<ClInclude Include="dur_journalimpl.h" />
<ClInclude Include="..\util\concurrency\race.h" />
<ClInclude Include="..\util\alignedbuilder.h" />
<ClInclude Include="queryutil.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="db.rc" />
Expand Down
7 changes: 6 additions & 1 deletion db/dur_journal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ namespace mongo {
if something highly surprising, throws to abort
*/
unsigned long long LSNFile::get() {
uassert(13614, "unexpected version number of lsn file in journal/ directory", ver == 0);
uassert(13614, str::stream() << "unexpected version number of lsn file in journal/ directory got: " << ver , ver == 0);
if( ~lsn != checkbytes ) {
log() << "lsnfile not valid. recovery will be from log start. lsn: " << hex << lsn << " checkbytes: " << hex << checkbytes << endl;
return 0;
Expand Down Expand Up @@ -486,6 +486,11 @@ namespace mongo {
File f;
f.open(lsnPath().string().c_str());
assert(f.is_open());
if( f.len() == 0 ) {
// this could be 'normal' if we crashed at the right moment
log() << "info lsn file is zero bytes long" << endl;
return 0;
}
f.read(0,(char*)&L, sizeof(L));
unsigned long long lsn = L.get();
return lsn;
Expand Down
4 changes: 2 additions & 2 deletions db/queryutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ namespace mongo {
FieldRangeSet _singleKey;
FieldRangeSet _multiKey;
friend class FieldRangeOrSet;
friend class QueryUtilIndexed;
friend struct QueryUtilIndexed;
};

class IndexSpec;
Expand Down Expand Up @@ -407,7 +407,7 @@ namespace mongo {
// ensure memory is owned
list<FieldRangeSetPair> _oldOrSets;
bool _orFound;
friend class QueryUtilIndexed;
friend struct QueryUtilIndexed;
};

/** returns a string that when used as a matcher, would match a super set of regex()
Expand Down
10 changes: 10 additions & 0 deletions db/repl/rs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,14 @@ namespace mongo {
forgetPrimary();

setSelfTo(0);

// For logging
string members = "";

for( vector<ReplSetConfig::MemberCfg>::iterator i = _cfg->members.begin(); i != _cfg->members.end(); i++ ) {
const ReplSetConfig::MemberCfg& m = *i;
Member *mi;
members += ( members == "" ? "" : ", " ) + m.h.toString();
if( m.h.isSelf() ) {
assert( _self == 0 );
mi = new Member(m.h, m._id, &m, true);
Expand All @@ -484,6 +489,11 @@ namespace mongo {
box.setOtherPrimary(mi);
}
}

if( ! _self ){
log() << "replSet warning did not detect own host in full reconfig, members " << members << " config: " << c << rsLog;
}

return true;
}

Expand Down
3 changes: 2 additions & 1 deletion db/repl/rs.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ namespace mongo {
void loadConfig();

list<HostAndPort> memberHostnames() const;
const ReplSetConfig::MemberCfg& myConfig() const { return _self->config(); }
const ReplSetConfig::MemberCfg& myConfig() const { assert( _self ); return _self->config(); }
bool iAmArbiterOnly() const { return myConfig().arbiterOnly; }
bool iAmPotentiallyHot() const { return myConfig().potentiallyHot() && elect.steppedDown <= time(0); }
protected:
Expand Down Expand Up @@ -505,6 +505,7 @@ namespace mongo {

inline Member::Member(HostAndPort h, unsigned ord, const ReplSetConfig::MemberCfg *c, bool self) :
_config(*c), _h(h), _hbinfo(ord) {
assert(c);
if( self )
_hbinfo.health = 1.0;
}
Expand Down
2 changes: 1 addition & 1 deletion db/repl/rs_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace mongo {

cx.db()->flushFiles(true);
}
DEV log() << "replSet saveConfigLocally done" << rsLog;
log() << "replSet saveConfigLocally done" << rsLog;
}

bo ReplSetConfig::MemberCfg::asBson() const {
Expand Down
21 changes: 15 additions & 6 deletions db/repl/rs_sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace mongo {
if ( *ns == '.' || *ns == 0 ) {
if( *o.getStringField("op") == 'n' )
return;
log() << "replSet skipping bad op in oplog: " << o.toString() << endl;
log() << "replSet skipping bad op in oplog: " << o.toString() << rsLog;
return;
}

Expand Down Expand Up @@ -141,7 +141,7 @@ namespace mongo {
time_t now = time(0);
if (now - start > 10) {
// simple progress metering
log() << "initialSyncOplogApplication applied " << n << " operations, synced to "
log() << "replSet initialSyncOplogApplication applied " << n << " operations, synced to "
<< ts.toStringPretty() << rsLog;
start = now;
}
Expand Down Expand Up @@ -322,8 +322,8 @@ namespace mongo {
OpTime ts = o["ts"]._opTime();
long long h = o["h"].numberLong();
if( ts != lastOpTimeWritten || h != lastH ) {
log() << "replSet our last op time written: " << lastOpTimeWritten.toStringPretty() << endl;
log() << "replset source's GTE: " << ts.toStringPretty() << endl;
log() << "replSet our last op time written: " << lastOpTimeWritten.toStringPretty() << rsLog;
log() << "replset source's GTE: " << ts.toStringPretty() << rsLog;
syncRollback(r);
return;
}
Expand Down Expand Up @@ -467,8 +467,13 @@ namespace mongo {
*/

while( 1 ) {
if( myConfig().arbiterOnly )
// After a reconfig, we may not be in the replica set anymore, so
// check that we are in the set (and not an arbiter) before
// trying to sync with other replicas.
if( ! _self || myConfig().arbiterOnly ){
if( ! _self ) log() << "replSet warning did not detect own host and port, not syncing, config: " << theReplSet->config() << rsLog;
return;
}

try {
_syncThread();
Expand All @@ -488,7 +493,11 @@ namespace mongo {
are no heartbeat threads, so we do it here to be sure. this is relevant if the singleton
member has done a stepDown() and needs to come back up.
*/
OCCASIONALLY mgr->send( boost::bind(&Manager::msgCheckNewState, theReplSet->mgr) );
OCCASIONALLY {
log() << "replSet default heartbeat starting..." << rsLog;
mgr->send( boost::bind(&Manager::msgCheckNewState, theReplSet->mgr) );
log() << "replSet heartbeat finished" << rsLog;
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions dbtests/test.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@
<ClCompile Include="..\db\geo\haystack.cpp" />
<ClCompile Include="..\db\mongommf.cpp" />
<ClCompile Include="..\db\projection.cpp" />
<ClCompile Include="..\db\querypattern.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="..\db\repl\consensus.cpp" />
<ClCompile Include="..\db\repl\heartbeat.cpp" />
<ClCompile Include="..\db\repl\manager.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions dbtests/test.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,9 @@
<ClCompile Include="..\db\dbcommands_admin.cpp">
<Filter>db\cpp</Filter>
</ClCompile>
<ClCompile Include="..\db\querypattern.cpp">
<Filter>db</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="..\SConstruct">
Expand Down
5 changes: 5 additions & 0 deletions jstests/check_shard_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ assert.eq( 3 , f.count() , "2. count after initial insert should be 3" );
res = db.runCommand( { checkShardingIndex: "test.jstests_shardingindex" , keyPattern: {x:1, y:1} , force: true });
assert.eq( false , res.ok , "2b " + tojson(res) );

//
res = db.runCommand( { checkShardingIndex: "test.jstests_shardingindex" , keyPattern: {_id:1} , force: true });
assert.eq( true , res.ok , "3a " + tojson(res) );
assert( res.idskip , "3b " + tojson(res) )

print("PASSED");
1 change: 1 addition & 0 deletions jstests/delx.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ x.next();
y.next();

a.foo.remove( { _id : { $gt : 50 } } );
db.getLastError();

assert.eq( 51 , a.foo.find().itcount() , "B1" )
assert.eq( 100 , b.foo.find().itcount() , "B2" )
Expand Down
Loading

0 comments on commit eb964f1

Please sign in to comment.