Giter Site home page Giter Site logo

killme2008 / carmine-sentinel Goto Github PK

View Code? Open in Web Editor NEW
14.0 3.0 4.0 118 KB

A Clojure library designed to connect redis by sentinel, make carmine to support sentinel.

License: Eclipse Public License 1.0

Clojure 96.37% Makefile 3.63%
clojure carmine sentinel redis-sentinel

carmine-sentinel's People

Contributors

killme2008 avatar ylgrgyq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

carmine-sentinel's Issues

support carmine upper than v2.15.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.0to 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. 😱

在连续进行 master 切换的时候有小概率不清理本地 resolve 的 master 地址

主要是在这个地方,当从 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 地址。

Feature: Permit redirection from slave, or use of a master, as opposed to sentinel only

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.

remove-invalid-resolved-master-specs! usage

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?

是否需要考虑订阅 majority 个 sentinel

从目前的实现来看,只会订阅那个能成功拿到 master 节点配置的 sentinel,其它的 sentinel 不会进行订阅。但是比如有 A B C D E 这 5 个节点,如果只订阅 A,剩余节点按说是能凑够 qurum 重新选一个 master 出来的,在网络有隔离的时候 A 可能不知道当前 master 已切换,从而只订阅 A 的话这个 client 收不到 master 切换的通知。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.