From 37d7d7041acf6bd7d32323ca84668061cdb1147b Mon Sep 17 00:00:00 2001 From: Gregory Wlodarek Date: Mon, 1 Nov 2021 14:45:28 +0000 Subject: SERVER-60179 The 'validate' command should return 'InvalidOptions' instead of 'CommandNotSupported' for incompatible options --- jstests/noPassthrough/background_validation_repl.js | 2 +- .../noPassthrough/validate_detects_invalid_index_options.js | 8 ++++---- jstests/noPassthroughWithMongod/background_validation.js | 2 +- src/mongo/db/commands/validate.cpp | 12 ++++++------ 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/jstests/noPassthrough/background_validation_repl.js b/jstests/noPassthrough/background_validation_repl.js index 8d3eb39e8f2..673e7e79a2c 100644 --- a/jstests/noPassthrough/background_validation_repl.js +++ b/jstests/noPassthrough/background_validation_repl.js @@ -60,7 +60,7 @@ const doTest = replSet => { * Ensure {full:true} and {background:true} cannot be run together. */ assert.commandFailedWithCode(testColl.validate({background: true, full: true}), - ErrorCodes.CommandNotSupported); + ErrorCodes.InvalidOptions); assert.commandWorked(testDB.adminCommand({fsync: 1})); diff --git a/jstests/noPassthrough/validate_detects_invalid_index_options.js b/jstests/noPassthrough/validate_detects_invalid_index_options.js index c8a3e495bb0..98ae6130209 100644 --- a/jstests/noPassthrough/validate_detects_invalid_index_options.js +++ b/jstests/noPassthrough/validate_detects_invalid_index_options.js @@ -43,14 +43,14 @@ checkLog.containsJson(conn, 5980501); // foreground validation on the ephemeralForTest storage engine, making it incompatible with this // test. assert.commandFailedWithCode(db.runCommand({validate: collName, metadata: true, background: true}), - ErrorCodes.CommandNotSupported); + ErrorCodes.InvalidOptions); assert.commandFailedWithCode(db.runCommand({validate: collName, metadata: true, repair: true}), - ErrorCodes.CommandNotSupported); + ErrorCodes.InvalidOptions); assert.commandFailedWithCode(db.runCommand({validate: collName, metadata: true, full: true}), - ErrorCodes.CommandNotSupported); + ErrorCodes.InvalidOptions); assert.commandFailedWithCode( db.runCommand({validate: collName, metadata: true, enforceFastCount: true}), - ErrorCodes.CommandNotSupported); + ErrorCodes.InvalidOptions); // Drop the index with the invalid index options and validate only the metadata. assert.commandWorked(coll.dropIndex({x: 1})); diff --git a/jstests/noPassthroughWithMongod/background_validation.js b/jstests/noPassthroughWithMongod/background_validation.js index dfb9a0aa05e..c47ee69c154 100644 --- a/jstests/noPassthroughWithMongod/background_validation.js +++ b/jstests/noPassthroughWithMongod/background_validation.js @@ -41,7 +41,7 @@ for (let i = 0; i < numDocs; ++i) { * Ensure {full:true} and {background:true} cannot be run together. */ assert.commandFailedWithCode(testColl.validate({background: true, full: true}), - ErrorCodes.CommandNotSupported); + ErrorCodes.InvalidOptions); forceCheckpoint(); diff --git a/src/mongo/db/commands/validate.cpp b/src/mongo/db/commands/validate.cpp index f00ed058f94..fb494ab74eb 100644 --- a/src/mongo/db/commands/validate.cpp +++ b/src/mongo/db/commands/validate.cpp @@ -135,33 +135,33 @@ public: const bool fullValidate = cmdObj["full"].trueValue(); if (background && fullValidate) { - uasserted(ErrorCodes::CommandNotSupported, + uasserted(ErrorCodes::InvalidOptions, str::stream() << "Running the validate command with both { background: true }" << " and { full: true } is not supported."); } const bool enforceFastCount = cmdObj["enforceFastCount"].trueValue(); if (background && enforceFastCount) { - uasserted(ErrorCodes::CommandNotSupported, + uasserted(ErrorCodes::InvalidOptions, str::stream() << "Running the validate command with both { background: true }" << " and { enforceFastCount: true } is not supported."); } const bool repair = cmdObj["repair"].trueValue(); if (background && repair) { - uasserted(ErrorCodes::CommandNotSupported, + uasserted(ErrorCodes::InvalidOptions, str::stream() << "Running the validate command with both {background: true }" << " and { repair: true } is not supported."); } if (enforceFastCount && repair) { - uasserted(ErrorCodes::CommandNotSupported, + uasserted(ErrorCodes::InvalidOptions, str::stream() << "Running the validate command with both {enforceFastCount: true }" << " and { repair: true } is not supported."); } repl::ReplicationCoordinator* replCoord = repl::ReplicationCoordinator::get(opCtx); if (repair && replCoord->isReplEnabled()) { - uasserted(ErrorCodes::CommandNotSupported, + uasserted(ErrorCodes::InvalidOptions, str::stream() << "Running the validate command with { repair: true } can only be" << " performed in standalone mode."); @@ -169,7 +169,7 @@ public: const bool metadata = cmdObj["metadata"].trueValue(); if (metadata && (background || fullValidate || enforceFastCount || repair)) { - uasserted(ErrorCodes::CommandNotSupported, + uasserted(ErrorCodes::InvalidOptions, str::stream() << "Running the validate command with { metadata: true } is not" << " supported with any other options"); } -- cgit v1.2.1