From d7bf13d97da047abfe9098a6b5f98678e89cd987 Mon Sep 17 00:00:00 2001 From: Cheahuychou Mao Date: Thu, 18 May 2023 00:17:48 +0000 Subject: SERVER-77247 Allow users to retry a configureQueryAnalyzer command to disable query sampling --- etc/backports_required_for_multiversion_tests.yml | 4 ++++ jstests/concurrency/fsm_workloads/analyze_shard_key.js | 6 +----- .../configure_query_analyzer_persistence.js | 13 ++++++------- src/mongo/db/s/configure_query_analyzer_cmd.cpp | 8 ++++---- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/etc/backports_required_for_multiversion_tests.yml b/etc/backports_required_for_multiversion_tests.yml index 4df96f221a8..c62a2241828 100644 --- a/etc/backports_required_for_multiversion_tests.yml +++ b/etc/backports_required_for_multiversion_tests.yml @@ -389,6 +389,8 @@ last-continuous: ticket: SERVER-76872 - test_file: jstests/sharding/resharding_update_tag_zones_large.js ticket: SERVER-76988 + - test_file: jstests/sharding/analyze_shard_key/configure_query_analyzer_persistence.js + ticket: SERVER-77247 suites: null last-lts: all: @@ -862,4 +864,6 @@ last-lts: ticket: SERVER-76872 - test_file: jstests/sharding/resharding_update_tag_zones_large.js ticket: SERVER-76988 + - test_file: jstests/sharding/analyze_shard_key/configure_query_analyzer_persistence.js + ticket: SERVER-77247 suites: null diff --git a/jstests/concurrency/fsm_workloads/analyze_shard_key.js b/jstests/concurrency/fsm_workloads/analyze_shard_key.js index dc6fa75d296..6e092338790 100644 --- a/jstests/concurrency/fsm_workloads/analyze_shard_key.js +++ b/jstests/concurrency/fsm_workloads/analyze_shard_key.js @@ -868,11 +868,7 @@ var $config = extendWorkload($config, function($config, $super) { $config.states.disableQuerySampling = function disableQuerySampling(db, collName) { print("Starting disableQuerySampling state"); const ns = db.getName() + "." + collName; - // If query sampling is off, this command is expected to fail with an IllegalOperation - // error. - assert.commandWorkedOrFailedWithCode( - db.adminCommand({configureQueryAnalyzer: ns, mode: "off"}), - ErrorCodes.IllegalOperation); + assert.commandWorked(db.adminCommand({configureQueryAnalyzer: ns, mode: "off"})); print("Finished disableQuerySampling state"); }; diff --git a/jstests/sharding/analyze_shard_key/configure_query_analyzer_persistence.js b/jstests/sharding/analyze_shard_key/configure_query_analyzer_persistence.js index 6ba1108021a..aba1408b8d1 100644 --- a/jstests/sharding/analyze_shard_key/configure_query_analyzer_persistence.js +++ b/jstests/sharding/analyze_shard_key/configure_query_analyzer_persistence.js @@ -73,10 +73,10 @@ function testPersistingConfiguration(conn) { tojson({dbName, collName, collUuid})}`); // Run a configureQueryAnalyzer command to disable query sampling. Verify that the command - // fails since query sampling is not even active. + // does not fail although query sampling is not even active. const mode0 = "off"; - assert.commandFailedWithCode(conn.adminCommand({configureQueryAnalyzer: ns, mode: mode0}), - ErrorCodes.IllegalOperation); + const res0 = assert.commandWorked(conn.adminCommand({configureQueryAnalyzer: ns, mode: mode0})); + assertConfigQueryAnalyzerResponse(res0, {mode: mode0} /* newConfig */); assertNoQueryAnalyzerConfigDoc(conn, ns); // Run a configureQueryAnalyzer command to enable query sampling. @@ -151,10 +151,9 @@ function testPersistingConfiguration(conn) { {mode: mode6} /* newConfig */, {mode: mode5, sampleRate: sampleRate5} /* oldConfig */); - // Retry the previous configureQueryAnalyzer command. Verify that the 'stopTime' remains the - // same. - assert.commandFailedWithCode(conn.adminCommand({configureQueryAnalyzer: ns, mode: mode6}), - ErrorCodes.IllegalOperation); + // Retry the previous configureQueryAnalyzer command. Verify that the retry does not fail and + // that the 'stopTime' remains the same. + assert.commandWorked(conn.adminCommand({configureQueryAnalyzer: ns, mode: mode6})); assertQueryAnalyzerConfigDoc( conn, ns, collUuid, mode6, sampleRate5, doc5.startTime, doc6.stopTime); } diff --git a/src/mongo/db/s/configure_query_analyzer_cmd.cpp b/src/mongo/db/s/configure_query_analyzer_cmd.cpp index b40c0d2396c..8719aca1de4 100644 --- a/src/mongo/db/s/configure_query_analyzer_cmd.cpp +++ b/src/mongo/db/s/configure_query_analyzer_cmd.cpp @@ -245,10 +245,10 @@ public: if (preImageDoc.getCollectionUuid() == collUuid) { response.setOldConfiguration(preImageDoc.getConfiguration()); } - } else { - uassert(ErrorCodes::IllegalOperation, - "Attempted to disable query sampling but query sampling was not active", - mode != QueryAnalyzerModeEnum::kOff); + } else if (mode != QueryAnalyzerModeEnum::kOff) { + LOGV2_WARNING( + 7724700, + "Attempted to disable query sampling but query sampling was not active"); } return response; -- cgit v1.2.1