-
-
Notifications
You must be signed in to change notification settings - Fork 428
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 sentinel mode read-write separation #749
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #749 +/- ##
========================================
- Coverage 63.2% 63.2% -0.0%
========================================
Files 43 43
Lines 3223 3231 +8
Branches 244 244
========================================
+ Hits 2034 2039 +5
- Misses 1172 1175 +3
Partials 17 17
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
f7d1ac0
to
9e56f92
Compare
for more information, see https://pre-commit.ci
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!
# so it doesn't interfere with the SentinelConnectionPool constructor | ||
if "is_master" in query_params: | ||
del query_params["is_master"] | ||
new_query = urlencode(query_params, doseq=True) |
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.
why do you need this if you deleted the key from the original query_params
variable?
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 this parameter is not deleted, it cannot be correctly parsed as bool type in redis-py, but as str type. This will cause it to use the master node for reading and writing even if is_master=0 is set.
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.
yeah, sure, my bad
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.
please merge master into your branch and solve conflicts then
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 have merged and resolved the conflicts
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!
When I attempted to set up read-write separation in Sentinel mode by configuring redis://redis-master/db?is_master=0, I noticed that both read and write requests were still being directed to the master node, without any separation. After reviewing and debugging the source code, I found that the issue was due to redis-py being unable to correctly parse the is_master parameter, and there was also an error in how the project handled is_master. The pool.is_master was only set to False after retrieving the redis.sentinel.SentinelConnectionPool object from redis-py, which resulted in the system supposedly using the slave node, but actually using the master node.