|
| 1 | +// Ensures that if the primary config server is blackholed from the point of view of mongos, CRUD |
| 2 | +// and read-only config operations continue to work. |
| 3 | +(function() { |
| 4 | + 'use strict'; |
| 5 | + |
| 6 | + var st = new ShardingTest({ |
| 7 | + name: 'primary_config_server_blackholed_from_mongos', |
| 8 | + shards: 2, |
| 9 | + mongos: 1, |
| 10 | + useBridge: true |
| 11 | + }); |
| 12 | + |
| 13 | + var testDB = st.s.getDB('BlackHoleDB'); |
| 14 | + var configDB = st.s.getDB('config'); |
| 15 | + |
| 16 | + assert.commandWorked(testDB.adminCommand({enableSharding: 'BlackHoleDB'})); |
| 17 | + assert.commandWorked( |
| 18 | + testDB.adminCommand({shardCollection: testDB.ShardedColl.getFullName(), key: {_id: 1}})); |
| 19 | + |
| 20 | + var bulk = testDB.ShardedColl.initializeUnorderedBulkOp(); |
| 21 | + for (var i = 0; i < 1000; i++) { |
| 22 | + bulk.insert({_id: i}); |
| 23 | + } |
| 24 | + assert.writeOK(bulk.execute()); |
| 25 | + |
| 26 | + jsTest.log('Partitioning the config server primary from the mongos'); |
| 27 | + var configPrimary = st.configRS.getPrimary(); |
| 28 | + configPrimary.discardMessagesFrom(st.s, 1.0); |
| 29 | + st.s.discardMessagesFrom(configPrimary, 1.0); |
| 30 | + |
| 31 | + assert.commandWorked(testDB.adminCommand({flushRouterConfig: 1})); |
| 32 | + |
| 33 | + // This should fail, because the primary is not available |
| 34 | + jsTest.log('Doing write operation on a new database and collection'); |
| 35 | + assert.writeError(st.s.getDB('NonExistentDB') |
| 36 | + .TestColl.insert({_id: 0, value: 'This value will never be inserted'})); |
| 37 | + |
| 38 | + jsTest.log('Doing CRUD operations on the sharded collection'); |
| 39 | + assert.eq(1000, testDB.ShardedColl.find().itcount()); |
| 40 | + assert.writeOK(testDB.ShardedColl.insert({_id: 1000})); |
| 41 | + assert.eq(1001, testDB.ShardedColl.find().count()); |
| 42 | + |
| 43 | + jsTest.log('Doing read operations on a config server collection'); |
| 44 | + // Should fail due to primary read preference |
| 45 | + assert.throws(function() { |
| 46 | + configDB.chunks.find().itcount(); |
| 47 | + }); |
| 48 | + assert.throws(function() { |
| 49 | + configDB.chunks.find().count(); |
| 50 | + }); |
| 51 | + assert.throws(function() { |
| 52 | + configDB.chunks.aggregate().itcount(); |
| 53 | + }); |
| 54 | + |
| 55 | + // With secondary read pref config server reads should work |
| 56 | + st.s.setReadPref('secondary'); |
| 57 | + assert.lt(0, configDB.chunks.find().itcount()); |
| 58 | + assert.lt(0, configDB.chunks.find().count()); |
| 59 | + assert.lt(0, configDB.chunks.aggregate().itcount()); |
| 60 | + |
| 61 | + st.stop(); |
| 62 | + |
| 63 | +}()); |
0 commit comments