-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
fix: fixes ring.SetAddrs and rebalance race #2283
fix: fixes ring.SetAddrs and rebalance race #2283
Conversation
The change ensures atomic update of `c.hash` and `c.shards`. `BenchmarkRingRebalanceLocked` shows rebalance latency: ``` go test . -run=NONE -bench=BenchmarkRingRebalanceLocked -v -count=10 | benchstat /dev/stdin name time/op RingRebalanceLocked-8 8.50µs ±14% ``` (Note: it essentially reverts a46b053)
7adfdca
to
433975c
Compare
ring_test.go
Outdated
return string(h) | ||
} | ||
|
||
func TestRingSetAddrsAndRebalanceRace(t *testing.T) { |
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.
Could you please create and move this test to internal_test.go
that has package redis
so we don't need to export more commands in export_test.go
?
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.
Moved test and benchmark to internal_test.go
return c.sharding.ShardByName(name) | ||
} | ||
|
||
func (c *ringSharding) ShardByName(name string) *ringShard { |
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.
This was only used by above ShardByName
Thanks for the fix 👍 |
While working on reducing
ring.SetAddrs
lock contention (see #2190 (comment)) I have discovered a race condition betweenSetAddrs
andrebalance
which I would like to fix first and separately.The change consists of two commits:
The fix ensures atomic update of
c.hash
andc.shards
, otherwisec.hash
may return shard name that is not in thec.shards
and cause ring operation panic.BenchmarkRingRebalanceLocked
shows rebalance latency if that is a concern:(Note: it essentially reverts a46b053)
Updates #2077
FYI @szuecs