Skip to content
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 rule id conflict #2967

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

fix rule id conflict #2967

wants to merge 6 commits into from

Conversation

garroshh
Copy link
Contributor

Describe what this PR does / why we need it

dashboard 接入外接数据源后,当dashboard重启后id自增会被重置,或dashboard为多副本时规则id会出现相同的自增数字id,导致生成重复的规则id。

Does this pull request fix one issue?

Fixes #2932

Describe how you did it

采用雪花算法,做到尽可能小的概率id冲突。
尽可能小的原因是雪花算法中间的机器位数,需要借助中间件如mysql或zk来分配机房,机器等ID,或者借助配置文件自己分配,为了不引入中间件,所以机器位数这里采用了随机数,为了不超出long的限制,这里取了0-999随机数。

@CLAassistant
Copy link

CLAassistant commented Nov 22, 2022

CLA assistant check
All committers have signed the CLA.

@sczyh30 sczyh30 added kind/enhancement Category issues or prs related to enhancement. to-review To review area/dashboard Issues or PRs about Sentinel Dashboard labels Nov 22, 2022
@wilsonwu
Copy link
Contributor

wilsonwu commented Dec 9, 2022

Confirmed this is already working in our private version of sentinel dashboard.

Copy link
Contributor

@jnan806 jnan806 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

采用时间戳的话,在多副本情况下,会存在时钟回拨引起 id 重复问题😃

@wilsonwu
Copy link
Contributor

采用时间戳的话,在多副本情况下,会存在时钟回拨引起 id 重复问题😃

是的,这个之前也考虑到有风险,所以加了一个随机数,由于创建规则的频率和密度通常是非常低的,所以觉得这个问题被触发的几率极低,我认为可以接受,如果真的要完全唯一的id,不借助额外组件是不能实现的,所以权衡了一下觉得这个方式是性价比最高的,可以听听你的建议。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/dashboard Issues or PRs about Sentinel Dashboard kind/enhancement Category issues or prs related to enhancement. to-review To review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sentinel Dashboard多副本或重启后规则ID不正常的问题
5 participants