Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
在Leaf的官方介绍文章中曾经提到分布式ID应该保证信息安全性,
让ID不连续,否则容易被恶意爬取和泄露单量,目前使用snowflake模式生成ID时是有取随机数相关的逻辑来保证ID不连续的,但是如果是Leaf-segment数据库方案来生成ID,每次从数据库取完ID,都是存储在内存中,发放给业务项目,所以运行期间,使用的ID都是连续的,竞争对手很容易通过在两天中午12点分别下单,通过订单id号相减就能大致计算出公司一天的订单量。如果我们在每次从数据库取一个分段的ID时,计算一个随机数,丢弃掉随机数数量的ID,这样就可以保证ID不连续,保证Leaf-segment数据库方案来保证生成ID的安全性。
源代码:SegmentIDGenImpl中updateSegmentFromDb()方法中计算当前ID分段最小值
修改后的代码