diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
| commit | 4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch) | |
| tree | 1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/db/pipeline/document_source_coll_stats.cpp | |
| parent | aa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff) | |
| parent | 8f0827553e09872941945a093b647a4211a9db7f (diff) | |
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0'
with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/db/pipeline/document_source_coll_stats.cpp')
| -rw-r--r-- | src/mongo/db/pipeline/document_source_coll_stats.cpp | 61 |
1 files changed, 26 insertions, 35 deletions
diff --git a/src/mongo/db/pipeline/document_source_coll_stats.cpp b/src/mongo/db/pipeline/document_source_coll_stats.cpp index a947f1589e6..c00f5fcd44d 100644 --- a/src/mongo/db/pipeline/document_source_coll_stats.cpp +++ b/src/mongo/db/pipeline/document_source_coll_stats.cpp @@ -71,15 +71,18 @@ intrusive_ptr<DocumentSource> DocumentSourceCollStats::createFromBson( return make_intrusive<DocumentSourceCollStats>(pExpCtx, std::move(spec)); } -BSONObj DocumentSourceCollStats::makeStatsForNs( - const boost::intrusive_ptr<ExpressionContext>& expCtx, - const NamespaceString& nss, - const DocumentSourceCollStatsSpec& spec) { +DocumentSource::GetNextResult DocumentSourceCollStats::doGetNext() { + if (_finished) { + return GetNextResult::makeEOF(); + } + + _finished = true; + BSONObjBuilder builder; - builder.append("ns", nss.ns()); + builder.append("ns", pExpCtx->ns.ns()); - auto shardName = expCtx->mongoProcessInterface->getShardName(expCtx->opCtx); + auto shardName = pExpCtx->mongoProcessInterface->getShardName(pExpCtx->opCtx); if (!shardName.empty()) { builder.append("shard", shardName); @@ -88,49 +91,37 @@ BSONObj DocumentSourceCollStats::makeStatsForNs( builder.append("host", getHostNameCachedAndPort()); builder.appendDate("localTime", jsTime()); - if (auto latencyStatsSpec = spec.getLatencyStats()) { - // getRequestOnTimeseriesView is set to true if collstats is called on the view. - auto resolvedNss = - spec.getRequestOnTimeseriesView() ? nss.getTimeseriesViewNamespace() : nss; - expCtx->mongoProcessInterface->appendLatencyStats( - expCtx->opCtx, resolvedNss, latencyStatsSpec->getHistograms(), &builder); + if (auto latencyStatsSpec = _collStatsSpec.getLatencyStats()) { + pExpCtx->mongoProcessInterface->appendLatencyStats( + pExpCtx->opCtx, pExpCtx->ns, latencyStatsSpec->getHistograms(), &builder); } - if (auto storageStats = spec.getStorageStats()) { + if (auto storageStats = _collStatsSpec.getStorageStats()) { // If the storageStats field exists, it must have been validated as an object when parsing. BSONObjBuilder storageBuilder(builder.subobjStart("storageStats")); - uassertStatusOKWithContext(expCtx->mongoProcessInterface->appendStorageStats( - expCtx->opCtx, nss, *storageStats, &storageBuilder), + uassertStatusOKWithContext(pExpCtx->mongoProcessInterface->appendStorageStats( + pExpCtx->opCtx, pExpCtx->ns, *storageStats, &storageBuilder), "Unable to retrieve storageStats in $collStats stage"); storageBuilder.doneFast(); } - if (spec.getCount()) { - uassertStatusOKWithContext( - expCtx->mongoProcessInterface->appendRecordCount(expCtx->opCtx, nss, &builder), - "Unable to retrieve count in $collStats stage"); + if (_collStatsSpec.getCount()) { + uassertStatusOKWithContext(pExpCtx->mongoProcessInterface->appendRecordCount( + pExpCtx->opCtx, pExpCtx->ns, &builder), + "Unable to retrieve count in $collStats stage"); } - if (spec.getQueryExecStats()) { - uassertStatusOKWithContext( - expCtx->mongoProcessInterface->appendQueryExecStats(expCtx->opCtx, nss, &builder), - "Unable to retrieve queryExecStats in $collStats stage"); + if (_collStatsSpec.getQueryExecStats()) { + uassertStatusOKWithContext(pExpCtx->mongoProcessInterface->appendQueryExecStats( + pExpCtx->opCtx, pExpCtx->ns, &builder), + "Unable to retrieve queryExecStats in $collStats stage"); } - return builder.obj(); -} - -DocumentSource::GetNextResult DocumentSourceCollStats::doGetNext() { - if (_finished) { - return GetNextResult::makeEOF(); - } - - _finished = true; - return {Document(makeStatsForNs(pExpCtx, pExpCtx->ns, _collStatsSpec))}; + return {Document(builder.obj())}; } -Value DocumentSourceCollStats::serialize(const SerializationOptions& opts) const { - return Value(Document{{getSourceName(), _collStatsSpec.toBSON(opts)}}); +Value DocumentSourceCollStats::serialize(boost::optional<ExplainOptions::Verbosity> explain) const { + return Value(Document{{getSourceName(), _collStatsSpec.toBSON()}}); } } // namespace mongo |
