[SERVER-44013] MR Agg: Report plan stats and summary for currentOp/profiler/slow query logging Created: 15/Oct/19  Updated: 29/Oct/23  Resolved: 31/Oct/19

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 4.3.1

Type: Task Priority: Major - P3
Reporter: James Wahlin Assignee: James Wahlin
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-44016 MR Agg: Replica set M/R fails on unin... Closed
is duplicated by SERVER-44168 MR Agg: Add plan summary stats to output Closed
Related
related to SERVER-44016 MR Agg: Replica set M/R fails on unin... Closed
Backwards Compatibility: Fully Compatible
Sprint: Query 2019-11-04
Participants:

 Description   

We should mirror the stats written to CurOp for run_aggregate.cpp. Here is an example.



 Comments   
Comment by Githook User [ 31/Oct/19 ]

Author:

{'name': 'James Wahlin', 'username': 'jameswahlin', 'email': 'james.wahlin@mongodb.com'}

Message: SERVER-44013 MR Agg: Report plan stats and summary for currentOp/profiler/slow query logging
Branch: master
https://github.com/mongodb/mongo/commit/996e6060811aced89dfef78b0d695d208690f3d6

Comment by Githook User [ 31/Oct/19 ]

Author:

{'username': 'jameswahlin', 'email': 'james.wahlin@mongodb.com', 'name': 'James Wahlin'}

Message: Revert "SERVER-44013 MR Agg: Report plan stats and summary for currentOp/profiler/slow query logging"

This reverts commit 8e9a8b5552ae078e1890ec319909b7268adcfaac.
Branch: master
https://github.com/mongodb/mongo/commit/7a3d17ea6b73bc916d94e59a44d5c1a56cbcb2e5

Comment by Githook User [ 31/Oct/19 ]

Author:

{'name': 'James Wahlin', 'username': 'jameswahlin', 'email': 'james.wahlin@mongodb.com'}

Message: SERVER-44013 MR Agg: Report plan stats and summary for currentOp/profiler/slow query logging
Branch: master
https://github.com/mongodb/mongo/commit/8e9a8b5552ae078e1890ec319909b7268adcfaac

Comment by James Wahlin [ 15/Oct/19 ]

The following is a rough attempt to add the plan stats and plan summary string:

diff --git a/src/mongo/db/commands/SConscript b/src/mongo/db/commands/SConscript
index c382ad4a62..96e4d4c32a 100644
--- a/src/mongo/db/commands/SConscript
+++ b/src/mongo/db/commands/SConscript
@@ -523,6 +523,7 @@ env.Library(
         '$BUILD_DIR/mongo/db/commands/servers',
         '$BUILD_DIR/mongo/db/db_raii',
         '$BUILD_DIR/mongo/db/pipeline/mongo_process_interface',
+        '$BUILD_DIR/mongo/db/query_exec',
         '$BUILD_DIR/mongo/db/query/map_reduce_output_format',
         '$BUILD_DIR/mongo/idl/idl_parser',
         'map_reduce_parser'
diff --git a/src/mongo/db/commands/map_reduce_agg.cpp b/src/mongo/db/commands/map_reduce_agg.cpp
index d2eccd8e57..ca6ac7dec7 100644
--- a/src/mongo/db/commands/map_reduce_agg.cpp
+++ b/src/mongo/db/commands/map_reduce_agg.cpp
@@ -43,9 +43,11 @@
 #include "mongo/db/commands/map_reduce_javascript_code.h"
 #include "mongo/db/commands/map_reduce_stats.h"
 #include "mongo/db/commands/mr_common.h"
+#include "mongo/db/curop.h"
 #include "mongo/db/db_raii.h"
 #include "mongo/db/exec/document_value/value.h"
 #include "mongo/db/namespace_string.h"
+#include "mongo/db/pipeline/document_source_cursor.h"
 #include "mongo/db/pipeline/expression.h"
 #include "mongo/db/pipeline/pipeline_d.h"
 #include "mongo/db/query/map_reduce_output_format.h"
@@ -128,8 +130,20 @@ bool runAggregationMapReduce(OperationContext* opCtx,
             expCtx, pipeline.release());
     }();
 
+    {
+        stdx::lock_guard<Client> lk(*opCtx->getClient());
+        CurOp::get(opCtx)->setPlanSummary_inlock(
+            dynamic_cast<DocumentSourceCursor*>(runnablePipeline->getSources().front().get())
+                ->getPlanSummaryStr());
+    }
+
     auto resultArray = exhaustPipelineIntoBSONArray(runnablePipeline);
 
+    CurOp::get(opCtx)->debug().setPlanSummaryMetrics(
+        dynamic_cast<DocumentSourceCursor*>(runnablePipeline->getSources().front().get())
+            ->getPlanSummaryStats());
+
 

Generated at Thu Feb 08 05:04:44 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.