summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPol Pinol Castuera <pol.pinol@mongodb.com>2022-11-24 07:37:20 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-11-24 08:09:16 +0000
commit1d72b538dd9696f14e01bec6589ee533cb0bee32 (patch)
tree5125256a32a94c7f864abbf2af6b93a1afcfcf89
parent9dc322154b1a1d6b3b5910843bbd87e690a46995 (diff)
downloadmongo-1d72b538dd9696f14e01bec6589ee533cb0bee32.tar.gz
SERVER-71477 Check '_internalAllCollectionStatsSpec.getStats()' exists before calling 'makeStatsForNs'
-rw-r--r--etc/backports_required_for_multiversion_tests.yml4
-rw-r--r--jstests/sharding/all_collection_stats.js4
-rw-r--r--src/mongo/db/pipeline/document_source_internal_all_collection_stats.cpp14
-rw-r--r--src/mongo/db/pipeline/document_source_internal_all_collection_stats.h2
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 e9f9dd4b5b4..662a66d0850 100644
--- a/etc/backports_required_for_multiversion_tests.yml
+++ b/etc/backports_required_for_multiversion_tests.yml
@@ -262,6 +262,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:
@@ -599,4 +601,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 00cdc639082..c08c42fe8b2 100644
--- a/jstests/sharding/all_collection_stats.js
+++ b/jstests/sharding/all_collection_stats.js
@@ -67,6 +67,10 @@ for (let i = 0; i < 20; i++) {
assert(exists);
}
+// 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 f37206dbafe..5763042df1f 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
@@ -61,12 +61,14 @@ DocumentSource::GetNextResult DocumentSourceInternalAllCollectionStats::doGetNex
continue;
}
- try {
- return {Document{DocumentSourceCollStats::makeStatsForNs(
- pExpCtx, nss, _internalAllCollectionStatsSpec.getStats().get())}};
- } 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())}};
+ } 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 491b6354c3f..1779ee36dec 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