summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShin Yee Tan <shinyee.tan@mongodb.com>2022-10-14 20:43:06 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-10-14 21:39:40 +0000
commit8c0cd9eb1e2e32b489b5d93ba9ccb18b0aa43cf0 (patch)
tree9de4b9c45aff5278c6a674e970273569a0b76fd8
parent778227a06e1fe91c536e598a3722da8391230ffb (diff)
downloadmongo-8c0cd9eb1e2e32b489b5d93ba9ccb18b0aa43cf0.tar.gz
SERVER-53594 Add frozen indexes to total index counts and subtract from in progress index counts
-rw-r--r--jstests/noPassthrough/drop_unfinished_replicated_index_build_in_standalone.js73
-rw-r--r--src/mongo/db/catalog/index_catalog_impl.cpp2
-rw-r--r--src/mongo/db/catalog/index_catalog_impl.h2
3 files changed, 75 insertions, 2 deletions
diff --git a/jstests/noPassthrough/drop_unfinished_replicated_index_build_in_standalone.js b/jstests/noPassthrough/drop_unfinished_replicated_index_build_in_standalone.js
new file mode 100644
index 00000000000..549796e390b
--- /dev/null
+++ b/jstests/noPassthrough/drop_unfinished_replicated_index_build_in_standalone.js
@@ -0,0 +1,73 @@
+/**
+ * Test that we allow collections and databases to be dropped in standalone mode with unfinished
+ * replicated index builds.
+ *
+ * @tags: [
+ * requires_persistence,
+ * requires_replication,
+ * ]
+ */
+(function() {
+'use strict';
+
+load('jstests/disk/libs/wt_file_helper.js');
+load('jstests/noPassthrough/libs/index_build.js');
+
+const dbName = jsTestName();
+const collName1 = "test1";
+const collName2 = "test2";
+
+const rst = new ReplSetTest({nodes: 2});
+rst.startSet();
+rst.initiate();
+
+const primary = rst.getPrimary();
+
+const secondary = rst.getSecondary();
+let secondaryDB = secondary.getDB(dbName);
+const secondaryDbpath = secondary.dbpath;
+
+const primaryColl1 = primary.getDB(dbName).getCollection(collName1);
+const primaryColl2 = primary.getDB(dbName).getCollection(collName2);
+assert.commandWorked(primaryColl1.insert({_id: 0, a: 1}));
+assert.commandWorked(primaryColl2.insert({_id: 0, a: 1}));
+
+jsTestLog("Starting index builds on primary and pausing before completion");
+IndexBuildTest.pauseIndexBuilds(primary);
+const createIdx1 = IndexBuildTest.startIndexBuild(primary, primaryColl1.getFullName(), {a: 1});
+const createIdx2 = IndexBuildTest.startIndexBuild(primary, primaryColl2.getFullName(), {a: 1});
+
+// Waiting for secondary to start the index builds
+IndexBuildTest.waitForIndexBuildToStart(secondaryDB);
+
+jsTestLog("Shutting down secondary");
+rst.stop(secondary);
+
+// Waiting for parallel index build threads to finish
+let exitCode = createIdx1({checkExitSuccess: false});
+assert.neq(0, exitCode, 'expected shell to exit abnormally due to shutdown');
+exitCode = createIdx2({checkExitSuccess: false});
+assert.neq(0, exitCode, 'expected shell to exit abnormally due to shutdown');
+
+jsTestLog("Starting secondary as standalone");
+const mongod = MongoRunner.runMongod({dbpath: secondaryDbpath, noReplSet: true, noCleanData: true});
+secondaryDB = mongod.getDB(dbName);
+
+// Confirm that the secondary node leaves the index on coll1 as unfinished.
+IndexBuildTest.assertIndexes(
+ secondaryDB.getCollection(collName1), 2, ["_id_"], ["a_1"], {includeBuildUUIDs: true});
+
+jsTestLog("Dropping collection from secondary");
+assert.commandWorked(secondaryDB.runCommand({drop: collName1}));
+
+// Confirm that the secondary node leaves the index on coll2 as unfinished so we can check that
+// dropping database is also able to drop collections and indexes.
+IndexBuildTest.assertIndexes(
+ secondaryDB.getCollection(collName2), 2, ["_id_"], ["a_1"], {includeBuildUUIDs: true});
+
+jsTestLog("Dropping database from secondary");
+assert.commandWorked(secondaryDB.dropDatabase());
+
+MongoRunner.stopMongod(mongod);
+rst.stopSet();
+})();
diff --git a/src/mongo/db/catalog/index_catalog_impl.cpp b/src/mongo/db/catalog/index_catalog_impl.cpp
index 4e1d096aab1..15b83e6f336 100644
--- a/src/mongo/db/catalog/index_catalog_impl.cpp
+++ b/src/mongo/db/catalog/index_catalog_impl.cpp
@@ -1527,7 +1527,7 @@ bool IndexCatalogImpl::haveAnyIndexesInProgress() const {
}
int IndexCatalogImpl::numIndexesTotal(OperationContext* opCtx) const {
- return _readyIndexes.size() + _buildingIndexes.size();
+ return _readyIndexes.size() + _buildingIndexes.size() + _frozenIndexes.size();
}
int IndexCatalogImpl::numIndexesReady(OperationContext* opCtx) const {
diff --git a/src/mongo/db/catalog/index_catalog_impl.h b/src/mongo/db/catalog/index_catalog_impl.h
index 39b464bd153..c9d21c5500b 100644
--- a/src/mongo/db/catalog/index_catalog_impl.h
+++ b/src/mongo/db/catalog/index_catalog_impl.h
@@ -85,7 +85,7 @@ public:
int numIndexesTotal(OperationContext* opCtx) const override;
int numIndexesReady(OperationContext* opCtx) const override;
int numIndexesInProgress(OperationContext* opCtx) const {
- return numIndexesTotal(opCtx) - numIndexesReady(opCtx);
+ return numIndexesTotal(opCtx) - numIndexesReady(opCtx) - _frozenIndexes.size();
}
/**