[SERVER-50064] Make recursion depth thread-local in ServiceExecutor tests Created: 31/Jul/20  Updated: 29/Oct/23  Resolved: 04/Aug/20

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

Type: Bug Priority: Major - P3
Reporter: Amirsaman Memaripour Assignee: Amirsaman Memaripour
Resolution: Fixed Votes: 0
Labels: servicearch-wfbf-day
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Service Arch 2020-08-10
Participants:
Linked BF Score: 0

 Description   

The atomic variable used in ServiceExecutorFixedFixture::FlattenRecursiveScheduledTasks (see here) to track the recursion depth should be replaced by a thread-local integer, making it safe for multiple executor threads to run tasks without concurrently bumping up the recursion depth.

Having a thread-local variable to track recursion depth is necessary since another executor thread (i.e., exec2) may start executing a task immediately after it's been scheduled by another thread (i.e., exec1), making it appear as the thread that scheduled the task (exec1) is executing it recursively.



 Comments   
Comment by Githook User [ 04/Aug/20 ]

Author:

{'name': 'Amirsaman Memaripour', 'email': 'amirsaman.memaripour@mongodb.com', 'username': 'samanca'}

Message: SERVER-50064 Make recursion depth thread-local in ServiceExecutor tests
Branch: master
https://github.com/mongodb/mongo/commit/b4db8c01a13fd70997a05857be17548b0adec020

Comment by Billy Donahue [ 03/Aug/20 ]

billy.donahue, we check the provided flag and recurse here, so if any of the executor threads attempt to recurse, the thread-local recursionDepth variable for that executor thread will have a value greater than one.

 
I'm still unclear on why this requires a static thread_local counter. It's a big change from the old per-instance atomic int that we have. It's just that thread_local are hard to reason about. Can this counter be a property of a context that is passed around and shared by all the tasks? Explicit tracking of thread id in the increment and decrement code would make the tests easier to understand.

Maybe we can talk about it offline.

Comment by Amirsaman Memaripour [ 03/Aug/20 ]

billy.donahue, we check the provided flag and recurse here, so if any of the executor threads attempt to recurse, the thread-local recursionDepth variable for that executor thread will have a value greater than one.

Comment by Billy Donahue [ 03/Aug/20 ]

How do you know the ServiceExecutor is going to use the same thread for all the steps of the recursion?

 

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