summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorPatrick Freed <patrick.freed@mongodb.com>2018-11-16 18:03:44 -0500
committerPatrick Freed <patrick.freed@mongodb.com>2018-11-20 11:51:38 -0500
commit119d20943364bc9c2525a83a45dd36ebb1092bce (patch)
tree7e43ad0b40f509d46fb8659bfbef77e0679c4b5b /jstests
parent68958ba2b0b572f937c24f365bf9d8894735a8c9 (diff)
downloadmongo-119d20943364bc9c2525a83a45dd36ebb1092bce.tar.gz
SERVER-36968 Rebuild interrupted system indexes before checking AuthZN index presence
Diffstat (limited to 'jstests')
-rw-r--r--jstests/auth/rebuild_system_indexes.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/jstests/auth/rebuild_system_indexes.js b/jstests/auth/rebuild_system_indexes.js
new file mode 100644
index 00000000000..76ccd52c5a1
--- /dev/null
+++ b/jstests/auth/rebuild_system_indexes.js
@@ -0,0 +1,56 @@
+/**
+ * This test verifies that the server will attempt to rebuild admin.system.users index on startup if
+ * it is in a partially built state using the mmapv1 storage engine.
+ *
+ * @tags: [requires_journaling, requires_mmapv1]
+ */
+(() => {
+ "use strict";
+
+ const dbpath = "rebuild_system_indexes";
+ const user = 'admin';
+ const pwd = 'adminPassword';
+
+ const mongod = MongoRunner.runMongod({storageEngine: 'mmapv1', dbpath});
+
+ let admin = mongod.getDB('admin');
+
+ // Create the system.users index
+ assert.commandWorked(
+ admin.runCommand({createUser: user, pwd, roles: [{role: 'root', db: 'admin'}]}),
+ 'failed to create user/indexes');
+ assert.commandWorked(admin.runCommand({deleteIndexes: 'system.users', index: '*'}),
+ 'failed to drop indexes');
+
+ MongoRunner.stopMongod(mongod);
+
+ // Add a fail point so the server crashes while rebuilding the indexes
+ print('================= starting mongod that WILL CRASH PURPOSEFULLY =================');
+ MongoRunner.runMongod({
+ restart: mongod,
+ storageEngine: 'mmapv1',
+ setParameter: "failpoint.crashAfterStartingIndexBuild={mode: 'alwaysOn'}", dbpath,
+ });
+ print('======================== END PURPOSEFUL CRASH ========================');
+
+ // Make sure the server isnt running
+ assert.neq(0,
+ runMongoProgram('mongo', '--port', mongod.port, '--eval', 'db.isMaster()'),
+ "mongod did not crash when creating index");
+
+ // Start up normally, indexes should be rebuilt
+ MongoRunner.runMongod({
+ restart: mongod,
+ storageEngine: 'mmapv1',
+ setParameter: "failpoint.crashAfterStartingIndexBuild={mode: 'off'}", dbpath,
+ });
+
+ assert(mongod);
+
+ admin = mongod.getDB('admin');
+ admin.auth(user, pwd);
+
+ assert(admin.getCollection('system.users').getIndexes().length > 1, 'indexes were not rebuilt');
+
+ MongoRunner.stopMongod(mongod);
+})();