-
Notifications
You must be signed in to change notification settings - Fork 125
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
TimingWheel中currentTime和overflowWheel变量存在竞争问题 #33
Comments
确实是这样,kafka源码中的注释也提到了advanceClock和add不能同时调用,具体实现的方式就是读写锁 |
@juine @yunlong0928 两位好!请问具体是什么竞争,以及会导致什么问题,方便具体描述下吗? |
TimingWheel结构体中currentTime,当add方法和addvanceClock方法并发时,存在如下这种竞争情况:add方法执行完 Lines 68 to 88 in 54845bd
除非确保advanceClock方法和add方法不同时调用 详见yunlong0928:master |
TimingWheel结构体中currentTime变量同时为多个goroutine访问,其中 add方法是只读,addvanceClock则是先去读currentTime变量,再判断,然后写入。使用了atomic只保证了读写currentTime变量那一个操作原子化,但是advanceClock则是先读再判断最后再写入, 会与add函数发生竞争,同理overflow变量也是一样好。粗略看了一下,kafka源码里面采用了是读写锁临时保护了这些变量
The text was updated successfully, but these errors were encountered: