-
Notifications
You must be signed in to change notification settings - Fork 173
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
[GLCC] Implement Sequencer API with snowflake algorithm #193
Comments
assign to me pls, thanks for your replys and tips |
阿里云有NTP服务器,可以参考下 : https://help.aliyun.com/document_detail/92704.html |
This issue has been automatically marked as stale because it has not had recent activity in the last 30 days. It will be closed in the next 7 days unless it is tagged (pinned, good first issue or help wanted) or other activity occurs. Thank you for your contributions. |
This issue has been automatically closed because it has not had activity in the last 37 days. If this issue is still valid, please ping a maintainer and ask them to label it as pinned, good first issue or help wanted. Thank you for your contributions. |
@keleqnma Hi, are u still working on it? |
This issue will participate in the chinese GLCC activity 1.题目描述Layotto Sequencer API 的雪花算法实现 2.编码任务
3.技能要求和编程语言
4.预期完成的结果
5.题目详情Layotto Sequencer API已经有了基于redis、zookeeper、etcd的自增id实现,基于mysql与postgresql的实现也已经提交pr,雪花算法的实现存在一定的难度。在这里不细说雪花算法的距离原理,其实现分成时间戳+机器id+序列号三部分,且能保证递增和全局唯一。但由于机器时间的不确定性,,有可能会发生时间漂移出现时间回退 的现象,则会出现数据重复和非递增性。可以参考业界的方案来解决此问题。 参考文档: 导师价值扩展Layotto的Sequencer API,提供更多的选择。 |
This issue has been automatically marked as stale because it has not had recent activity in the last 30 days. It will be closed in the next 7 days unless it is tagged (pinned, good first issue or help wanted) or other activity occurs. Thank you for your contributions. |
进展: |
@OOOOlh 可以展开说一下这里吗。按这种方式,delta seconds已经和时间没有什么关系了。 |
1、传统雪花算法是完全依赖时间,所以发生时钟回拨后容易出问题。所以为了减少对时间的依赖,就采取序列依次+1,满后delta seconds +1的方法。只在程序启动时读取当前时间(这个时间一般是比上次RingBuffer中的uid的时间戳晚的),这也可以保证趋势递增。这种方法的一个主要不足是业务请求的uid反解析后的时间不是业务真实发生的时间,我不确定这个影响算不算大。 |
这个问题应该不大,只要是递增的就行
还有这里,按照上面的设计,每次启动不都是获取的新的workid吗?那么时间戳从0开始不都可以? |
百度的这个雪花算法顺序是sign+delta seconds+work id +sequence,delta seconds在高位,所以必须读当前时间。@ZLBer |
好,我大概明白了,就是不再依赖于物理时间。可以大概描述下整个id生成的过程,然后可以写代码了。 |
@seeflood 周老师看下方案吧 |
1、程序开始时,从mysql读workid,再结合当前时间生成uid,并填满整个RingBuffer; |
What would you like to be added:
Implement Sequencer API with snowflake algorithm.
We need to be careful to avoid clock rollback problems.
Reference:
I don't know if we can ignore clock rollback problem just warning in the document "Hey,please use a reliable NTP server which prevent clock rollback. Otherwise the generated id might duplicate."
为了解决时钟回拨问题,得依赖存储;
我不确定能否无视时钟回拨问题、省掉存储,仅仅声明“我们不帮你解决时钟回拨问题,请使用一个可靠的NTP服务器、让他确保你的机器不会时钟回拨”。我不确定有没有这样的NTP服务(我记得即使关闭NTP同步,闰秒还是会导致回拨?)
Why is this needed:
Snowflake algorithms is a useful tool to generate distributed unique id.
The text was updated successfully, but these errors were encountered: