Back to godoc.org
go.etcd.io/etcd / pkg / idutil

Package idutil

v3.3.22+incompatible
Latest Go to latest

The latest major version is .

Published: May 20, 2020 | License: Apache-2.0 | Module: go.etcd.io/etcd

Overview

Package idutil implements utility functions for generating unique, randomized ids.

Index

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator generates unique identifiers based on counters, timestamps, and a node member ID.

The initial id is in this format: High order 2 bytes are from memberID, next 5 bytes are from timestamp, and low order one byte is a counter. | prefix | suffix | | 2 bytes | 5 bytes | 1 byte | | memberID | timestamp | cnt |

The timestamp 5 bytes is different when the machine is restart after 1 ms and before 35 years.

It increases suffix to generate the next id. The count field may overflow to timestamp field, which is intentional. It helps to extend the event window to 2^56. This doesn't break that id generated after restart is unique because etcd throughput is << 256req/ms(250k reqs/second).

func NewGenerator

func NewGenerator(memberID uint16, now time.Time) *Generator

func (*Generator) Next

func (g *Generator) Next() uint64

Next generates a id that is unique.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier