summaryrefslogtreecommitdiff
path: root/src/mongo/s/query
diff options
context:
space:
mode:
authorMickey. J Winters <mickey.winters@mongodb.com>2021-08-19 17:41:16 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-08-19 18:45:26 +0000
commit093eeacde2f5a2c84dbf9ac22ea851ac4471e3e4 (patch)
treeba77915687904da96281a95510d7b452eec778d4 /src/mongo/s/query
parent5a670b3d9ecdf085e727e29fb1ad9c939cf0838a (diff)
downloadmongo-093eeacde2f5a2c84dbf9ac22ea851ac4471e3e4.tar.gz
SERVER-54571 Add queryHash and planCacheKey fields to getMore request slow query logs
Diffstat (limited to 'src/mongo/s/query')
-rw-r--r--src/mongo/s/query/cluster_client_cursor.h5
-rw-r--r--src/mongo/s/query/cluster_client_cursor_impl.cpp11
-rw-r--r--src/mongo/s/query/cluster_client_cursor_impl.h5
-rw-r--r--src/mongo/s/query/cluster_client_cursor_mock.cpp4
-rw-r--r--src/mongo/s/query/cluster_client_cursor_mock.h2
-rw-r--r--src/mongo/s/query/cluster_cursor_manager.cpp3
6 files changed, 28 insertions, 2 deletions
diff --git a/src/mongo/s/query/cluster_client_cursor.h b/src/mongo/s/query/cluster_client_cursor.h
index e98783cc09d..62302030988 100644
--- a/src/mongo/s/query/cluster_client_cursor.h
+++ b/src/mongo/s/query/cluster_client_cursor.h
@@ -207,6 +207,11 @@ public:
virtual void setLastUseDate(Date_t now) = 0;
/**
+ * Returns the queryHash of the query.
+ */
+ virtual boost::optional<uint32_t> getQueryHash() const = 0;
+
+ /**
* Returns the number of batches returned by this cursor.
*/
virtual std::uint64_t getNBatches() const = 0;
diff --git a/src/mongo/s/query/cluster_client_cursor_impl.cpp b/src/mongo/s/query/cluster_client_cursor_impl.cpp
index d42675f97ec..9df37343455 100644
--- a/src/mongo/s/query/cluster_client_cursor_impl.cpp
+++ b/src/mongo/s/query/cluster_client_cursor_impl.cpp
@@ -33,6 +33,7 @@
#include <memory>
+#include "mongo/db/curop.h"
#include "mongo/s/query/router_stage_limit.h"
#include "mongo/s/query/router_stage_merge.h"
#include "mongo/s/query/router_stage_remove_metadata_fields.h"
@@ -73,7 +74,8 @@ ClusterClientCursorImpl::ClusterClientCursorImpl(OperationContext* opCtx,
_lsid(lsid),
_opCtx(opCtx),
_createdDate(opCtx->getServiceContext()->getPreciseClockSource()->now()),
- _lastUseDate(_createdDate) {
+ _lastUseDate(_createdDate),
+ _queryHash(CurOp::get(opCtx)->debug().queryHash) {
dassert(!_params.compareWholeSortKeyOnRouter ||
SimpleBSONObjComparator::kInstance.evaluate(
_params.sortToApplyOnRouter == AsyncResultsMerger::kWholeSortKeySortPattern));
@@ -89,7 +91,8 @@ ClusterClientCursorImpl::ClusterClientCursorImpl(OperationContext* opCtx,
_lsid(lsid),
_opCtx(opCtx),
_createdDate(opCtx->getServiceContext()->getPreciseClockSource()->now()),
- _lastUseDate(_createdDate) {
+ _lastUseDate(_createdDate),
+ _queryHash(CurOp::get(opCtx)->debug().queryHash) {
dassert(!_params.compareWholeSortKeyOnRouter ||
SimpleBSONObjComparator::kInstance.evaluate(
_params.sortToApplyOnRouter == AsyncResultsMerger::kWholeSortKeySortPattern));
@@ -210,6 +213,10 @@ void ClusterClientCursorImpl::setLastUseDate(Date_t now) {
_lastUseDate = std::move(now);
}
+boost::optional<uint32_t> ClusterClientCursorImpl::getQueryHash() const {
+ return _queryHash;
+}
+
std::uint64_t ClusterClientCursorImpl::getNBatches() const {
return _nBatchesReturned;
}
diff --git a/src/mongo/s/query/cluster_client_cursor_impl.h b/src/mongo/s/query/cluster_client_cursor_impl.h
index d95dcf11ee1..59c60b43808 100644
--- a/src/mongo/s/query/cluster_client_cursor_impl.h
+++ b/src/mongo/s/query/cluster_client_cursor_impl.h
@@ -114,6 +114,8 @@ public:
void setLastUseDate(Date_t now) final;
+ boost::optional<uint32_t> getQueryHash() const final;
+
std::uint64_t getNBatches() const final;
void incNBatches() final;
@@ -170,6 +172,9 @@ private:
// The time when the cursor was last unpinned, i.e. the end of the last getMore.
Date_t _lastUseDate;
+ // The hash of the query shape to be used for slow query logging;
+ boost::optional<uint32_t> _queryHash;
+
// The number of batches returned by this cursor.
std::uint64_t _nBatchesReturned = 0;
};
diff --git a/src/mongo/s/query/cluster_client_cursor_mock.cpp b/src/mongo/s/query/cluster_client_cursor_mock.cpp
index 3605abef6b7..31926830901 100644
--- a/src/mongo/s/query/cluster_client_cursor_mock.cpp
+++ b/src/mongo/s/query/cluster_client_cursor_mock.cpp
@@ -109,6 +109,10 @@ void ClusterClientCursorMock::setLastUseDate(Date_t now) {
_lastUseDate = std::move(now);
}
+boost::optional<uint32_t> ClusterClientCursorMock::getQueryHash() const {
+ return boost::none;
+}
+
void ClusterClientCursorMock::kill(OperationContext* opCtx) {
_killed = true;
if (_killCallback) {
diff --git a/src/mongo/s/query/cluster_client_cursor_mock.h b/src/mongo/s/query/cluster_client_cursor_mock.h
index 8f2b38c8315..4b687df6203 100644
--- a/src/mongo/s/query/cluster_client_cursor_mock.h
+++ b/src/mongo/s/query/cluster_client_cursor_mock.h
@@ -104,6 +104,8 @@ public:
void setLastUseDate(Date_t now) final;
+ boost::optional<uint32_t> getQueryHash() const final;
+
std::uint64_t getNBatches() const final;
void incNBatches() final;
diff --git a/src/mongo/s/query/cluster_cursor_manager.cpp b/src/mongo/s/query/cluster_cursor_manager.cpp
index d5744416e46..a7cfce88687 100644
--- a/src/mongo/s/query/cluster_cursor_manager.cpp
+++ b/src/mongo/s/query/cluster_cursor_manager.cpp
@@ -36,6 +36,7 @@
#include <set>
+#include "mongo/db/curop.h"
#include "mongo/db/kill_sessions_common.h"
#include "mongo/db/logical_session_cache.h"
#include "mongo/logv2/log.h"
@@ -293,6 +294,8 @@ StatusWith<ClusterCursorManager::PinnedCursor> ClusterCursorManager::checkOutCur
}
cursorGuard->reattachToOperationContext(opCtx);
+ CurOp::get(opCtx)->debug().queryHash = cursorGuard->getQueryHash();
+
_log.push({LogEvent::Type::kCheckoutComplete, cursorId, now, nss});
return PinnedCursor(this, std::move(cursorGuard), nss, cursorId);
}