baidu / baidu/uid-generator

使用CachedUidGenerator 在分布式情况下没办法做到有序。

Open
#97 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
5.6k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

#### 看设计是系统启动的时候会拿到当前系统时间;作为前缀部分。每次使用都是通过PaddedAtomicLong,参数加上:系统启动的时间 基础上做递增。
```java
//系统启动获得系统时间戳
this.lastSecond = new PaddedAtomicLong(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()));
//通过lastSecond递增生成uid
List uidList = uidProvider.provide(lastSecond.incrementAndGet());

```
- 比如我有a,b两个节点。大量流量打到a节点,a节点会使用本地的批量生成的uid 。但是b节点一直没有使用。当有流量突然打到b节点。那么b节点生成的id就会比a节点生成的小。因为b节点的uid在后面使用的。

- 例子: 系统初始化时间=10:00
- a节点 10:00 1010+a 1011+a 1012+a
- b节点 10:00 ------------------------>1010+b

- 数据库生成的数据顺序: 1010+a 1011+a 1012+a 1010+b

- 从这个例子上看到最后生成的 1010+b 比前面的小。

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with CachedUidGenerator and its PaddedAtomicLong/uidProvider path. Reproduce the two-node sequence described in the issue, with one node generating many IDs while the other is idle, and inspect the resulting order. The issue does not specify a proposed change or acceptance criterion, so confirm the intended ordering guarantee before estimating completion.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, distributed-systems
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.