killme2008 / carmine-sentinel Goto Github PK
View Code? Open in Web Editor NEWA Clojure library designed to connect redis by sentinel, make carmine to support sentinel.
License: Eclipse Public License 1.0
A Clojure library designed to connect redis by sentinel, make carmine to support sentinel.
License: Eclipse Public License 1.0
Some of the refactorings on carmine.commands/defcommand from com.taoensso/carmine v2.15.0
has made every sentinel commands defined in carmine-sentinel invalid (The defcommand
in old version is here for reference). We need to update those definitions like follows to support com.taoensso/carmine
upper than v2.15.0
:
(ns carmine-sentinel.core
(:require [taoensso.carmine.commands :as cmds]))
(cmds/defcommand "SENTINEL get-master-addr-by-name"
{:fn-name "sentinel-get-master-addr-by-name"
:fn-params-fixed [name]
:fn-params-more nil
:req-args-fixed ["SENTINEL" "get-master-addr-by-name" name]
:cluster-key-idx 2
:fn-docstring "get master address by master name. complexity O(1)"})
(cmds/defcommand "SENTINEL slaves"
{:fn-name "sentinel-slaves"
:fn-params-fixed [name]
:fn-params-more nil
:req-args-fixed ["SENTINEL" "slaves" name]
:cluster-key-idx 2
:fn-docstring "get slaves address by master name. complexity O(1)"})
(cmds/defcommand "SENTINEL sentinels"
{:fn-name "sentinel-sentinels"
:fn-params-fixed [name]
:fn-params-more nil
:req-args-fixed ["SENTINEL" "sentinels" name]
:cluster-key-idx 2
:fn-docstring "get sentinel instances by mater name. complexity O(1)"})
But this is a breaking change which will cause the users who still sticking on com.taoensso/carmine v2.14.0
to fail. So maybe we can just record this issue and leave carmine-sentinel
as it is. Those who do need to use com.taoensso/carmine
upper than v2.15.0
can refer to the codes above and make it work by themselves. 😱
Use SENTINEL sentinels [name]
to refresh sentinel instance list.
主要是在这个地方,当从 sentinel 拿到 master 地址并且跟 master 通信确认对方就是 master 后,假若此时刚巧发生了 master 切换,可能会误将失效的 master 地址存入 resolved master 地址结果中且持续保存。没有其它处理的话后续请求都会访问老 master。
目前考虑一个办法是在存 sentinel-resolved-specs
后再检查一次 master role,看目标是不是发生变化,变了就继续查找下一个 sentinel;
再一个办法是考虑给 wcar 增加 try catch,捕获 carmine 抛出的各种异常。因为 carmine 抛出的异常都是 ExceptionInfo 基本都没附带其它信息,所以考虑用个恶心一些的方法,检查异常中的 msg,如果 msg 中有类似 READONLY 即提示当前 client 连的是 slave 或者是 connection 相关的异常(每次 master 切换后,连着老 master 的连接会断开),当匹配成功时将 sentinel-resolved-specs
清理干净,下次访问 redis 会再次去 resolve master 地址。
Adds api doc
Running the role
command on establishing a connection will return master
, slave
or sentinel
. Proceeding to current logic in the sentinel case, while redirecting to the master returned in the result of said query in the slave
case or using the connection one already has for data/queries in the master
case, would serve to generalize this library for use in all single-master redis clusters, including those that don't actually use Sentinel; or those where access to the Sentinel nodes is not permitted from clients.
Hi,
We have a situation where the master becomes unavailable but we haven't received any sentinel event - how exactly this happens I'm not sure yet, but the effect of this is that the cached state about the master is never updated.
I see there is a fn remove-invalid-resolved-master-specs!
which could resolve this, the docstring of which says Please call this periodically to keep safe.
- although the readme makes no mention of it, but I guess it should? Or is there some specific scenarios this is intended for perhaps.
The other thing is that the fn catches EOFException
but in the case where master is unreachable I'm getting a different exception, so need a more general catch.
Happy to do PR if wanted?
从目前的实现来看,只会订阅那个能成功拿到 master 节点配置的 sentinel,其它的 sentinel 不会进行订阅。但是比如有 A B C D E 这 5 个节点,如果只订阅 A,剩余节点按说是能凑够 qurum 重新选一个 master 出来的,在网络有隔离的时候 A 可能不知道当前 master 已切换,从而只订阅 A 的话这个 client 收不到 master 切换的通知。
这种情况下需要重新获取 redis 配置,而不是继续使用上次缓存的。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.