summaryrefslogtreecommitdiff
path: root/jstests/replsets/global_index_ddl_rollback.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/replsets/global_index_ddl_rollback.js')
-rw-r--r--jstests/replsets/global_index_ddl_rollback.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/jstests/replsets/global_index_ddl_rollback.js b/jstests/replsets/global_index_ddl_rollback.js
new file mode 100644
index 00000000000..5243f6d4d3d
--- /dev/null
+++ b/jstests/replsets/global_index_ddl_rollback.js
@@ -0,0 +1,56 @@
+/**
+ * Tests that global index container ddl operations can be rolled back.
+ *
+ * @tags: [
+ * featureFlagGlobalIndexes,
+ * requires_fcv_62,
+ * requires_replication,
+ * ]
+ */
+(function() {
+'use strict';
+
+load('jstests/replsets/libs/rollback_test.js');
+
+function uuidToNss(uuid) {
+ const [_, uuidString] = uuid.toString().match(/"((?:\\.|[^"\\])*)"/);
+ return "globalIndexes." + uuidString;
+}
+
+const rollbackTest = new RollbackTest(jsTestName());
+
+const primary = rollbackTest.getPrimary();
+const adminDB = primary.getDB("admin");
+const globalIndexCreateUUID = UUID();
+const globalIndexDropUUID = UUID();
+
+// Create a global index container to be dropped.
+assert.commandWorked(adminDB.runCommand({_shardsvrCreateGlobalIndex: globalIndexDropUUID}));
+
+rollbackTest.transitionToRollbackOperations();
+
+// Create a global index container to be rolled back.
+assert.commandWorked(adminDB.runCommand({_shardsvrCreateGlobalIndex: globalIndexCreateUUID}));
+// Drop a global index container, operation should be rolled back.
+assert.commandWorked(adminDB.runCommand({_shardsvrDropGlobalIndex: globalIndexDropUUID}));
+
+// Perform the rollback.
+rollbackTest.transitionToSyncSourceOperationsBeforeRollback();
+rollbackTest.transitionToSyncSourceOperationsDuringRollback();
+rollbackTest.transitionToSteadyStateOperations();
+
+rollbackTest.getTestFixture().nodes.forEach(function(node) {
+ const nodeDB = node.getDB("system");
+
+ // Check globalIndexCreateUUID creation is rolled back and does not exist.
+ var res =
+ nodeDB.runCommand({listCollections: 1, filter: {name: uuidToNss(globalIndexCreateUUID)}});
+ assert.eq(res.cursor.firstBatch.length, 0);
+
+ // Check globalIndexDropUUID drop is rolled back and still exists.
+ res = nodeDB.runCommand({listCollections: 1, filter: {name: uuidToNss(globalIndexDropUUID)}});
+ assert.eq(res.cursor.firstBatch.length, 1);
+});
+
+rollbackTest.stop();
+})();