diff options
author | Suganthi Mani <suganthi.mani@mongodb.com> | 2020-03-25 11:24:28 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-04-15 18:08:53 +0000 |
commit | cead747b708c560c8487bf04051f554cceaea334 (patch) | |
tree | 62fce5cdbd537f2155b87b7aa5ce5ef6015a2750 /jstests | |
parent | 1067844167dec31e3a379ce0b63522e43e029c96 (diff) | |
download | mongo-cead747b708c560c8487bf04051f554cceaea334.tar.gz |
SERVER-46557 Guarantees the commit quorum value gets persisted before start of the index build.
(cherry picked from commit 4c41ed37fd58c4e4d4d2707f63f797f23ff9b486)
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/replsets/primary_restart_before_index_build_received_votes.js | 64 | ||||
-rw-r--r-- | jstests/replsets/primary_rollbacks_before_index_build_received_votes.js | 63 |
2 files changed, 127 insertions, 0 deletions
diff --git a/jstests/replsets/primary_restart_before_index_build_received_votes.js b/jstests/replsets/primary_restart_before_index_build_received_votes.js new file mode 100644 index 00000000000..84c4914c10e --- /dev/null +++ b/jstests/replsets/primary_restart_before_index_build_received_votes.js @@ -0,0 +1,64 @@ +/* + * Tests that primary retains commit quorum provided to createIndexes across restarts. + * @tags: [requires_persistence] + */ +(function() { + +"use strict"; +load("jstests/replsets/rslib.js"); +load('jstests/noPassthrough/libs/index_build.js'); + +const rst = new ReplSetTest({nodes: [{}, {rsConfig: {priority: 0}}]}); +rst.startSet(); +rst.initiate(); + +const dbName = jsTest.name(); +const collName = "coll"; + +let primary = rst.getPrimary(); +let primaryDB = primary.getDB(dbName); +const primaryColl = primaryDB[collName]; +const collNss = primaryColl.getFullName(); +const secondary = rst.getSecondary(); +const secondaryDB = secondary.getDB(dbName); + +jsTestLog("Do a document write."); +assert.commandWorked( + primaryColl.insert({_id: 0, x: 0}, {"writeConcern": {"w": "majority"}})); +rst.awaitReplication(); + +// This makes sure the index build on primary hangs before receiving any votes from itself and +// secondary. +IndexBuildTest.pauseIndexBuilds(secondary); +IndexBuildTest.pauseIndexBuilds(primary); + +jsTestLog("Start index build."); +const awaitBuild = IndexBuildTest.startIndexBuild( + primary, collNss, {i: 1}, {}, [ErrorCodes.InterruptedDueToReplStateChange]); + +jsTestLog("Wait for secondary to reach collection scan phase."); +IndexBuildTest.waitForIndexBuildToScanCollection(secondaryDB, collName, 'i_1'); + +jsTestLog("Wait for primary to reach collection scan phase."); +IndexBuildTest.waitForIndexBuildToScanCollection(primaryDB, collName, 'i_1'); + +jsTestLog("Restarting the primary"); +rst.stop(primary, undefined, {skipValidation: true}); +rst.start(primary, {}, true); + +jsTestLog("Wait for primary to get re-elected."); +primary = rst.getPrimary(); +primaryDB = primary.getDB(dbName); + +awaitBuild(); + +jsTestLog("Resume index build on secondary."); +IndexBuildTest.resumeIndexBuilds(secondary); +IndexBuildTest.waitForIndexBuildToStop(primaryDB, collName, "i_1"); +rst.awaitReplication(); + +// Check to see if the index was successfully created. +IndexBuildTest.assertIndexes(primaryDB[collName], 2, ['_id_', 'i_1']); + +rst.stopSet(); +})(); diff --git a/jstests/replsets/primary_rollbacks_before_index_build_received_votes.js b/jstests/replsets/primary_rollbacks_before_index_build_received_votes.js new file mode 100644 index 00000000000..80508a1ad40 --- /dev/null +++ b/jstests/replsets/primary_rollbacks_before_index_build_received_votes.js @@ -0,0 +1,63 @@ +/* + * Test that primary rollbacks before receiving any votes from the replica set should not + * make createIndexes command's commit quorum value to be lost. + */ +(function() { + +"use strict"; + +load("jstests/replsets/libs/rollback_test.js"); +load('jstests/noPassthrough/libs/index_build.js'); + +const dbName = jsTest.name(); +const collName = "coll"; + +const rollbackTest = new RollbackTest(dbName); +let primary = rollbackTest.getPrimary(); +let primaryDB = primary.getDB(dbName); +const primaryColl = primaryDB[collName]; +const collNss = primaryColl.getFullName(); + +const secondary = rollbackTest.getSecondary(); +const secondaryDB = secondary.getDB(dbName); + +jsTestLog("Do a document write."); +assert.commandWorked( + primaryColl.insert({_id: 0, x: 0}, {"writeConcern": {"w": "majority"}})); + +// This makes sure the index build on primary hangs before receiving any votes from itself and +// secondary. +IndexBuildTest.pauseIndexBuilds(secondary); +IndexBuildTest.pauseIndexBuilds(primary); + +jsTestLog("Start index build."); +const awaitBuild = IndexBuildTest.startIndexBuild( + primary, collNss, {i: 1}, {}, [ErrorCodes.InterruptedDueToReplStateChange]); + +jsTestLog("Wait for secondary to reach collection scan phase."); +IndexBuildTest.waitForIndexBuildToScanCollection(secondaryDB, collName, 'i_1'); + +jsTestLog("Wait for primary to reach collection scan phase."); +IndexBuildTest.waitForIndexBuildToScanCollection(primaryDB, collName, 'i_1'); + +rollbackTest.transitionToRollbackOperations(); +rollbackTest.transitionToSyncSourceOperationsBeforeRollback(); +rollbackTest.transitionToSyncSourceOperationsDuringRollback(); + +jsTestLog("Resume index builds."); +IndexBuildTest.resumeIndexBuilds(secondary); +IndexBuildTest.resumeIndexBuilds(primary); + +let newPrimary = rollbackTest.getPrimary(); +let newPrimaryDB = newPrimary.getDB(dbName); +IndexBuildTest.waitForIndexBuildToStop(newPrimaryDB, collName, "i_1"); + +rollbackTest.transitionToSteadyStateOperations(); + +awaitBuild(); + +// check to see if the index was successfully created. +IndexBuildTest.assertIndexes(newPrimaryDB[collName], 2, ['_id_', 'i_1']); + +rollbackTest.stop(); +})(); |