[SERVER-58332] pipeline MemoryUsageTracker: change StringMap to unordered_map for pointer stability Created: 07/Jul/21  Updated: 29/Oct/23  Resolved: 08/Jul/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 5.0.2, 5.1.0-rc0

Type: Bug Priority: Major - P3
Reporter: Billy Donahue Assignee: Billy Donahue
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
is depended on by SERVER-51476 Upgrade Abseil to 20210324.1 Closed
Related
is related to SERVER-58322 Perform aggregate on buckets collecti... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v5.0
Sprint: Service Arch 2021-07-12
Participants:

 Description   

This appears to be a previously undiagnosed error in the Agg pipeline "explain" implementation, which becomes visible when abseil is upgraded.

This is blocking SERVER-51476 (Abseil upgrade), as aggregation tests begin to fail with new absl version.
https://spruce.mongodb.com/version/60e00def61837d5cfc0f4f9c/tasks

I can reproduce this locally on a Linux virtual workstation and attach a debugger, but I don't have a root cause for it. Still investigating.

7  0x00007fba641ab8c2 in mongo::breakpoint () at src/mongo/util/debugger.cpp:72
#8  0x00007fba6416481d in mongo::(anonymous namespace)::abruptQuitWithAddrSignal (signalNum=11, siginfo=0x7fba2f64d4f0, ucontext_erased=0x7fba2f64d3c0) at src/mongo/util/signal_handlers_synchronous.cpp:284
#9  <signal handler called>
#10 0x00007fba4f2435bc in mongo::MemoryUsageTracker::update (this=0xcdcdcdcdcdcdcdcd, diff=3617008641903833723) at src/mongo/db/pipeline/memory_usage_tracker.h:152
#11 0x00007fba4f242e56 in mongo::MemoryUsageTracker::PerFunctionMemoryTracker::set (this=0x7fba3757c658, total=72) at src/mongo/db/pipeline/memory_usage_tracker.h:64
#12 0x00007fba4f355ef4 in mongo::WindowFunctionExecNonRemovable::initialize (this=0x7fba3757c220) at src/mongo/db/pipeline/window_function/window_function_exec_non_removable.h:125
#13 0x00007fba4f35515d in mongo::WindowFunctionExecNonRemovable::getNext (this=0x7fba3757c220) at src/mongo/db/pipeline/window_function/window_function_exec_non_removable.h:69
#14 0x00007fba4f2eafad in mongo::DocumentSourceInternalSetWindowFields::doGetNext (this=0x7fba3753c8e0) at src/mongo/db/pipeline/document_source_set_window_fields.cpp:454
#15 0x00007fba534edc0b in mongo::DocumentSource::getNext (this=0x7fba3753c8e0) at src/mongo/db/pipeline/document_source.h:305
#16 0x00007fba4f334133 in mongo::Pipeline::getNext (this=0x7fba3022f3a0) at src/mongo/db/pipeline/pipeline.cpp:448
#17 0x00007fba53e53f2c in mongo::PlanExecutorPipeline::_tryGetNext (this=0x7fba39010420) at src/mongo/db/pipeline/plan_executor_pipeline.cpp:128
#18 0x00007fba53e53dc7 in mongo::PlanExecutorPipeline::_getNext (this=0x7fba39010420) at src/mongo/db/pipeline/plan_executor_pipeline.cpp:116
#19 0x00007fba53e53cae in mongo::PlanExecutorPipeline::getNextDocument (this=0x7fba39010420, docOut=0x7fba22e34a88, recordIdOut=0x0) at src/mongo/db/pipeline/plan_executor_pipeline.cpp:98
#20 0x00007fba53e53b49 in mongo::PlanExecutorPipeline::getNext (this=0x7fba39010420, objOut=0x7fba22e34ae0, recordIdOut=0x0) at src/mongo/db/pipeline/plan_executor_pipeline.cpp:78
#21 0x00007fba53e6a2cc in mongo::(anonymous namespace)::executePlan (exec=0x7fba39010420) at src/mongo/db/query/explain.cpp:263
#22 0x00007fba53e6a796 in mongo::Explain::explainPipeline (exec=0x7fba39010420, executePipeline=true, verbosity=mongo::explain::VerbosityEnum::kExecStats, command=..., out=0x7fba22e34d70) at src/mongo/db/query/explain.cpp:318
#23 0x00007fba4321fc7d in mongo::runAggregate (opCtx=0x7fba2ed48220, origNss=..., request=..., liteParsedPipeline=..., cmdObj=..., privileges=..., result=0x7fba3757bb20) at src/mongo/db/commands/run_aggregate.cpp:896
#24 0x00007fba432124ef in mongo::(anonymous namespace)::PipelineCommand::Invocation::explain (this=0x7fba2ee4c520, opCtx=0x7fba2ed48220, verbosity=mongo::explain::VerbosityEnum::kExecStats, result=0x7fba3757bb20) at src/mongo/db/commands/pipeline_command.cpp:167
#25 0x00007fba431ae43c in mongo::(anonymous namespace)::CmdExplain::Invocation::run (this=0x7fba2f44ed60, opCtx=0x7fba2ed48220, result=0x7fba3757bb20) at src/mongo/db/commands/explain_cmd.cpp:113
#26 0x00007fba4d841d10 in mongo::CommandHelpers::runCommandInvocation (opCtx=0x7fba2ed48220, request=..., invocation=0x7fba2f44ed60, response=0x7fba3757bb20) at src/mongo/db/commands.cpp:200
#27 0x00007fba4d841a6a in mongo::CommandHelpers::<lambda()>::operator()(void) const (__closure=0x7fba22e35710) at src/mongo/db/commands.cpp:184



 Comments   
Comment by Vivian Ge (Inactive) [ 06/Oct/21 ]

Updating the fixversion since branching activities occurred yesterday. This ticket will be in rc0 when it’s been triggered. For more active release information, please keep an eye on #server-release. Thank you!

Comment by Githook User [ 27/Jul/21 ]

Author:

{'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com', 'username': 'BillyDonahue'}

Message: SERVER-58332 memory_usage_tracker: switch to node_hash_map for stable pointers

(cherry picked from commit 11b4bd0749384cc3097bce7bf75d3e39768a2a1f)
Branch: v5.0
https://github.com/mongodb/mongo/commit/154008633e31b5d947f97e97f72a397b4221e16b

Comment by Billy Donahue [ 08/Jul/21 ]

This was accidentally committed with the wrong ticket number SERVER-58322 in the description,
but actually fixes this bug.

Author:

{'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com', 'username': 'BillyDonahue'}

Message: SERVER-58322 memory_usage_tracker: switch to node_hash_map for stable pointers
Branch: master
https://github.com/mongodb/mongo/commit/11b4bd0749384cc3097bce7bf75d3e39768a2a1f

Comment by Billy Donahue [ 08/Jul/21 ]

Figured it out. A StringMap is a typedef for absl::flat_hash_map for some reason, instead of absl::node_hash_map.
This means that elements do not have stable addresses, and references to elements are invalidated.

The pipeline MemoryUsageTracker::operator[] was therefore handing out unstable references to PerFunctionMemoryTracker elements.

Comment by Billy Donahue [ 08/Jul/21 ]


code review https://mongodbcr.appspot.com/812250003/

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