diff options
author | Tyler Brock <tyler.brock@gmail.com> | 2023-01-30 16:10:19 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-01-30 16:37:53 +0000 |
commit | 58a2c8137cc2abfdf2bf274d2cc9aee645f9f519 (patch) | |
tree | 7e33c5bbec8de35e94b12cf3297ff4f02c75fcd9 | |
parent | 825af07e91f65f3f65fb15b54380eeee67b7510e (diff) | |
download | mongo-58a2c8137cc2abfdf2bf274d2cc9aee645f9f519.tar.gz |
SERVER-72620 ensure shard added to $indexStats for unsharded collections
4 files changed, 12 insertions, 8 deletions
diff --git a/etc/backports_required_for_multiversion_tests.yml b/etc/backports_required_for_multiversion_tests.yml index 528a0a202d6..9205d9f93b3 100644 --- a/etc/backports_required_for_multiversion_tests.yml +++ b/etc/backports_required_for_multiversion_tests.yml @@ -90,6 +90,8 @@ last-continuous: ticket: SERVER-68728 - test_file: jstests/sharding/move_chunk_concurrent_cloning.js ticket: SERVER-68648 + - test_file: jstests/sharding/timeseries_cluster_indexstats.js + ticket: SERVER-72620 suites: change_streams_multiversion_passthrough: null change_streams_sharded_collections_multiversion_passthrough: null @@ -277,6 +279,8 @@ last-lts: ticket: SERVER-68728 - test_file: jstests/sharding/move_chunk_concurrent_cloning.js ticket: SERVER-68648 + - test_file: jstests/sharding/timeseries_cluster_indexstats.js + ticket: SERVER-72620 suites: change_streams_multiversion_passthrough: null change_streams_sharded_collections_multiversion_passthrough: null diff --git a/jstests/aggregation/sources/indexStats/verify_index_stats_output.js b/jstests/aggregation/sources/indexStats/verify_index_stats_output.js index 0b2dbeba8f9..15cc007672d 100644 --- a/jstests/aggregation/sources/indexStats/verify_index_stats_output.js +++ b/jstests/aggregation/sources/indexStats/verify_index_stats_output.js @@ -69,6 +69,7 @@ let shardsFound = []; db.getSiblingDB("config").shards.find().forEach(function(shard) { allShards.push(shard._id); }); +const isShardedCluster = !!allShards.length; for (const indexStats of pausedOutput) { assert.hasFields(indexStats, ["building", "spec"]); @@ -84,6 +85,8 @@ for (const indexStats of pausedOutput) { // names of known shards. if (indexStats.hasOwnProperty("shard")) { shardsFound.push(indexStats["shard"]); + } else { + assert(!isShardedCluster); } } diff --git a/jstests/sharding/timeseries_cluster_indexstats.js b/jstests/sharding/timeseries_cluster_indexstats.js index d20df38c47a..1f8c86afd40 100644 --- a/jstests/sharding/timeseries_cluster_indexstats.js +++ b/jstests/sharding/timeseries_cluster_indexstats.js @@ -65,13 +65,7 @@ function checkIndexStats(coll, keys, sharded) { keys.length, `There should be ${keys.length} indices on the collection.\n${tojson(indices)}`); indices.forEach((index, i) => { - assert.eq(index.hasOwnProperty('shard'), - sharded, - sharded - ? `Index stats 'shard' field should exist on a sharded collection.\n${ - tojson(index)}` - : `Index stats 'shard' field should not exist on a non-sharded collection.\n${ - tojson(index)}`); + assert(index.hasOwnProperty('shard'), tojson(index)); assert.docEq( index.key, keys[i], `Index should have key spec ${tojson(keys[i])}.\n${tojson(index)}`); }); diff --git a/src/mongo/db/pipeline/document_source_index_stats.cpp b/src/mongo/db/pipeline/document_source_index_stats.cpp index e87b614e59a..139fdde3bca 100644 --- a/src/mongo/db/pipeline/document_source_index_stats.cpp +++ b/src/mongo/db/pipeline/document_source_index_stats.cpp @@ -51,7 +51,10 @@ const char* DocumentSourceIndexStats::getSourceName() const { DocumentSource::GetNextResult DocumentSourceIndexStats::doGetNext() { if (_indexStats.empty()) { _indexStats = pExpCtx->mongoProcessInterface->getIndexStats( - pExpCtx->opCtx, pExpCtx->ns, _processName, pExpCtx->fromMongos); + pExpCtx->opCtx, + pExpCtx->ns, + _processName, + serverGlobalParams.clusterRole != ClusterRole::None); _indexStatsIter = _indexStats.cbegin(); } |