"clock sequence" 是什么意思?

What does "clock sequence" mean?

RFC 4122(通用唯一标识符 (UUID) URN 命名空间)使用术语“clock sequence”:

4.1.5. Clock Sequence

For UUID version 1, the clock sequence is used to help avoid duplicates that could arise when the clock is set backwards in time or if the node ID changes.

If the clock is set backwards, or might have been set backwards (e.g., while the system was powered off), and the UUID generator can not be sure that no UUIDs were generated with timestamps larger than the value to which the clock was set, then the clock sequence has to be changed. If the previous value of the clock sequence is known, it can just be incremented; otherwise it should be set to a random or high-quality pseudo-random value.

Similarly, if the node ID changes (e.g., because a network card has been moved between machines), setting the clock sequence to a random number minimizes the probability of a duplicate due to slight differences in the clock settings of the machines. If the value of clock sequence associated with the changed node ID were known, then the clock sequence could just be incremented, but that is unlikely.

The clock sequence MUST be originally (i.e., once in the lifetime of a system) initialized to a random number to minimize the correlation across systems. This provides maximum protection against node identifiers that may move or switch from system to system rapidly. The initial value MUST NOT be correlated to the node identifier.

For UUID version 3 or 5, the clock sequence is a 14-bit value constructed from a name as described in Section 4.3.

For UUID version 4, clock sequence is a randomly or pseudo-randomly generated 14-bit value as described in Section 4.4.

这个词是什么意思?

它是构成 UUID 的字段之一,如 4.1.2 节中所定义。

"Clock Sequence" 似乎是一个非常具有误导性的名称。根据其定义,更好的名称可能是 "Random Component of uuid".

uuid 的一个重要声明是,如果我们都生成一个 UUID 值,我们可以非常确信我们不会生成相同的 128 位值。这说明了碰撞的可能性。

如果我们有一个共同的协调员或一个预先商定的方案,我们也可以确信我们不会遇到冲突。

潜在方案:

1. Partition Int Space: I get numbers 1-999, you get 1000-1999.
2. Request Reservation: Request 10 numbers and increment a centrally stored max reserved numbers.  You get numbers 1-10.  The next reservation gets 11-20.

主要的 UUID 观察是,如果您有相当多的位(在本例中为 16),下一个请求者不太可能获得相同的随机值。

彩票就是基于这个概念。

https://pubs.opengroup.org/onlinepubs/9629399/apdxa.htm#tagcjh_20_02_01讲时钟序列的生成算法

综上所述,就是程序开始时产生的随机数。每次都增加

  • 检测到本地UTC时间倒退
  • 由于应用重启,未设置之前的UTC时间

术语“时钟序列”是用词不当。它只是一个随机数,不是一个序列。

时钟序列仅用于一个目的:帮助避免重复

RFC-4122 指出在以下情况下必须更改时钟序列:

  • 时钟倒转了;
  • 时钟可能调反了;
  • 生成器不确定时钟是否向后;
  • 节点标识符已更改;
  • 节点标识符混淆了。

时钟序列“可以递增”(就像一个序列)。但这是可能的,而不是应该的。我发现一些实现总是随机化时钟序列 here and here.

我认为“序列”这个词会造成混淆。虽然时钟序列在递增时表现得像一个序列,但它实际上是一个随机数。

UUID v1有3个部分,即:

  • time(自 1582 年 10 月 15 日以来 100 纳米的数量);
  • place (IEEE 地址);
  • 一些熵(时钟序列)。

在这个 Github 问题中,您可以找到有关时钟序列的讨论:https://github.com/uuid6/uuid6-ietf-draft/issues/41