summaryrefslogtreecommitdiff
path: root/jstests/disk
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2022-01-25 14:56:39 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-01-27 00:11:24 +0000
commit2bc052f1aa5f40868dee6569d12b703605d5a411 (patch)
tree8cd874775d7d79e9a55b8b7282e114781ba9e190 /jstests/disk
parent621652e91925e944e9c13669a5c212bae7dfd662 (diff)
downloadmongo-2bc052f1aa5f40868dee6569d12b703605d5a411.tar.gz
SERVER-62606 Add a test verifying that the server can startup in standalone mode with missing data files for user collections
(cherry picked from commit 376a1b164bebb03d265d00c7005c58cddd26f6d7)
Diffstat (limited to 'jstests/disk')
-rw-r--r--jstests/disk/wt_startup_with_missing_user_collection.js63
1 files changed, 63 insertions, 0 deletions
diff --git a/jstests/disk/wt_startup_with_missing_user_collection.js b/jstests/disk/wt_startup_with_missing_user_collection.js
new file mode 100644
index 00000000000..2fb903646b4
--- /dev/null
+++ b/jstests/disk/wt_startup_with_missing_user_collection.js
@@ -0,0 +1,63 @@
+/**
+ * Tests that mongod can startup in standalone mode with missing data files for user collections.
+ * Performing any operations against collections with missing data files will result in a crash.
+ *
+ * @tags: [requires_wiredtiger]
+ */
+(function() {
+
+load('jstests/disk/libs/wt_file_helper.js');
+
+// This test triggers an unclean shutdown (an fassert), which may cause inaccurate fast counts.
+TestData.skipEnforceFastCountOnValidate = true;
+
+const baseName = "wt_startup_with_missing_user_collection";
+const dbpath = MongoRunner.dataPath + baseName + "/";
+
+resetDbpath(dbpath);
+let mongod = startMongodOnExistingPath(dbpath);
+
+const dbName = "test";
+let testDB = mongod.getDB(dbName);
+
+assert.commandWorked(testDB.createCollection("a"));
+assert.commandWorked(testDB.createCollection("b"));
+
+assert.commandWorked(testDB.adminCommand({fsync: 1}));
+
+const collUri = getUriForColl(testDB.getCollection("a"));
+const indexUri = getUriForIndex(testDB.getCollection("a"), /*indexName=*/"_id_");
+
+MongoRunner.stopMongod(mongod);
+
+// Remove data files for collection "a" after shutting down.
+removeFile(dbpath + "/" + collUri + ".wt");
+removeFile(dbpath + "/" + indexUri + ".wt");
+
+// Perform a startup and shutdown with no other operations in between.
+mongod = startMongodOnExistingPath(dbpath);
+assert.neq(null, mongod, "Failed to start");
+
+// Disable validation because it is expected to fail when data files are missing.
+MongoRunner.stopMongod(mongod, null, {skipValidation: true});
+
+// Perform a startup and try to use collection "a". Mongod will crash.
+mongod = startMongodOnExistingPath(dbpath);
+assert.neq(null, mongod, "Failed to start");
+
+testDB = mongod.getDB(dbName);
+
+assert.throws(() => {
+ assert.commandWorked(testDB.getCollection("a").insert({}));
+});
+assert.gte(rawMongoProgramOutput().search("Fatal assertion.*50883"), 0);
+
+// Perform a startup, drop collection "a" and shutdown.
+mongod = startMongodOnExistingPath(dbpath);
+assert.neq(null, mongod, "Failed to start");
+
+testDB = mongod.getDB(dbName);
+assert(testDB.getCollection("a").drop());
+
+MongoRunner.stopMongod(mongod);
+}());