summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorNaama Bareket <naama.bareket@mongodb.com>2023-02-06 15:20:47 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-02-06 16:23:01 +0000
commit39ddb8c2c82900ccd4452928d9fb0c8f22b35e3a (patch)
treea9f542eb25af3cf608aebe6624dbd4bdd6d1c693 /src/mongo
parent50922d144694ae20c397126dcd3a520219771070 (diff)
downloadmongo-39ddb8c2c82900ccd4452928d9fb0c8f22b35e3a.tar.gz
SERVER-72518 Make 5% random-cursor $sample cutoff configurable
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/pipeline/pipeline_d.cpp12
-rw-r--r--src/mongo/db/query/SConscript1
-rw-r--r--src/mongo/db/query/query_knobs.idl24
-rw-r--r--src/mongo/db/sorter/SConscript1
4 files changed, 37 insertions, 1 deletions
diff --git a/src/mongo/db/pipeline/pipeline_d.cpp b/src/mongo/db/pipeline/pipeline_d.cpp
index bb146b1cb94..f0d4d224f42 100644
--- a/src/mongo/db/pipeline/pipeline_d.cpp
+++ b/src/mongo/db/pipeline/pipeline_d.cpp
@@ -516,7 +516,17 @@ StatusWith<unique_ptr<PlanExecutor, PlanExecutor::Deleter>> PipelineD::createRan
// function because double-locking forces any PlanExecutor we create to adopt a NO_YIELD policy.
invariant(opCtx->lockState()->isCollectionLockedForMode(coll->ns(), MODE_IS));
- static const double kMaxSampleRatioForRandCursor = 0.05;
+ auto* clusterParameters = ServerParameterSet::getClusterParameterSet();
+ auto* randomCursorSampleRatioParam =
+ clusterParameters
+ ->get<ClusterParameterWithStorage<InternalQueryCutoffForSampleFromRandomCursorStorage>>(
+ "internalQueryCutoffForSampleFromRandomCursor");
+
+ auto maxSampleRatioClusterParameter =
+ randomCursorSampleRatioParam->getValue(expCtx->ns.tenantId());
+
+ const double kMaxSampleRatioForRandCursor = maxSampleRatioClusterParameter.getSampleCutoff();
+
if (!expCtx->ns.isTimeseriesBucketsCollection()) {
if (sampleSize > numRecords * kMaxSampleRatioForRandCursor || numRecords <= 100) {
return nullptr;
diff --git a/src/mongo/db/query/SConscript b/src/mongo/db/query/SConscript
index bb1b4efda4c..a2c337ce8bd 100644
--- a/src/mongo/db/query/SConscript
+++ b/src/mongo/db/query/SConscript
@@ -267,6 +267,7 @@ env.Library(
LIBDEPS_PRIVATE=[
'$BUILD_DIR/mongo/db/server_base',
'$BUILD_DIR/mongo/db/service_context',
+ '$BUILD_DIR/mongo/idl/cluster_server_parameter',
'$BUILD_DIR/mongo/util/pcre_wrapper',
'memory_util',
],
diff --git a/src/mongo/db/query/query_knobs.idl b/src/mongo/db/query/query_knobs.idl
index 64d8b782359..d4ca334491f 100644
--- a/src/mongo/db/query/query_knobs.idl
+++ b/src/mongo/db/query/query_knobs.idl
@@ -26,6 +26,9 @@
# it in the license file.
#
+imports:
+ - "mongo/idl/cluster_server_parameter.idl"
+
global:
cpp_namespace: "mongo"
cpp_includes:
@@ -61,6 +64,21 @@ enums:
# Use a prefix of sha256 redaction strategy
kSha256RedactionStrategy: "sha256"
+structs:
+ InternalQueryCutoffForSampleFromRandomCursorStorage:
+ description: "A specification for the 'internalQueryCutoffForSampleFromRandomCursor' cluster-wide configuration parameter type."
+ inline_chained_structs: true
+ chained_structs:
+ ClusterServerParameter: clusterServerParameter
+ fields:
+ sampleCutoff:
+ description: "The configuration for random-cursor sample cutoffs."
+ type: double
+ default: 0.05
+ validator:
+ gt: 0.0
+ lte: 1.0
+
server_parameters:
#
@@ -1076,6 +1094,12 @@ server_parameters:
gte: 0
on_update: plan_cache_util::clearSbeCacheOnParameterChange
+ internalQueryCutoffForSampleFromRandomCursor:
+ description: "The maximum sample ratio for random cursor."
+ set_at: cluster
+ cpp_varname: "internalQueryCutoffForSampleFromRandomCursor"
+ cpp_vartype: InternalQueryCutoffForSampleFromRandomCursorStorage
+
internalQueryGlobalProfilingFilter:
description: "Enables the setProfilingFilterGlobally command."
set_at: [ startup ]
diff --git a/src/mongo/db/sorter/SConscript b/src/mongo/db/sorter/SConscript
index a52da1d0c7a..5f88dabdc58 100644
--- a/src/mongo/db/sorter/SConscript
+++ b/src/mongo/db/sorter/SConscript
@@ -13,6 +13,7 @@ sorterEnv.CppUnitTest(
],
LIBDEPS=[
'$BUILD_DIR/mongo/db/exec/document_value/document_value',
+ '$BUILD_DIR/mongo/db/query/query_knobs',
'$BUILD_DIR/mongo/db/service_context',
'$BUILD_DIR/mongo/db/storage/encryption_hooks',
'$BUILD_DIR/mongo/db/storage/storage_options',