-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: move tl_cluster_config into cluster_config.cc #4714
Conversation
ec504bc
to
72697ab
Compare
72697ab
to
9bd1d77
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every call to Current()
is a copy of the shared pointer. Is this something we are ok with ?
@@ -17,6 +17,9 @@ using namespace std; | |||
namespace dfly::cluster { | |||
|
|||
namespace { | |||
|
|||
thread_local shared_ptr<ClusterConfig> tl_cluster_config; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand. Why is this a shared_ptr when it's a thread local ? Why do you need atomic ref count on a non concurrent (thread local) storage ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I just realized this was moved nvm. General remark, I still think shared pointer for a single thread is an antipattern + you do atomic operations on data that is not shared among threads.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we share the same config between all threads
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then why is it a thread local ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And also, each call to current
now is a copy and an atomic increment. If this is used concurrently we might stall the processors (especially on NUMA). We should really use the threadlocal when we are in scope and we know that the object won't be destructed (we did that previously)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
discussed offline
|
||
auto config = tl_cluster_config->GetConfig(); | ||
auto config = ClusterConfig::Current()->GetConfig(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before, you used the thread local directly. Now you do instead: copy of the shared_ptr which increments atomically the control block/ref count and then call GetConfig(). Is there a reason for this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't need ref count and can gurantee the lifetime, why not simply return a plain pointer
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't know when the life of the config will be finished. So it is the reason of shared_ptr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fine but why then is it a thread local ?
yes. |
if you need cluster_config you don't need cluster_family now