diff options
author | agirbal <antoine@10gen.com> | 2010-12-23 17:39:22 -0800 |
---|---|---|
committer | agirbal <antoine@10gen.com> | 2010-12-23 17:39:22 -0800 |
commit | 378ba71fd2d98fcfd73deebd32376bdcee08df82 (patch) | |
tree | d5e313728f260cf8ff1f0dae93864a5ef5009dea | |
parent | a6bf3b2b61453a72842ff03bc9f416a185d3fb35 (diff) | |
download | mongo-378ba71fd2d98fcfd73deebd32376bdcee08df82.tar.gz |
[SERVER-2284]: operations using system.js collection (group, mapred, where) always fail the 1st time on slave
-rw-r--r-- | jstests/replsets/groupAndMapReduce.js | 66 | ||||
-rw-r--r-- | scripting/engine.cpp | 2 |
2 files changed, 67 insertions, 1 deletions
diff --git a/jstests/replsets/groupAndMapReduce.js b/jstests/replsets/groupAndMapReduce.js new file mode 100644 index 00000000000..9fefd3bb708 --- /dev/null +++ b/jstests/replsets/groupAndMapReduce.js @@ -0,0 +1,66 @@ +doTest = function( signal ) { + + // Test basic replica set functionality. + // -- Replication + // -- Failover + + // Replica set testing API + // Create a new replica set test. Specify set name and the number of nodes you want. + var replTest = new ReplSetTest( {name: 'testSet', nodes: 3} ); + + // call startSet() to start each mongod in the replica set + // this returns a list of nodes + var nodes = replTest.startSet(); + + // Call initiate() to send the replSetInitiate command + // This will wait for initiation + replTest.initiate(); + + // Call getMaster to return a reference to the node that's been + // elected master. + var master = replTest.getMaster(); + + // save some records + var len = 100 + for (var i = 0; i < len; ++i) { + master.getDB("foo").foo.save({a: i}); + } + + // This method will check the oplogs of the master + // and slaves in the set and wait until the change has replicated. + replTest.awaitReplication(); + print("Sleeping 10s for slaves to go to secondary state"); + sleep(10000); + + slaves = replTest.liveNodes.slaves; + assert( slaves.length == 2, "Expected 2 slaves but length was " + slaves.length ); + slaves.forEach(function(slave) { + // testing against + slave.setSlaveOk(); + + // try to read from slave + var count = slave.getDB("foo").foo.count(); + printjson( count ); + assert.eq( len , count , "slave count wrong: " + slave ); + + var one = slave.getDB("foo").foo.findOne(); + printjson(one); + +// stats = slave.getDB("foo").adminCommand({replSetGetStatus:1}); +// printjson(stats); + + // now do group on slave + count = slave.getDB("foo").foo.group({initial: {n:0}, reduce: function(obj,out){out.n++;}}); + printjson( count ); + assert.eq( len , count[0].n , "slave group count wrong: " + slave ); + + }); + + + + // Shut down the set and finish the test. + replTest.stopSet( signal ); +} + +doTest( 15 );
+print("SUCCESS");
diff --git a/scripting/engine.cpp b/scripting/engine.cpp index 27a23f6f3c0..e696f70f2dd 100644 --- a/scripting/engine.cpp +++ b/scripting/engine.cpp @@ -183,7 +183,7 @@ namespace mongo { string coll = _localDBName + ".system.js"; static DBClientBase * db = createDirectClient(); - auto_ptr<DBClientCursor> c = db->query( coll , Query() ); + auto_ptr<DBClientCursor> c = db->query( coll , Query(), 0, 0, NULL, QueryOption_SlaveOk, 0 ); assert( c.get() ); set<string> thisTime; |