-
-
Notifications
You must be signed in to change notification settings - Fork 72
Rotate slaves #50
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
base: master
Are you sure you want to change the base?
Rotate slaves #50
Conversation
This is really helpful, thank you. Could you please @pintsized or @piotrp look at this pull request? |
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.
LGTM. Could you please add a test case to cover the change? You can find examples in sentinel.t
.
You shouldn't keep rotation state in a global variable, this should be kept in connector instance. And, preferably, be a opt-in behavior (or at least opt-out?). A few technical remarks:
A generalized rotation function could look like this: local function rotate_slaves_2(slaves, rotate_by)
local slave_count = #slaves
local rotated_slaves = tbl_new(#slaves, 0)
for i, slave in ipairs(slaves) do
local new_index = (i - rotate_by - 1) % slave_count + 1
rotated_slaves[new_index] = slave
end
return rotated_slaves
end |
Sorry for a delayed answer, I was busy with other things. @piotrp Thanks for the suggestions. I moved the variable inside the connector instance and set slaves rotation as an opt-in. @pintsized I added two tests that test the implementation. Due to the fact that redis instances are not "fresh" for each test I had to put the tests above the already existing ones. Also since sentinel doesn't guarantee in which order the slave instances are returned while listing them I had to add some |
@piotrp @pintsized Just want to remind you that I made some changes to this PR and I would be really grateful if you take a look at it. 🙂 |
A quick test rotating 4 "slaves" (originally
Looks fine to me. |
While using this connector in my code I noticed that the operations towards slaves are not balanced between all slave instances returned by Sentinel. Connector just tries to connect to slaves in the order returned by Sentinel and uses the first one that succeeds. I checked how other Redis Clients solve this problem and for example client for Python rotates the slaves in round-robin manner (as you can see here). I implemented similar rotation for this connector so that all slave instances are utilized equally.