Permalink
Browse files

Merge branch 'master' of github.com:mongodb/mongo

  • Loading branch information...
2 parents ceda65c + e07b71d commit 5bfecc88d0ac9cc1da5e59f0cae6a8e112385efd @erh erh committed Jul 30, 2010
Showing with 1,852 additions and 1,788 deletions.
  1. +5 −1 client/dbclientcursor.cpp
  2. +2 −1 db/repl/rs.h
  3. +23 −4 db/repl/rs_sync.cpp
  4. +52 −12 jstests/replsets/replset2.js
  5. +3 −3 jstests/replsets/replset_remove_node.js
  6. +1,764 −1,764 shell/mongo_vstudio.cpp
  7. +3 −3 shell/servers.js
@@ -151,15 +151,19 @@ namespace mongo {
}
BSONObj DBClientCursor::next() {
- DEV assert( more() );
+ DEV _assertIfNull();
if ( !_putBack.empty() ) {
BSONObj ret = _putBack.top();
_putBack.pop();
return ret;
}
+
+ uassert(13422, "DBClientCursor next() called but more() is false", pos < nReturned);
+
pos++;
BSONObj o(data);
data += o.objsize();
+ /* todo would be good to make data null at end of batch for safety */
return o;
}
View
@@ -268,7 +268,8 @@ namespace mongo {
_hbmsg[sz] = 0;
memcpy(_hbmsg, s.c_str(), sz);
}
- log(logLevel) << "replSet " << s << rsLog;
+ if( !s.empty() )
+ log(logLevel) << "replSet " << s << rsLog;
}
protected:
bool initFromConfig(ReplSetConfig& c); // true if ok; throws if config really bad; false if config doesn't include self
View
@@ -81,6 +81,15 @@ namespace mongo {
assert( r.awaitCapable() );
{
+ if( !r.more() ) {
+ log() << "replSet syncTail error querying oplog >= " << lastOpTimeWritten.toString() << " from " << hn << rsLog;
+ try {
+ log() << "replSet " << hn << " last op: " << r.getLastOp(rsoplog).toString() << rsLog;
+ }
+ catch(...) { }
+ sleepsecs(1);
+ return;
+ }
BSONObj o = r.nextSafe();
OpTime ts = o["ts"]._opTime();
long long h = o["h"].numberLong();
@@ -95,8 +104,6 @@ namespace mongo {
}
}
- // TODO : switch state to secondary here when appropriate...
-
while( 1 ) {
while( 1 ) {
if( !r.moreInCurrentBatch() ) {
@@ -138,6 +145,16 @@ namespace mongo {
BSONObj o = r.nextSafe(); /* note we might get "not master" at some point */
{
writelock lk("");
+
+ /* if we have become primary, we dont' want to apply things from elsewhere
+ anymore. assumePrimary is in the db lock so we are safe as long as
+ we check after we locked above. */
+ if( box.getPrimary() != primary ) {
+ if( box.getState().primary() )
+ log(0) << "replSet stopping syncTail we are now primary" << rsLog;
+ return;
+ }
+
syncApply(o);
_logOpObjRS(o); /* with repl sets we write the ops to our oplog too: */
}
@@ -157,8 +174,10 @@ namespace mongo {
void ReplSetImpl::_syncThread() {
StateBox::SP sp = box.get();
- if( sp.state.primary() )
+ if( sp.state.primary() ) {
+ sleepsecs(1);
return;
+ }
/* later, we can sync from up secondaries if we want. tbd. */
if( sp.primary == 0 )
@@ -190,7 +209,7 @@ namespace mongo {
// TODO : SET NOT SECONDARY here.
sleepsecs(60);
}
- sleepsecs(2);
+ sleepsecs(1);
}
}
@@ -1,6 +1,9 @@
doTest = function( signal ) {
+ // FAILING TEST
+ // See below:
+
// Test replication with getLastError
// Replica set testing API
@@ -20,21 +23,58 @@ doTest = function( signal ) {
var master = replTest.getMaster();
// Wait for replication to a single node
- master.getDB("foo").bar.insert({n: 1});
- var result = master.getDB("foo").runCommand({getlasterror: {w: 1, wtimeout: 20000}});
- assert( result['ok'] == 1, "getLastError with w=1 failed");
+ master.getDB("test").bar.insert({n: 1});
+
+ // Wait for initial sync
+ replTest.awaitReplication();
+
+ var slaves = replTest.liveNodes.slaves;
+ slaves.forEach(function(slave) { slave.setSlaveOk(); });
+
+ var testDB = "repl-test";
+
+ var callGetLastError = function(w, timeout, db) {
+ var result = master.getDB(db).runCommand({getlasterror: 1, w: w, wtimeout: timeout});
+ printjson( result );
+ assert( result['ok'] == 1, "getLastError with w=" + w + " failed");
+ }
+
+
+ // Test getlasterror with a simple insert
+ // TEST FAILS HERE
+ master.getDB(testDB).foo.insert({n: 1});
+ callGetLastError(3, 100000, testDB);
+
+
+ m1 = master.getDB(testDB).foo.findOne({n: 1});
+ assert( m1['n'] == 1 , "Failed to save to master");
+
+ var s0 = slaves[0].getDB(testDB).foo.findOne({n: 1});
+ assert( s0['n'] == 1 , "Failed to replicate to slave 0");
+
+ var s1 = slaves[1].getDB(testDB).foo.findOne({n: 1});
+ assert( s1['n'] == 1 , "Failed to replicate to slave 1");
+
+
+
+ // Test getlasterror with large insert
+ bigData = new Array(2000).toString()
+ for(var n=0; n<1000; n++)
+ master.getDB(testDB).baz.insert({n: n, data: bigData});
+ callGetLastError(3, 60000);
- // Wait for replication two two nodes
- master.getDB("foo").bar.insert({n: 2});
- var result = master.getDB("foo").runCommand({getlasterror: {w: 2, wtimeout: 20000}});
- assert( result['ok'] == 1, "getLastError with w=2 failed");
+ var verifyReplication = function(nodeName, collection) {
+ data = collection.findOne({n: 1});
+ assert( data['n'] == 1 , "Failed to save to " + nodeName);
+ m1 = collection.findOne({n: 999});
+ assert( data['n'] == 999 , "Failed to save to " + nodeName);
+ }
- // Wait for replication to three nodes
- master.getDB("foo").bar.insert({n: 3});
- var result = master.getDB("foo").runCommand({getlasterror: {w: 3, wtimeout: 20000}});
- assert( result['ok'] == 1, "getLastError with w=3 failed");
+ verifyReplication("master", master.getDB(testDB).baz);
+ verifyReplication("slave 0", slaves[0].getDB(testDB).baz);
+ verifyReplication("slave 1", slaves[1].getDB(testDB).baz);
replTest.stopSet( signal );
}
-doTest( 15 );
+// doTest( 15 );
@@ -40,18 +40,18 @@ doTest = function( signal ) {
stat = master.getDB("admin").runCommand({replSetGetStatus: 1});
printjson( stat );
return stat.myState == 1;
- }, "Master failed to come up as master.");
+ }, "Master failed to come up as master.", 60000);
// Slaves to be set to 2 (secondary)
assert.soon(function() {
stat = slaves[0].getDB("admin").runCommand({replSetGetStatus: 1});
return stat.myState == 2;
- }, "Slave failed to come up as slave.");
+ }, "Slave failed to come up as slave.", 60000);
assert.soon(function() {
stat = slaves[0].getDB("admin").runCommand({replSetGetStatus: 1});
return stat.members.length == 2;
- }, "Wrong number of members");
+ }, "Wrong number of members", 60000);
}
doTest( 15 );
Oops, something went wrong.

0 comments on commit 5bfecc8

Please sign in to comment.