|
| 1 | +/** |
| 2 | + * Common helpers for testing operations on unsharded collections. |
| 3 | + */ |
| 4 | + |
| 5 | +function getNewNs(dbName) { |
| 6 | + if (typeof getNewNs.counter == 'undefined') { |
| 7 | + getNewNs.counter = 0; |
| 8 | + } |
| 9 | + getNewNs.counter++; |
| 10 | + const collName = "ns" + getNewNs.counter; |
| 11 | + return [collName, dbName + "." + collName]; |
| 12 | +} |
| 13 | + |
| 14 | +function checkInStorageCatalog({dbName, collName, type, shardConn}) { |
| 15 | + const query = {name: collName, type}; |
| 16 | + assert.eq(1, |
| 17 | + shardConn.getDB(dbName).getCollectionInfos(query).length, |
| 18 | + "Current contents of storage catalog on " + shardConn + ": " + |
| 19 | + tojson(shardConn.getDB(dbName).getCollectionInfos()) + |
| 20 | + ", query: " + tojson(query)); |
| 21 | +} |
| 22 | + |
| 23 | +function checkNotInStorageCatalog({dbName, collName, shardConn}) { |
| 24 | + const query = {name: collName}; |
| 25 | + assert.eq(0, |
| 26 | + shardConn.getDB(dbName).getCollectionInfos(query).length, |
| 27 | + "Current contents of storage catalog on " + shardConn + ": " + |
| 28 | + tojson(shardConn.getDB(dbName).getCollectionInfos()) + |
| 29 | + ", query: " + tojson(query)); |
| 30 | +} |
| 31 | + |
| 32 | +function checkInShardingCatalog({ns, shardKey, unique, distributionMode, numChunks, mongosConn}) { |
| 33 | + const configDB = mongosConn.getDB("config"); |
| 34 | + |
| 35 | + // Check the collection entry. |
| 36 | + const collQuery = {}; |
| 37 | + collQuery._id = ns; |
| 38 | + collQuery["key." + shardKey] = 1; |
| 39 | + collQuery.unique = unique; |
| 40 | + collQuery.distributionMode = distributionMode; |
| 41 | + assert.neq(null, |
| 42 | + configDB.collections.findOne(collQuery), |
| 43 | + "Current contents of config.collections: " + |
| 44 | + tojson(configDB.collections.find().toArray()) + ", query: " + tojson(collQuery)); |
| 45 | + |
| 46 | + // Check the chunk entries. |
| 47 | + const chunkQuery = {}; |
| 48 | + chunkQuery.ns = ns; |
| 49 | + chunkQuery["min." + shardKey] = {$exists: true}; |
| 50 | + chunkQuery["max." + shardKey] = {$exists: true}; |
| 51 | + assert.eq(numChunks, |
| 52 | + configDB.chunks.count(chunkQuery), |
| 53 | + "Current contents of config.chunks: " + tojson(configDB.chunks.find().toArray()) + |
| 54 | + ", query: " + tojson(chunkQuery)); |
| 55 | +} |
| 56 | + |
| 57 | +function checkNotInShardingCatalog({ns, mongosConn}) { |
| 58 | + const configDB = mongosConn.getDB("config"); |
| 59 | + |
| 60 | + assert.eq( |
| 61 | + null, |
| 62 | + configDB.collections.findOne({_id: ns}), |
| 63 | + "Current contents of config.collections: " + tojson(configDB.collections.find().toArray())); |
| 64 | + assert.eq(0, |
| 65 | + configDB.chunks.count({ns: ns}), |
| 66 | + "Current contents of config.chunks: " + tojson(configDB.chunks.find().toArray())); |
| 67 | +} |
| 68 | + |
| 69 | +function setFailpoint(failpointName, conn) { |
| 70 | + assert.commandWorked(conn.adminCommand({ |
| 71 | + configureFailPoint: failpointName, |
| 72 | + mode: "alwaysOn", |
| 73 | + })); |
| 74 | +} |
| 75 | + |
| 76 | +function unsetFailpoint(failpointName, conn) { |
| 77 | + assert.commandWorked(conn.adminCommand({ |
| 78 | + configureFailPoint: failpointName, |
| 79 | + mode: "off", |
| 80 | + })); |
| 81 | +} |
0 commit comments