diff options
author | Tyler Brock <tyler.brock@gmail.com> | 2023-01-30 16:10:40 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-01-30 16:49:36 +0000 |
commit | 909bf6415431b6260dec1baedcd799c27626039c (patch) | |
tree | a9b580ebfd5b1dbf6c54d7d7a56687f0fc5f25a6 | |
parent | 062a33ddfec03e7d3707d81809ea75aeacba93e1 (diff) | |
download | mongo-909bf6415431b6260dec1baedcd799c27626039c.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 542be21bf8e..4ce9d53b0d0 100644 --- a/etc/backports_required_for_multiversion_tests.yml +++ b/etc/backports_required_for_multiversion_tests.yml @@ -244,6 +244,8 @@ last-continuous: ticket: SERVER-72422 - test_file: jstests/sharding/move_chunk_concurrent_cloning.js ticket: SERVER-68648 + - test_file: jstests/sharding/timeseries_cluster_indexstats.js + ticket: SERVER-72620 suites: null last-lts: all: @@ -565,4 +567,6 @@ last-lts: ticket: SERVER-72422 - test_file: jstests/sharding/move_chunk_concurrent_cloning.js ticket: SERVER-68648 + - test_file: jstests/sharding/timeseries_cluster_indexstats.js + ticket: SERVER-72620 suites: 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 f734d8b03b4..5c480cdf65f 100644 --- a/jstests/sharding/timeseries_cluster_indexstats.js +++ b/jstests/sharding/timeseries_cluster_indexstats.js @@ -59,13 +59,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(); } |