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

Add bit reverse example to dev-guide-unique-serial-number-generation (#16150) #16291

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion develop/dev-guide-unique-serial-number-generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ uid-generator 生成的 64 位 ID 结构如下:

应用程序每次按配置好的步长获取一段序列号,并同时更新数据库以持久化保存当前序列已被分配出去的最大值,然后在应用程序内存中即可完成序列号加工及分配动作。待一段号码耗尽之后,应用程序才会去获取新的号段,这样就有效降低了数据库写入压力。实际使用过程中,还可以适度调节步长以控制数据库记录的更新频度。

最后,需要注意的是,上述两种方案生成的 ID 都不够随机,不适合直接作为 TiDB 表的主键。实际使用过程中可以对生成的 ID 进行位反转(bit-reverse)后得到一个较为随机的新 ID。
最后,需要注意的是,上述两种方案生成的 ID 都不够随机,不适合直接作为 TiDB 表的主键。实际使用过程中可以对生成的 ID 进行位反转(bit-reverse)后得到一个较为随机的新 ID。例如,经过位反转后,ID `00000010100101000001111010011100` 变为 `00111001011110000010100101000000`,ID `11111111111111111111111111111101` 变为 `10111111111111111111111111111111`