-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feature: dynamically add and remove shards by the ring client #2093
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
Conversation
In case of kubernetes dataclient we can detect the number of redis shards available and trigger an update to the redis ringclient. In order to use this feature we have to use a forked version of go-redis until it is merged and released redis/go-redis#2093 Signed-off-by: Sandor Szücs <sandor.szuecs@zalando.de>
The code could be cleaner if you restructure it like this: shards := newRingShards(addrs, c.shards)
c.mu.Lock()
if c.closed {
// close shards
} else {
c.shards = shards
c.list = shards.list()
}
c.mu.Unlock() What do you think? |
@vmihailenco so you are suggesting a type change of
|
I suggest to slightly refactor // SetAddrs is safe to be used concurrently.
func (c *Ring) SetAddrs(addrs map[string]string) {
// Construct new shards without holding the lock. Pass old shards to reuse existing clients.
shards := newRingShards(addrs, c.shards)
c.shardsMu.Lock()
defer c.shardsMu.Unlock()
if c.closed {
// Ring is closed. Close new shards.
shards.Close()
return
}
// Atomically set new shards so they are used by the Ring.
c.shards = shards
} Does that make sense? |
@vmihailenco yeah thanks, makes a lot of sense! |
This does not look to be safe for concurrent use: imagine two threads call |
As an idea we may have another mutex to guard only |
Yes, that is what I suggest as well. |
@AlexanderYastrebov great idea, I hope this is now good, but also happy to rewrite. :) |
@vmihailenco if you give it another try for a review would be great. I had an online session with @AlexanderYastrebov and rewrote some parts to make it nicer. In an unrelated follow up PR I would like to enhance the locking in ring.go and for example remove the current rebalance() |
2f67804
to
d1c1751
Compare
In case of kubernetes dataclient we can detect the number of redis shards available and trigger an update to the redis ringclient. In order to use this feature we have to use a forked version of go-redis until it is merged and released redis/go-redis#2093 Signed-off-by: Sandor Szücs <sandor.szuecs@zalando.de>
In case of kubernetes dataclient we can detect the number of redis shards available and trigger an update to the redis ringclient. In order to use this feature we have to use a forked version of go-redis until it is merged and released redis/go-redis#2093 Signed-off-by: Sandor Szücs <sandor.szuecs@zalando.de>
* feature: dynamic detect and resize redis instances In case of kubernetes dataclient we can detect the number of redis shards available and trigger an update to the redis ringclient. In order to use this feature we have to use a forked version of go-redis until it is merged and released redis/go-redis#2093 Signed-off-by: Sandor Szücs <sandor.szuecs@zalando.de>
…euse old connections test: ring scale-in and scale-out rewrite as suggested by @AlexanderYastrebov Signed-off-by: Sandor Szücs <sandor.szuecs@zalando.de>
fix #2077
feature: ring.SetAddrs to add and remove shards by the ring client #2093
tests: to scale in and out
Signed-off-by: Sandor Szücs sandor.szuecs@zalando.de