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

leaf snowflake真的解决了时钟回拨引起的重复id问题了吗 #216

Open
miles-ton opened this issue Apr 14, 2024 · 0 comments
Open

Comments

@miles-ton
Copy link

举一个栗子:
后台线程每3s会将机器的当前时间同步到zk。假设现在是第9s,后台线程刚刚同步了时间到zk。然后过了2s,并且这两秒有id被发出去。此时机器重启,并且同时发生了时钟回拨,回拨了1s。
leaf snowflake启动的时候会把当前机器时间和zk的上次注册时间做对比,如果小于上次注册时间能判断出发上了回拨,由于这次回拨只回拨了1s,也就是当前机器时间是第10s,是大于第9s的,所以启动能正常启动。然后会继续用第10s做id分发。
现在问题来了,在重启之前实际上是以及分发了2s的id了,也就是说第11s之前的id都以及被分发过。但是重启之后又从10s开始分发id,这个时候不就导致id被重复分发了吗?
求大佬解答一下这个疑问

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant