diff options
Diffstat (limited to 'jstests/sharding/drop_collection.js')
| -rw-r--r-- | jstests/sharding/drop_collection.js | 70 |
1 files changed, 26 insertions, 44 deletions
diff --git a/jstests/sharding/drop_collection.js b/jstests/sharding/drop_collection.js index 0947b56124a..f07ced08ae5 100644 --- a/jstests/sharding/drop_collection.js +++ b/jstests/sharding/drop_collection.js @@ -32,29 +32,17 @@ function assertCollectionDropped(ns, uuid = null) { configDB.tags.countDocuments({ns: ns}), "Found unexpected tag for a collection after drop."); - // Sharding metadata checks - - // No more coll entry - assert.eq(null, st.s.getCollection(ns).exists()); - assert.eq(0, - configDB.collections.countDocuments({_id: ns}), - "Found collection entry in 'config.collection' after drop."); - // No more chunks + const errMsg = "Found collection entry in 'config.collection' after drop."; + // Before 5.0 chunks were indexed by ns, now by uuid + assert.eq(0, configDB.chunks.countDocuments({ns: ns}), errMsg); if (uuid != null) { - assert.eq(0, - configDB.chunks.countDocuments({uuid: uuid}), - "Found references to collection uuid in 'config.chunks' after drop."); + assert.eq(0, configDB.chunks.countDocuments({uuid: uuid}), errMsg); } - // Verify that persisted cached metadata was removed as part of the dropCollection - const chunksCollName = 'cache.chunks.' + ns; - for (let configDb of [st.shard0.getDB('config'), st.shard1.getDB('config')]) { - assert.eq(configDb['cache.collections'].countDocuments({_id: ns}), - 0, - "Found collection entry in 'config.cache.collections' after drop."); - assert(!configDb[chunksCollName].exists()); - } + // No more coll entry + assert.eq(null, st.s.getCollection(ns).exists()); + assert.eq(0, configDB.collections.countDocuments({_id: ns})); } jsTest.log("Drop unsharded collection."); @@ -86,11 +74,10 @@ jsTest.log("Drop unsharded collection also remove tags."); assert.commandWorked(db.runCommand({drop: coll.getName()})); assertCollectionDropped(coll.getFullName()); } - jsTest.log("Drop sharded collection repeated."); { const db = getNewDb(); - const coll = db['shardedColl0']; + const coll = db['unshardedColl0']; // Create the database assert.commandWorked(st.s.adminCommand({enableSharding: db.getName()})); for (var i = 0; i < 3; i++) { @@ -98,11 +85,9 @@ jsTest.log("Drop sharded collection repeated."); assert.commandWorked(st.s.adminCommand({shardCollection: coll.getFullName(), key: {x: 1}})); assert.commandWorked(coll.insert({x: 123})); assert.eq(1, coll.countDocuments({x: 123})); - // Drop the collection - var uuid = getCollectionUUID(coll.getFullName()); assert.commandWorked(db.runCommand({drop: coll.getName()})); - assertCollectionDropped(coll.getFullName(), uuid); + assertCollectionDropped(coll.getFullName()); } } @@ -260,9 +245,7 @@ jsTest.log("Move primary with drop and recreate - new primary own chunks."); configDB, coll.getFullName(), {shard: st.shard1.shardName})); jsTest.log("Drop sharded collection"); - var uuid = getCollectionUUID(coll.getFullName()); coll.drop(); - assertCollectionDropped(coll.getFullName(), uuid); jsTest.log("Re-Create sharded collection with one chunk on shard 0"); st.shardColl(coll, {skey: 1}, false, false); @@ -274,12 +257,11 @@ jsTest.log("Move primary with drop and recreate - new primary own chunks."); st.ensurePrimaryShard(db.getName(), st.shard1.shardName); jsTest.log("Drop sharded collection"); - uuid = getCollectionUUID(coll.getFullName()); coll.drop(); - assertCollectionDropped(coll.getFullName(), uuid); } -jsTest.log("Test that dropping an unsharded collection, relevant events are logged on CSRS."); +jsTest.log( + "Test that dropping a non-sharded collection, relevant events are properly logged on CSRS"); { // Create a non-sharded collection const db = getNewDb(); @@ -288,7 +270,6 @@ jsTest.log("Test that dropping an unsharded collection, relevant events are logg // Drop the collection assert.commandWorked(db.runCommand({drop: coll.getName()})); - assertCollectionDropped(coll.getFullName()); // Verify that the drop collection start event has been logged const startLogCount = @@ -301,7 +282,7 @@ jsTest.log("Test that dropping an unsharded collection, relevant events are logg assert.gte(1, endLogCount, "dropCollection end event not found in changelog"); } -jsTest.log("Test that dropping a sharded collection, relevant events are logged on CSRS."); +jsTest.log("Test that dropping a sharded collection, relevant events are properly logged on CSRS"); { // Create a sharded collection const db = getNewDb(); @@ -318,9 +299,7 @@ jsTest.log("Test that dropping a sharded collection, relevant events are logged assert.commandWorked(coll.insert({_id: -10})); // Drop the collection - const uuid = getCollectionUUID(coll.getFullName()); assert.commandWorked(db.runCommand({drop: coll.getName()})); - assertCollectionDropped(coll.getFullName(), uuid); // Verify that the drop collection start event has been logged const startLogCount = @@ -333,7 +312,7 @@ jsTest.log("Test that dropping a sharded collection, relevant events are logged assert.gte(1, endLogCount, "dropCollection end event not found in changelog"); } -jsTest.log("Test that dropping a sharded collection, the cached metadata on shards is cleaned up."); +jsTest.log("Test that dropping a sharded collection, the cached metadata on shards is cleaned up"); { // Create a sharded collection const db = getNewDb(); @@ -341,21 +320,24 @@ jsTest.log("Test that dropping a sharded collection, the cached metadata on shar assert.commandWorked( st.s.adminCommand({enableSharding: db.getName(), primaryShard: st.shard0.shardName})); assert.commandWorked(st.s.adminCommand({shardCollection: coll.getFullName(), key: {_id: 1}})); + + // Distribute the chunks among the shards + assert.commandWorked(st.s.adminCommand({split: coll.getFullName(), middle: {_id: 0}})); assert.commandWorked(coll.insert({_id: 10})); + assert.commandWorked(coll.insert({_id: -10})); - // At this point only one shard has valid filtering information (i.e. the one that has data). - // Below we are forcing to all shards to have their valid filtering information. For the shard - // that doesn't own any data, that means having a filtering information stating that no chunks - // are owned by that shard. - assert.commandWorked( - st.shard0.adminCommand({_flushRoutingTableCacheUpdates: coll.getFullName()})); - assert.commandWorked( - st.shard1.adminCommand({_flushRoutingTableCacheUpdates: coll.getFullName()})); + // Get the chunks cache collection name + const configCollDoc = st.s0.getDB('config').collections.findOne({_id: coll.getFullName()}); + const chunksCollName = 'cache.chunks.' + coll.getFullName(); // Drop the collection - const uuid = getCollectionUUID(coll.getFullName()); assert.commandWorked(db.runCommand({drop: coll.getName()})); - assertCollectionDropped(coll.getFullName(), uuid); + + // Verify that the cached metadata on shards is cleaned up + for (let configDb of [st.shard0.getDB('config'), st.shard1.getDB('config')]) { + assert.eq(configDb['cache.collections'].countDocuments({_id: coll.getFullName()}), 0); + assert(!configDb[chunksCollName].exists()); + } } st.stop(); |
