Class TimeBasedKOrderedUUIDGenerator

java.lang.Object
org.elasticsearch.common.TimeBasedKOrderedUUIDGenerator

public class TimeBasedKOrderedUUIDGenerator extends Object
Generates a base64-encoded, k-ordered UUID string optimized for compression and efficient indexing.

This method produces a time-based UUID where slowly changing components like the timestamp appear first, improving prefix-sharing and compression during indexing. It ensures uniqueness across nodes by incorporating a timestamp, a MAC address, and a sequence ID.

Timestamp: Represents the current time in milliseconds, ensuring ordering and uniqueness.
MAC Address: Ensures uniqueness across different coordinators.
Sequence ID: Differentiates UUIDs generated within the same millisecond, ensuring uniqueness even at high throughput.

The result is a compact base64-encoded string, optimized for efficient compression of the _id field in an inverted index.

  • Field Details

    • sequenceNumber

      protected final AtomicInteger sequenceNumber
    • lastTimestamp

      protected final AtomicLong lastTimestamp
    • timestampSupplier

      protected final Supplier<Long> timestampSupplier
  • Constructor Details

    • TimeBasedKOrderedUUIDGenerator

      public TimeBasedKOrderedUUIDGenerator(Supplier<Long> timestampSupplier, Supplier<Integer> sequenceIdSupplier, Supplier<byte[]> macAddressSupplier)
  • Method Details

    • getBase64UUID

      public String getBase64UUID()
    • getBase64UUID

      public String getBase64UUID(OptionalInt hash)
    • macAddress

      protected byte[] macAddress()