idutil

package
v2.2.0-alpha.1+incompa... Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2015 License: Apache-2.0 Imports: 3 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generator

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

The initial id is in this format: High order byte is memberID, next 5 bytes are from timestamp, and low order 2 bytes are 0s. | prefix | suffix | | 1 byte | 5 bytes | 2 bytes | | 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 << 65536req/ms.

func NewGenerator

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

func (*Generator) Next

func (g *Generator) Next() uint64

Next generates a id that is unique.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL