-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
sentinel-cluster-client-redis #1226
Conversation
RedisClusterTokenServiceTest && RedisClient adjust sentinel-cluster-client-redis
Nice, I'll take a review these days. Could you please add some details of the design in the PR description? |
谢谢,PR description中已经添加了内容。 |
嗨,可以帮忙review一下代码吗 |
嗨,方便加个钉钉吗? |
Sorry for the late reply. We'll take a rapid review these days. |
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.
@@ -0,0 +1,27 @@ | |||
package com.alibaba.csp.sentinel.cluster.redis.config; | |||
|
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.
And i just want to question that why we created a suit of shadow configuration classes (HostAndPort, Client, Factory) but didn't use that in redisclient? We can handle different types of clients in RedisClientFactory (replacement of RedisClientFactoryManager) originally.
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.
redisclient有歧义,该类负责调用redis执行requestToken等逻辑操作,而不是redis的客户类(已改成RedisProcessor),所以HostAndPort这些配置类没有用于redisclient,而用于负责生成它的RedisClientFactory(已改为RedisProcessorFactory)中,RedisClientFactoryManager(已改成RedisProcessorFactoryManager)则根据不同redis java客户端和redis集群方式生成对应的RedisClientFactory。你看这样是否合理
...t-redis/src/main/java/com/alibaba/csp/sentinel/cluster/redis/config/ClusterClientConfig.java
Outdated
Show resolved
Hide resolved
|
||
import java.util.Set; | ||
|
||
public interface RedisClient { |
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 think the loading process should not be put in client (or we call it proxy or util) and load when needed. This may cause racing or latency, right?
Better put them in kinds of initializing codes like InitFunc, etc
And the name RedisClient
will cause ambiguous with real client of Redis.
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.
redis加载工作确实在RedisClusterClientInitFunc#initJedisClient方法中RedisProcessorFactoryManager.setClientType完成。
RedisClient已改为RedisProcessor。
...ent-redis/src/main/java/com/alibaba/csp/sentinel/cluster/redis/jedis/JedisClusterClient.java
Outdated
Show resolved
Hide resolved
|
||
@Override | ||
public int requestToken(String luaId, RequestData requestData) { | ||
final String flowId = String.valueOf(requestData.getFlowId()); |
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.
How to separate the flowId
in different projects sharing same redis/redis cluster?
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.
添加了namespace,ClusterFlowRuleManager为flowRule指定所属的namespace,可以区分不同项目的flowId。
@Override | ||
public int requestToken(String luaId, RequestData requestData) { | ||
String luaCode = LuaUtil.loadLuaCodeIfNeed(luaId); | ||
String luaSha = LuaUtil.loadLuaShaIfNeed(luaCode, new Function<String, String>() { |
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.
Have you tested the scenario migration of redis cluster? Is the lua cache migrated or not? If not there it would fail 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.
redis cluster迁移到新集群,要通过ClusterClientConfigManager.applyNewConfig更新配置,重新创建redis连接,这时也会清理所有的lua sha缓存
...-redis/src/main/java/com/alibaba/csp/sentinel/cluster/redis/config/RedisFlowRuleManager.java
Outdated
Show resolved
Hide resolved
...-redis/src/main/java/com/alibaba/csp/sentinel/cluster/redis/config/RedisFlowRuleManager.java
Outdated
Show resolved
Hide resolved
@@ -0,0 +1,125 @@ | |||
package com.alibaba.csp.sentinel.cluster.redis.config; |
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.
And all new files should prepend the license header please.
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.
不好意思,不太理解这个问题,可以再解释一下吗
|
travis-ci.org err fix
钉钉binecy,欢迎交流 |
RedisClusterFlowRuleManager
anything update? |
Describe what this PR does / why we need it
使用redis作为集群流控的服务端,某些场景下可以减少部署集群流控服务端的工作,也可以充分利用redis的高可用特性。
Does this pull request fix one issue?
Fixes #1188
Describe how you did it
flowRule在redis中key为sentinel:config:{namespace-flowId}, 使用Map结构存放sampleCount,intervalInMs,windowLengthInMs,thresholdCount配置。
redis中统计数据的key为sentinel:token:{namespace-flowId},使用Map结构存放所有的bucket,Map的key为time/windowLengthInMs,val为pass。
lua脚步统计数据步骤为:
使用sentinel:config:{namespace-flowId}查找对应的rule配置
使用time/windowLengthInMs计算bucket下标
如果bucket不存在,添加新的bucket同时删除过期的bucket
统计所有bucket中pass总数,计算qps
比较结果 添加pass数据
5.RedisClusterFlowSlot处理由RedisClusterFlowRuleManager添加的flowRule,该类代码除了ruleProvider,其他代码与FlowSlot一致。
6.RedisClusterFlowSlotExtender将RedisClusterFlowSlot添加到slotChain
Describe how to verify it
可见ClusterJedisTokenServiceTest,ClusterJedisRuleManagerTest
Special notes for reviews
支持redis4.0+,支持redis单机,sentinel,cluster集群模式,客户端使用jedis。
现在只支持集群总阈值模式,requestToken请求,不支持prioritized参数
单机均摊模式,requestParamToken请求和Lettuce客户端正在开发中