|
| 1 | +/** |
| 2 | + * Shuts down config server and shard replica set nodes one by one and ensures correct behaviour. |
| 3 | + */ |
| 4 | + |
| 5 | +// Checking UUID consistency involves talking to the config servers, which are shut down in this |
| 6 | +// test. |
| 7 | +TestData.skipCheckingUUIDsConsistentAcrossCluster = true; |
| 8 | + |
| 9 | +(function() { |
| 10 | + 'use strict'; |
| 11 | + |
| 12 | + var st = new ShardingTest({shards: {rs0: {nodes: 2}}}); |
| 13 | + |
| 14 | + jsTest.log('Config nodes up: 3 of 3, shard nodes up: 2 of 2: ' + |
| 15 | + 'Insert test data to work with'); |
| 16 | + assert.writeOK(st.s0.getDB('TestDB').TestColl.update( |
| 17 | + {_id: 0}, {$inc: {count: 1}}, {upsert: true, writeConcern: {w: 2, wtimeout: 30000}})); |
| 18 | + assert.eq([{_id: 0, count: 1}], st.s0.getDB('TestDB').TestColl.find().toArray()); |
| 19 | + |
| 20 | + jsTest.log('Config nodes up: 2 of 3, shard nodes up: 2 of 2: ' + |
| 21 | + 'Inserts and queries must work'); |
| 22 | + st.configRS.stop(0); |
| 23 | + st.restartMongos(0); |
| 24 | + assert.writeOK(st.s0.getDB('TestDB').TestColl.update( |
| 25 | + {_id: 0}, {$inc: {count: 1}}, {upsert: true, writeConcern: {w: 2, wtimeout: 30000}})); |
| 26 | + assert.eq([{_id: 0, count: 2}], st.s0.getDB('TestDB').TestColl.find().toArray()); |
| 27 | + |
| 28 | + jsTest.log('Config nodes up: 1 of 3, shard nodes up: 2 of 2: ' + |
| 29 | + 'Inserts and queries must work'); |
| 30 | + st.configRS.stop(1); |
| 31 | + st.restartMongos(0); |
| 32 | + assert.writeOK(st.s0.getDB('TestDB').TestColl.update( |
| 33 | + {_id: 0}, {$inc: {count: 1}}, {upsert: true, writeConcern: {w: 2, wtimeout: 30000}})); |
| 34 | + assert.eq([{_id: 0, count: 3}], st.s0.getDB('TestDB').TestColl.find().toArray()); |
| 35 | + |
| 36 | + jsTest.log('Config nodes up: 1 of 3, shard nodes up: 1 of 2: ' + |
| 37 | + 'Only queries will work (no shard primary)'); |
| 38 | + st.rs0.stop(0); |
| 39 | + st.restartMongos(0); |
| 40 | + st.s0.setSlaveOk(true); |
| 41 | + assert.eq([{_id: 0, count: 3}], st.s0.getDB('TestDB').TestColl.find().toArray()); |
| 42 | + |
| 43 | + jsTest.log('Config nodes up: 1 of 3, shard nodes up: 0 of 2: ' + |
| 44 | + 'MongoS must start, but no operations will work (no shard nodes available)'); |
| 45 | + st.rs0.stop(1); |
| 46 | + st.restartMongos(0); |
| 47 | + assert.throws(function() { |
| 48 | + st.s0.getDB('TestDB').TestColl.find().toArray(); |
| 49 | + }); |
| 50 | + |
| 51 | + jsTest.log('Config nodes up: 0 of 3, shard nodes up: 0 of 2: ' + |
| 52 | + 'Metadata cannot be loaded at all, no operations will work'); |
| 53 | + st.configRS.stop(1); |
| 54 | + |
| 55 | + // Instead of restarting mongos, ensure it has no metadata |
| 56 | + assert.commandWorked(st.s0.adminCommand({flushRouterConfig: 1})); |
| 57 | + |
| 58 | + // Throws transport error first and subsequent times when loading config data, not no primary |
| 59 | + for (var i = 0; i < 2; i++) { |
| 60 | + try { |
| 61 | + st.s0.getDB('TestDB').TestColl.findOne(); |
| 62 | + |
| 63 | + // Must always throw |
| 64 | + assert(false); |
| 65 | + } catch (e) { |
| 66 | + printjson(e); |
| 67 | + |
| 68 | + // Make sure we get a transport error, and not a no-primary error |
| 69 | + assert(e.code == 10276 || // Transport error |
| 70 | + e.code == 13328 || // Connect error |
| 71 | + e.code == ErrorCodes.HostUnreachable || |
| 72 | + e.code == ErrorCodes.FailedToSatisfyReadPreference || |
| 73 | + e.code == ErrorCodes.ReplicaSetNotFound); |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + st.stop(); |
| 78 | +}()); |
0 commit comments