diff options
author | Pol Pinol Castuera <pol.pinol@mongodb.com> | 2022-11-24 07:35:51 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-11-24 08:07:57 +0000 |
commit | ad2b7e93f1e05bc0512d93d03db45a4139e20bb2 (patch) | |
tree | f0e108c1e6fe31dc5aea131e1d7a47563eddec2b | |
parent | b75695e4e1d1b07c545f82ed31663dac248202cb (diff) | |
download | mongo-ad2b7e93f1e05bc0512d93d03db45a4139e20bb2.tar.gz |
SERVER-71477 Check '_internalAllCollectionStatsSpec.getStats()' exists before calling 'makeStatsForNs'
4 files changed, 17 insertions, 7 deletions
diff --git a/etc/backports_required_for_multiversion_tests.yml b/etc/backports_required_for_multiversion_tests.yml index bfb7da29e79..29c2514d579 100644 --- a/etc/backports_required_for_multiversion_tests.yml +++ b/etc/backports_required_for_multiversion_tests.yml @@ -274,6 +274,8 @@ last-continuous: ticket: SERVER-70436 - test_file: jstests/sharding/prepare_transaction_then_migrate.js ticket: SERVER-68361 + - test_file: jstests/sharding/all_collection_stats.js + ticket: SERVER-71477 suites: null last-lts: all: @@ -623,4 +625,6 @@ last-lts: ticket: SERVER-70436 - test_file: jstests/sharding/prepare_transaction_then_migrate.js ticket: SERVER-68361 + - test_file: jstests/sharding/all_collection_stats.js + ticket: SERVER-71477 suites: null diff --git a/jstests/sharding/all_collection_stats.js b/jstests/sharding/all_collection_stats.js index ac0207bda7b..62a725719cf 100644 --- a/jstests/sharding/all_collection_stats.js +++ b/jstests/sharding/all_collection_stats.js @@ -175,6 +175,10 @@ for (let i = numCollections / 2; i < numCollections; i++) { checkResults(outputData, checksToDo); })(); +// Test valid query with empty specification +assert.commandWorked( + adminDb.runCommand({aggregate: 1, pipeline: [{$_internalAllCollectionStats: {}}], cursor: {}})); + // Test invalid queries/values. assert.commandFailedWithCode( adminDb.runCommand({aggregate: 1, pipeline: [{$_internalAllCollectionStats: 3}], cursor: {}}), diff --git a/src/mongo/db/pipeline/document_source_internal_all_collection_stats.cpp b/src/mongo/db/pipeline/document_source_internal_all_collection_stats.cpp index 73782cd88c4..bbc07b66bc4 100644 --- a/src/mongo/db/pipeline/document_source_internal_all_collection_stats.cpp +++ b/src/mongo/db/pipeline/document_source_internal_all_collection_stats.cpp @@ -62,12 +62,14 @@ DocumentSource::GetNextResult DocumentSourceInternalAllCollectionStats::doGetNex continue; } - try { - return {Document{DocumentSourceCollStats::makeStatsForNs( - pExpCtx, nss, _internalAllCollectionStatsSpec.getStats().get(), _projectFilter)}}; - } catch (const ExceptionFor<ErrorCodes::CommandNotSupportedOnView>&) { - // We don't want to retrieve data for views, only for collections. - continue; + if (const auto& stats = _internalAllCollectionStatsSpec.getStats()) { + try { + return {Document{DocumentSourceCollStats::makeStatsForNs( + pExpCtx, nss, stats.get(), _projectFilter)}}; + } catch (const ExceptionFor<ErrorCodes::CommandNotSupportedOnView>&) { + // We don't want to retrieve data for views, only for collections. + continue; + } } } diff --git a/src/mongo/db/pipeline/document_source_internal_all_collection_stats.h b/src/mongo/db/pipeline/document_source_internal_all_collection_stats.h index 93b1556b94f..d9a081412f9 100644 --- a/src/mongo/db/pipeline/document_source_internal_all_collection_stats.h +++ b/src/mongo/db/pipeline/document_source_internal_all_collection_stats.h @@ -119,7 +119,7 @@ private: // The specification object given to $_internalAllCollectionStats containing user specified // options. - DocumentSourceInternalAllCollectionStatsSpec _internalAllCollectionStatsSpec; + const DocumentSourceInternalAllCollectionStatsSpec _internalAllCollectionStatsSpec; boost::optional<std::deque<BSONObj>> _catalogDocs; // A $match stage can be absorbed in order to avoid unnecessarily computing the stats for |