1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
/**
* Test getLastError with w parameter when writing directly to the config servers will
* cause an error.
*/
function writeToConfigTest(){
var st = new ShardingTest({ shards: 2 });
var confDB = st.s.getDB( 'config' );
confDB.settings.update({ _id: 'balancer' }, { $set: { stopped: true }});
var gleObj = confDB.runCommand({ getLastError: 1, w: 'majority' });
assert( gleObj.ok );
assert.eq("norepl", gleObj.err);
// w:1 should still work
confDB.settings.update({ _id: 'balancer' }, { $set: { stopped: true }});
var gleObj = confDB.runCommand({ getLastError: 1, w: 1 });
assert(gleObj.ok);
assert.eq(null, gleObj.err);
st.stop();
}
/**
* Test getLastError with w parameter will not cause an error when writes to mongos
* would trigger writes to config servers (in this test, split chunks is used).
*/
function configTest( configCount ){
var st = new ShardingTest({ shards: 1, config: configCount,
rs: { oplogSize: 10 }, other: { chunkSize: 1 }});
var mongos = st.s;
var testDB = mongos.getDB( 'test' );
var coll = testDB.user;
testDB.adminCommand({ enableSharding: testDB.getName() });
testDB.adminCommand({ shardCollection: coll.getFullName(), key: { x: 1 }});
var chunkCount = function() {
return mongos.getDB( 'config' ).chunks.find().count();
};
var initChunks = chunkCount();
var currChunks = initChunks;
var gleObj = null;
var x = 0;
while( currChunks <= initChunks ){
coll.insert({ x: x++ });
gleObj = testDB.runCommand({ getLastError: 1, w: 'majority' });
currChunks = chunkCount();
}
assert( gleObj.ok );
assert.eq( null, gleObj.err );
st.stop();
}
writeToConfigTest();
configTest( 1 );
configTest( 3 ); // sync cluster config servers
|