summaryrefslogtreecommitdiff
path: root/jstests/core/list_namespaces_invalidation.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/core/list_namespaces_invalidation.js')
-rw-r--r--jstests/core/list_namespaces_invalidation.js66
1 files changed, 35 insertions, 31 deletions
diff --git a/jstests/core/list_namespaces_invalidation.js b/jstests/core/list_namespaces_invalidation.js
index 81f6c7d69f1..bcf75ae0695 100644
--- a/jstests/core/list_namespaces_invalidation.js
+++ b/jstests/core/list_namespaces_invalidation.js
@@ -1,45 +1,49 @@
-// SERVER-27996 Missing invalidation for system.namespaces writes
+// SERVER-27996/SERVER-28022 Missing invalidation for system.namespaces writes
(function() {
'use strict';
- let dbInvalidName = 'system_namespaces_invalidations';
- let dbInvalid = db.getSiblingDB(dbInvalidName);
- let num_collections = 3;
- function testNamespaceInvalidation(isRename) {
+ var dbInvalidName = 'system_namespaces_invalidations';
+ var dbInvalid = db.getSiblingDB(dbInvalidName);
+ var num_collections = 3;
+ var DROP = 1;
+ var RENAME = 2;
+ function testNamespaceInvalidation(namespaceAction, batchSize) {
dbInvalid.dropDatabase();
// Create enough collections to necessitate multiple cursor batches.
- for (let i = 0; i < num_collections; i++) {
+ for (var i = 0; i < num_collections; i++) {
assert.commandWorked(dbInvalid.createCollection('coll' + i.toString()));
}
- // Get the first two namespaces. Use find on 'system.namespaces' on MMAPv1, listCollections
- // otherwise.
- let cmd = dbInvalid.system.indexes.count() ? {find: 'system.namespaces'}
- : {listCollections: dbInvalidName};
- Object.extend(cmd, {batchSize: 2});
- let res = dbInvalid.runCommand(cmd);
- assert.commandWorked(res, 'could not run ' + tojson(cmd));
- printjson(res);
+ // Get the first batch of namespaces. Use find on 'system.namespaces' on MMAPv1,
+ // listCollections otherwise.
+ var cursor;
+ if (dbInvalid.system.namespaces.count()) {
+ cursor = dbInvalid.system.namespaces.find().batchSize(batchSize);
+ } else {
+ var res = dbInvalid.runCommand({listCollections: dbInvalidName});
+ assert.commandWorked(res, 'could not run listCollections');
+ cursor = new DBCommandCursor(dbInvalid.getMongo(), res);
+ }
- // Ensure the cursor has data, drop or rename the collections, and exhaust the cursor.
- let cursor = new DBCommandCursor(dbInvalid.getMongo(), res);
- let errMsg =
- 'expected more data from command ' + tojson(cmd) + ', with result ' + tojson(res);
+ // Ensure the cursor has data, invalidate the namespace, and exhaust the cursor.
+ var errMsg = 'expected more data from system.namespaces cursor';
assert(cursor.hasNext(), errMsg);
- for (let j = 0; j < num_collections; j++) {
- if (isRename) {
- // Rename the collection to something that does not fit in the previously allocated
- // memory for the record.
- assert.commandWorked(dbInvalid['coll' + j.toString()].renameCollection(
- 'coll' + j.toString() + 'lkdsahflaksjdhfsdkljhfskladhfkahfsakfla' +
- 'skfjhaslfaslfkhasklfjhsakljhdsjksahkldjslh'));
- } else {
- assert(dbInvalid['coll' + j.toString()].drop());
- }
+ if (namespaceAction == RENAME) {
+ // Rename the collection to something that does not fit in the previously allocated
+ // memory for the record.
+ assert.commandWorked(
+ dbInvalid['coll1'].renameCollection('coll1' +
+ 'lkdsahflaksjdhfsdkljhfskladhfkahfsakfla' +
+ 'skfjhaslfaslfkhasklfjhsakljhdsjksahkldjslh'));
+ } else if (namespaceAction == DROP) {
+ assert(dbInvalid['coll1'].drop());
}
assert.gt(cursor.itcount(), 0, errMsg);
}
- // Test that we invalidate namespaces for both collection drops and renames.
- testNamespaceInvalidation(false);
- testNamespaceInvalidation(true);
+ // Test that we invalidate the old namespace record ID when we remove or rename a namespace
+ // record.
+ for (var j = 2; j < 7; j++) {
+ testNamespaceInvalidation(DROP, j);
+ testNamespaceInvalidation(RENAME, j);
+ }
}());