Skip to content

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

@rebby665

Description

@rebby665

看设计是系统启动的时候会拿到当前系统时间;作为前缀部分。每次使用都是通过PaddedAtomicLong,参数加上:系统启动的时间 基础上做递增。

    //系统启动获得系统时间戳
      this.lastSecond = new PaddedAtomicLong(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()));
                //通过lastSecond递增生成uid
                 List<Long> 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 比前面的小。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions