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:
parent
108425fdd0
commit
1a3936b3ee
@ -79,6 +79,9 @@ node = rst.start(node, {noReplSet: true, setParameter: {logComponentVerbosity: l
|
|||||||
reconnect(node);
|
reconnect(node);
|
||||||
assertDocsInColl(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.");
|
jsTestLog("Test that on restart with the flag set we play recovery.");
|
||||||
node = rst.restart(node, {
|
node = rst.restart(node, {
|
||||||
noReplSet: true,
|
noReplSet: true,
|
||||||
@ -87,6 +90,9 @@ node = rst.restart(node, {
|
|||||||
reconnect(node);
|
reconnect(node);
|
||||||
assertDocsInColl(node, [3, 4, 5]);
|
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.");
|
jsTestLog("Test that we go into read-only mode.");
|
||||||
assert.commandFailedWithCode(getColl(node).insert({_id: 1}), ErrorCodes.IllegalOperation);
|
assert.commandFailedWithCode(getColl(node).insert({_id: 1}), ErrorCodes.IllegalOperation);
|
||||||
|
|
||||||
|
38
jstests/replsets/validate_fails_during_rollback.js
Normal file
38
jstests/replsets/validate_fails_during_rollback.js
Normal 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();
|
||||||
|
}());
|
@ -397,6 +397,12 @@ Status validate(OperationContext* opCtx,
|
|||||||
// constructor fail the cmd, as opposed to returning OK with valid:false.
|
// constructor fail the cmd, as opposed to returning OK with valid:false.
|
||||||
ValidateState validateState(opCtx, nss, background, fullValidate);
|
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 {
|
try {
|
||||||
std::map<std::string, int64_t> numIndexKeysPerIndex;
|
std::map<std::string, int64_t> numIndexKeysPerIndex;
|
||||||
ValidateResultsMap indexNsResultsMap;
|
ValidateResultsMap indexNsResultsMap;
|
||||||
|
@ -97,6 +97,10 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool maintenanceOk() const override {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
virtual void addRequiredPrivileges(const std::string& dbname,
|
virtual void addRequiredPrivileges(const std::string& dbname,
|
||||||
const BSONObj& cmdObj,
|
const BSONObj& cmdObj,
|
||||||
std::vector<Privilege>* out) const {
|
std::vector<Privilege>* out) const {
|
||||||
|
Loading…
Reference in New Issue
Block a user