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

创建全局Xid重复问题 #147

Open
menghuan123 opened this issue Feb 22, 2022 · 2 comments
Open

创建全局Xid重复问题 #147

menghuan123 opened this issue Feb 22, 2022 · 2 comments

Comments

@menghuan123
Copy link

image框架如何保证全局xid不重复呢?

@liuyangming
Copy link
Owner

liuyangming commented Feb 22, 2022

ByteJTA/ByteTCC的XID包含有如下信息:

  • 创建该XID信息的计算机的MAC地址: 占6 bytes
  • 时间戳: 占5 bytes;year只保留3 bit,8年内year不会重复;最小单位毫秒,大于1ms时不会出现重复;
  • 全局递增量: 占1 byte
  • 随机数: 占4 bytes

因此,可以看出:

  • 不同机器生成的xid,是不会重复的(通过mac地址保证);
  • 每8年内生成的xid,是不会重复的(时间戳保证);但大于8年,则可能与year-8年同一时间同一机器生成的xid重复;
  • 同一机器同一时间(毫秒)生成的xid数量小于等于256时,全局递增量(1 byte,256个)可保证不重复;
  • 同一机器同一时间(毫秒)生成的xid数量大于256时,通过全局递增量(1 byte,256个)和随机数(共4 bytes, 2^32)共同来避免重复;

总的来说,一台机器上处理的事务量不会太高(几乎不可能到256/ms:小于该值可保障;大于该值则靠随机数避免),且事务存在的时间也不会太长(不太可能超过8年),因此,一般来说,可以认为它是不重复的。

@liuyangming
Copy link
Owner

后续版本可能考虑将递增量占用调大而去掉随机数,且会调大year值。但不管怎样,一般情况下,可默认该值是全局唯一的。

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

2 participants