diff options
Diffstat (limited to 'jstests')
5 files changed, 93 insertions, 97 deletions
diff --git a/jstests/noPassthrough/delete_incomplete_index_data_on_startup_recovery.js b/jstests/noPassthrough/delete_incomplete_index_data_on_startup_recovery.js deleted file mode 100644 index baeef175b78..00000000000 --- a/jstests/noPassthrough/delete_incomplete_index_data_on_startup_recovery.js +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Test that the data tables for an incomplete index on unclean shutdown is dropped immediately as - * opposed to deferred per the usual two-phase index drop logic. - * - * @tags: [ - * requires_replication, - * # The primary is restarted and must retain its data. - * requires_persistence, - * ] - */ - -(function() { -"use strict"; - -load("jstests/libs/fail_point_util.js"); - -const rst = new ReplSetTest({name: jsTest.name(), nodes: 1}); -rst.startSet(); -rst.initiate(); - -const dbName = "testDB"; -const collName = "fantasticalCollName"; -const primary = rst.getPrimary(); -const primaryDB = primary.getDB(dbName); -const primaryColl = primaryDB[collName]; - -assert.commandWorked(primaryDB.createCollection(collName)); -assert.commandWorked(primaryColl.insert({x: 1})); -assert.commandWorked(primaryColl.insert({x: 2})); -assert.commandWorked(primaryColl.insert({x: 3})); - -const failPoint = configureFailPoint(primaryDB, "hangIndexBuildBeforeCommit"); -let ps = undefined; -try { - TestData.dbName = dbName; - TestData.collName = collName; - TestData.indexSpec = {x: 1}; - TestData.indexName = {name: "myFantasticalIndex"}; - - ps = startParallelShell(() => { - jsTestLog("Starting an index build that will hang, establishing an unfinished index " + - "to be found on startup."); - // Crashing the server while this command is running may cause the parallel shell code to - // error and stop executing. We will therefore ignore the result of this command and - // parallel shell. Test correctness is guaranteed by waiting for the failpoint this command - // hits. - db.getSiblingDB(TestData.dbName)[TestData.collName].createIndex(TestData.indexSpec, - TestData.indexName); - }, primary.port); - - jsTest.log("Waiting for the async index build to hit the failpoint."); - failPoint.wait(); - - jsTest.log( - "Force a checkpoint, now that the index is present in the catalog. This ensures that on " + - "startup the index will not be an 'unknown ident' discarded immediately because it does " + - "not have an associcated catalog entry. Or some other unexpected checkpoint situation."); - assert.commandWorked(primary.adminCommand({fsync: 1})); - - // Crash and restart the primary, which should cause the old index data to be deleted before - // rebuilding the index from scratch. - rst.stop(primary, 9, {allowedExitCode: MongoRunner.EXIT_SIGKILL}); -} catch (error) { - // Turn off the failpoint before allowing the test to end, so nothing hangs while the server - // shuts down or in post-test hooks. - failPoint.off(); - throw error; -} finally { - if (ps) { - ps({checkExitSuccess: false}); - } -} - -// Restart the node and set 'noCleanData' so that the node's data doesn't get wiped out. -rst.start(primary, {noCleanData: true}); - -// Wait for the node to become available. -rst.getPrimary(); - -// For debugging purposes, fetch and log the test collection's indexes after restart. -const indexes = - assert.commandWorked(rst.getPrimary().getDB(dbName).runCommand({listIndexes: collName})) - .cursor.firstBatch; -jsTestLog("The node restarted with the following indexes on coll '" + collName + - "': " + tojson(indexes)); - -// Now that the node is up and running, check that the expected code path was hit, to immediately -// drop the index data table on startup. -checkLog.containsJson(rst.getPrimary(), 6361201, {index: "myFantasticalIndex"}); - -rst.stopSet(); -})(); diff --git a/jstests/noPassthrough/durable_history_index_usage.js b/jstests/noPassthrough/durable_history_index_usage.js index 0b32d7a717d..b2f7c01f6c5 100644 --- a/jstests/noPassthrough/durable_history_index_usage.js +++ b/jstests/noPassthrough/durable_history_index_usage.js @@ -109,13 +109,15 @@ replTest.start( true /* restart */); const checkLogs = function() { - // The index build was not yet completed at the recovery timestamp, it will be dropped and - // rebuilt. - checkLog.containsJson(primary(), 6361201, { + // Found index from unfinished build. + checkLog.containsJson(primary(), 22253, { index: "a_1", namespace: coll().getFullName(), }); + // Resetting unfinished index. + checkLog.containsJson(primary(), 6987700, {namespace: coll().getFullName(), index: "a_1"}); + // Index build restarting. checkLog.containsJson(primary(), 20660); }; diff --git a/jstests/noPassthrough/libs/missing_index_ident.js b/jstests/noPassthrough/libs/missing_index_ident.js index 74cb057ed38..3be61a404c2 100644 --- a/jstests/noPassthrough/libs/missing_index_ident.js +++ b/jstests/noPassthrough/libs/missing_index_ident.js @@ -76,8 +76,8 @@ const MissingIndexIdent = class { }); // Since the index build was not yet completed at the recovery timestamp, its ident will - // be dropped. - checkLog.containsJson(conn, 6361201, { + // be reset. + checkLog.containsJson(conn, 6987700, { index: 'a_1', namespace: coll.getFullName(), ident: ident, diff --git a/jstests/noPassthrough/missing_index_ident_standalone_drop.js b/jstests/noPassthrough/missing_index_ident_standalone_drop.js index abb59d5bf64..79a0a65230c 100644 --- a/jstests/noPassthrough/missing_index_ident_standalone_drop.js +++ b/jstests/noPassthrough/missing_index_ident_standalone_drop.js @@ -24,6 +24,12 @@ IndexBuildTest.assertIndexes(coll, 2, ['_id_', 'a_1']); assert.commandWorked(standalone.getDB('test')[jsTestName()].dropIndex('a_1')); IndexBuildTest.assertIndexes(coll, 1, ['_id_']); +// Completing drop for index table immediately. +checkLog.containsJson(standalone, 6361201, { + index: 'a_1', + namespace: coll.getFullName(), +}); + MongoRunner.stopMongod(standalone); replTest.start(0, undefined, true /* restart */); IndexBuildTest.assertIndexes(replTest.getPrimary().getDB('test')[jsTestName()], 1, ['_id_']); diff --git a/jstests/noPassthrough/unfinished_index_builds_restart_using_same_ident.js b/jstests/noPassthrough/unfinished_index_builds_restart_using_same_ident.js new file mode 100644 index 00000000000..919504b0600 --- /dev/null +++ b/jstests/noPassthrough/unfinished_index_builds_restart_using_same_ident.js @@ -0,0 +1,80 @@ +/** + * Tests that during startup recovery unfinished index builds that are not resumable will drop and + * recreate the index table using the same ident to avoid doing untimestamped writes to the catalog. + * + * @tags: [ + * requires_persistence, + * requires_replication, + * requires_wiredtiger, + * ] + */ +(function() { +"use strict"; + +load("jstests/libs/fail_point_util.js"); +load('jstests/noPassthrough/libs/index_build.js'); + +const replSet = new ReplSetTest({nodes: 1}); +replSet.startSet(); +replSet.initiate(); + +const dbName = "test"; +const collName = jsTestName(); + +let primary = replSet.getPrimary(); +let primaryDB = primary.getDB(dbName); +let primaryColl = primaryDB[collName]; + +assert.commandWorked(primaryDB.createCollection(collName)); +assert.commandWorked(primaryColl.insert({x: 1})); +assert.commandWorked(primaryColl.insert({x: 2})); +assert.commandWorked(primaryColl.insert({x: 3})); + +const failPoint = configureFailPoint(primaryDB, "hangIndexBuildBeforeCommit"); +const indexBuild = IndexBuildTest.startIndexBuild(primaryDB.getMongo(), + primaryColl.getFullName(), + {x: 1}, + {}, + [ErrorCodes.InterruptedAtShutdown]); +failPoint.wait(); + +// Get the index ident. +const ident = assert.commandWorked(primaryDB.runCommand({collStats: collName})) + .indexDetails.x_1.uri.substring('statistics:table:'.length); +jsTestLog("Ident: " + ident); + +// Take a checkpoint so that the unfinished index is present in the catalog during the next startup. +assert.commandWorked(primary.adminCommand({fsync: 1})); + +// Crash and restart the node. +replSet.stop(primary, 9, {allowedExitCode: MongoRunner.EXIT_SIGKILL}); +indexBuild({checkExitSuccess: false}); +replSet.start(primary, {noCleanData: true, setParameter: {logLevel: 1}}); + +primary = replSet.getPrimary(); +primaryDB = primary.getDB(dbName); +primaryColl = primaryDB[collName]; + +// Resetting unfinished index. +checkLog.containsJson( + primary, 6987700, {namespace: primaryColl.getFullName(), index: "x_1", ident: ident}); + +// WT drop. +checkLog.containsJson(primary, 22338, {uri: "table:" + ident}); + +// Create uri. +checkLog.containsJson(primary, 51780, {uri: "table:" + ident}); + +// Index build starting. +checkLog.containsJson(primary, 20384, {ident: ident}); + +IndexBuildTest.waitForIndexBuildToStop(primaryDB); +IndexBuildTest.assertIndexes(primaryColl, 2, ["_id_", "x_1"]); + +assert.commandWorked(primaryColl.insert({x: 4})); +assert.commandWorked(primaryColl.insert({x: 5})); + +assert.eq(5, primaryColl.find().hint("x_1").count()); + +replSet.stopSet(); +}()); |