summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCheahuychou Mao <mao.cheahuychou@gmail.com>2023-05-02 21:08:36 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-05-02 22:25:18 +0000
commit19b39ff97b7861e789a6fb9ba406329a8d7e31d2 (patch)
treeb4c4830913105fd5176464c7ec5bd4150fd3668f
parent5cbb7581f7421f9ed04fb9e6812d72a2856008d2 (diff)
downloadmongo-19b39ff97b7861e789a6fb9ba406329a8d7e31d2.tar.gz
SERVER-76756 Make analyzeShardKey hook and concurrency workload ignore error thrown when analyzeShardKey command failed to look up documents for hashed shard key
-rw-r--r--jstests/concurrency/fsm_workloads/analyze_shard_key.js6
-rw-r--r--jstests/hooks/run_analyze_shard_key_background.js7
-rw-r--r--src/mongo/db/s/analyze_shard_key_cmd_util.cpp16
3 files changed, 22 insertions, 7 deletions
diff --git a/jstests/concurrency/fsm_workloads/analyze_shard_key.js b/jstests/concurrency/fsm_workloads/analyze_shard_key.js
index e3cfcec55f7..3d1a93a73cb 100644
--- a/jstests/concurrency/fsm_workloads/analyze_shard_key.js
+++ b/jstests/concurrency/fsm_workloads/analyze_shard_key.js
@@ -603,6 +603,12 @@ var $config = extendWorkload($config, function($config, $super) {
`point documents after the TTL deletions had started. ${tojsononeline(err)}`);
return true;
}
+ if (err.code == 7588600) {
+ print(`Failed to analyze the shard key because the document for one of the most ` +
+ `common shard key values got deleted while the command was running. ${
+ tojsononeline(err)}`);
+ return err;
+ }
return false;
};
diff --git a/jstests/hooks/run_analyze_shard_key_background.js b/jstests/hooks/run_analyze_shard_key_background.js
index 945d449acaa..b752de1902b 100644
--- a/jstests/hooks/run_analyze_shard_key_background.js
+++ b/jstests/hooks/run_analyze_shard_key_background.js
@@ -206,7 +206,12 @@ function analyzeShardKey(ns, shardKey, indexKey) {
}
if (res.code == 7559401) {
print(`Failed to analyze the shard key because one of the shards fetched the split ` +
- `point documents after the TTL deletions had started. ${tojsononeline(err)}`);
+ `point documents after the TTL deletions had started. ${tojsononeline(res)}`);
+ return res;
+ }
+ if (res.code == 7588600) {
+ print(`Failed to analyze the shard key because the document for one of the most common ` +
+ `shard key values got deleted while the command was running. ${tojsononeline(res)}`);
return res;
}
diff --git a/src/mongo/db/s/analyze_shard_key_cmd_util.cpp b/src/mongo/db/s/analyze_shard_key_cmd_util.cpp
index 9a3c960d598..be0c7262471 100644
--- a/src/mongo/db/s/analyze_shard_key_cmd_util.cpp
+++ b/src/mongo/db/s/analyze_shard_key_cmd_util.cpp
@@ -496,15 +496,19 @@ CardinalityFrequencyMetrics calculateCardinalityAndFrequencyGeneric(OperationCon
}
auto value = [&] {
+ if (doc.hasField(kIndexKeyFieldName)) {
+ return dotted_path_support::extractElementsBasedOnTemplate(
+ doc.getObjectField(kIndexKeyFieldName).replaceFieldNames(shardKey), shardKey);
+ }
if (doc.hasField(kDocFieldName)) {
return dotted_path_support::extractElementsBasedOnTemplate(
doc.getObjectField(kDocFieldName), shardKey);
- } else if (doc.hasField(kIndexKeyFieldName)) {
- return dotted_path_support::extractElementsBasedOnTemplate(
- doc.getObjectField(kIndexKeyFieldName).replaceFieldNames(shardKey), shardKey);
- } else
- uasserted(7588600,
- str::stream() << "Found a document with unexpected format " << doc);
+ }
+ uasserted(7588600,
+ str::stream() << "Failed to look up documents for most common shard key "
+ "values. This is likely caused by concurrent deletions. "
+ "Please try running the analyzeShardKey command again. "
+ << doc);
}();
if (value.objsize() > maxSizeBytesPerValue) {
value = truncateBSONObj(value, maxSizeBytesPerValue);