diff options
Diffstat (limited to 'src/mongo/db/clientcursor.h')
| -rw-r--r-- | src/mongo/db/clientcursor.h | 90 |
1 files changed, 24 insertions, 66 deletions
diff --git a/src/mongo/db/clientcursor.h b/src/mongo/db/clientcursor.h index 6ac10c21d86..0724c49d4dd 100644 --- a/src/mongo/db/clientcursor.h +++ b/src/mongo/db/clientcursor.h @@ -29,7 +29,6 @@ #pragma once -#include "mongo/bson/bsonobj.h" #include <boost/optional.hpp> #include <functional> @@ -37,7 +36,6 @@ #include "mongo/db/api_parameters.h" #include "mongo/db/auth/privilege.h" #include "mongo/db/auth/user_name.h" -#include "mongo/db/curop.h" #include "mongo/db/cursor_id.h" #include "mongo/db/jsobj.h" #include "mongo/db/logical_session_id.h" @@ -162,13 +160,6 @@ public: ReadPreferenceSetting getReadPreferenceSetting() const { return _readPreferenceSetting; } - bool getQueryStatsWillNeverExhaust() const { - return _queryStatsWillNeverExhaust; - } - - std::unique_ptr<query_stats::Key> takeKey() { - return std::move(_queryStatsKey); - } /** * Returns a pointer to the underlying query plan executor. All cursors manage a PlanExecutor, @@ -214,28 +205,29 @@ public: * Increments the cursor's tracked number of query results returned so far by 'n'. */ void incNReturnedSoFar(std::uint64_t n) { - _metrics.incrementNreturned(n); + _nReturnedSoFar += n; } - void incrementCursorMetrics(OpDebug::AdditiveMetrics newMetrics) { - _metrics.add(newMetrics); - if (!_firstResponseExecutionTime) { - _firstResponseExecutionTime = _metrics.executionTime; - } + /** + * Sets the cursor's tracked number of query results returned so far to 'n'. + */ + void setNReturnedSoFar(std::uint64_t n) { + invariant(n >= _nReturnedSoFar); + _nReturnedSoFar = n; } /** * Returns the number of batches returned by this cursor so far. */ std::uint64_t getNBatches() const { - return _metrics.nBatches.value_or(0); + return _nBatchesReturned; } /** * Increments the number of batches returned so far by one. */ void incNBatches() { - _metrics.incrementNBatches(); + ++_nBatchesReturned; } Date_t getLastUseDate() const { @@ -310,22 +302,6 @@ public: _stashedRecoveryUnit = std::move(ru); } - /** - * Returns true if a client has requested that this cursor can be killed. - */ - bool isKillPending() const { - return _killPending; - } - - /** - * Sets 'killPending' flag of this client cursor. This indicates to the cursor that a client - * has requested that it be killed while it was pinned, and it can proactively clean up its - * resources upon unpinning. - */ - void setKillPending(bool newValue) { - _killPending = newValue; - } - private: friend class CursorManager; friend class ClientCursorPin; @@ -359,12 +335,17 @@ private: ~ClientCursor(); /** + * Marks this cursor as killed, so any future uses will return 'killStatus'. It is an error to + * call this method with Status::OK. + */ + void markAsKilled(Status killStatus); + + /** * Disposes this ClientCursor's PlanExecutor. Must be called before deleting a ClientCursor to * ensure it has a chance to clean up any resources it is using. Can be called multiple times. - * It is an error to call any other method after calling dispose(). If 'now' is specified, - * will track cursor lifespan metrics. + * It is an error to call any other method after calling dispose(). */ - void dispose(OperationContext* opCtx, boost::optional<Date_t> now); + void dispose(OperationContext* opCtx); bool isNoTimeout() const { return _isNoTimeout; @@ -398,6 +379,13 @@ private: // an error to use a ClientCursor once it has been disposed. bool _disposed = false; + // Tracks the number of results returned by this cursor so far. Tracked only as debugging info + // for display in $currentOp output. + std::uint64_t _nReturnedSoFar = 0; + + // Tracks the number of batches returned by this cursor so far. + std::uint64_t _nBatchesReturned = 0; + // Holds an owned copy of the command specification received from the client. const BSONObj _originatingCommand; @@ -452,25 +440,8 @@ private: boost::optional<uint32_t> _planCacheKey; boost::optional<uint32_t> _queryHash; - // If boost::none, query stats should not be collected for this cursor. - boost::optional<std::size_t> _queryStatsKeyHash; - // Metrics that are accumulated over the lifetime of the cursor, incremented with each getMore. - // Useful for diagnostics like queryStats. - OpDebug::AdditiveMetrics _metrics; - // The Key used by query stats to generate the query stats store key. - std::unique_ptr<query_stats::Key> _queryStatsKey; - - // Flag for query stats on if the current cursor is used for a tailable or change stream query. - bool _queryStatsWillNeverExhaust{false}; - // The client OperationKey associated with this cursor. boost::optional<OperationKey> _opKey; - - // Flag indicating that a client has requested to kill the cursor. - bool _killPending = false; - - // The execution time collected from the initial operation prior to any getMore requests. - boost::optional<Microseconds> _firstResponseExecutionTime; }; /** @@ -578,17 +549,4 @@ private: void startClientCursorMonitor(); - -/** - * Records certain metrics for the current operation on OpDebug and aggregates those metrics for - * query stats use. If a cursor pin is provided, metrics are aggregated on the cursor; otherwise, - * metrics are written directly to the query stats store. - * NOTE: Metrics are taken from opDebug.additiveMetrics, so CurOp::setEndOfOpMetrics must be called - * *prior* to calling these. - * - * Currently, query stats are only collected for find and aggregate requests (and their subsequent - * getMore requests), so these should only be called from those request paths. - */ -void collectQueryStatsMongod(OperationContext* opCtx, ClientCursorPin& cursor); -void collectQueryStatsMongod(OperationContext* opCtx, std::unique_ptr<query_stats::Key> key); } // namespace mongo |
