0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

SERVER-42312 disallow validate cmd during rollback and recovering states

This commit is contained in:
Pavithra Vetriselvan 2019-09-24 18:43:38 +00:00 committed by evergreen
parent 108425fdd0
commit 1a3936b3ee
4 changed files with 54 additions and 0 deletions

View File

@ -79,6 +79,9 @@ node = rst.start(node, {noReplSet: true, setParameter: {logComponentVerbosity: l
reconnect(node);
assertDocsInColl(node, []);
// Test that we can run the validate command on a standalone.
assert.commandWorked(node.getDB(dbName).runCommand({"validate": collName}));
jsTestLog("Test that on restart with the flag set we play recovery.");
node = rst.restart(node, {
noReplSet: true,
@ -87,6 +90,9 @@ node = rst.restart(node, {
reconnect(node);
assertDocsInColl(node, [3, 4, 5]);
// Test that we can run the validate command on a standalone that recovered.
assert.commandWorked(node.getDB(dbName).runCommand({"validate": collName}));
jsTestLog("Test that we go into read-only mode.");
assert.commandFailedWithCode(getColl(node).insert({_id: 1}), ErrorCodes.IllegalOperation);

View File

@ -0,0 +1,38 @@
/*
* This test makes sure the 'validate' command fails correctly during rollback.
*/
(function() {
"use strict";
load("jstests/replsets/libs/rollback_test.js");
const dbName = "test";
const collName = "coll";
// Set up Rollback Test.
let rollbackTest = new RollbackTest();
let rollbackNode = rollbackTest.transitionToRollbackOperations();
assert.commandWorked(rollbackNode.adminCommand(
{configureFailPoint: "rollbackHangAfterTransitionToRollback", mode: "alwaysOn"}));
// Start rollback.
rollbackTest.transitionToSyncSourceOperationsBeforeRollback();
rollbackTest.transitionToSyncSourceOperationsDuringRollback();
// Wait for rollback to hang.
checkLog.contains(rollbackNode, "rollbackHangAfterTransitionToRollback fail point enabled.");
// Try to run the validate command on the rollback node. This should fail with a NotMaster error.
assert.commandFailedWithCode(rollbackNode.getDB(dbName).runCommand({"validate": collName}),
ErrorCodes.NotMasterOrSecondary);
assert.commandWorked(rollbackNode.adminCommand(
{configureFailPoint: "rollbackHangAfterTransitionToRollback", mode: "off"}));
rollbackTest.transitionToSteadyStateOperations();
// Check the replica set.
rollbackTest.stop();
}());

View File

@ -397,6 +397,12 @@ Status validate(OperationContext* opCtx,
// constructor fail the cmd, as opposed to returning OK with valid:false.
ValidateState validateState(opCtx, nss, background, fullValidate);
const auto replCoord = repl::ReplicationCoordinator::get(opCtx);
// Check whether we are allowed to read from this node after acquiring our locks. If we are
// in a state where we cannot read, we should not run validate.
uassertStatusOK(replCoord->checkCanServeReadsFor(
opCtx, nss, ReadPreferenceSetting::get(opCtx).canRunOnSecondary()));
try {
std::map<std::string, int64_t> numIndexKeysPerIndex;
ValidateResultsMap indexNsResultsMap;

View File

@ -97,6 +97,10 @@ public:
return true;
}
bool maintenanceOk() const override {
return false;
}
virtual void addRequiredPrivileges(const std::string& dbname,
const BSONObj& cmdObj,
std::vector<Privilege>* out) const {