buildid

package
v0.0.0-...-d3da680 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package buildid provides the build id computation related functions.

Build key: Build keys are autogenerated, monotonically decreasing integers. That is, when sorted by key, new builds are first. Build has no parent.

Build id is a 64 bits integer.

  • 1 highest order bit is set to 0 to keep value positive.
  • 43 bits are 43 lower bits of bitwise-inverted time since beginningOfTheWorld at 1ms resolution. It is good for 2**43 / 365.3 / 24 / 60 / 60 / 1000 = 278 years or 2010 + 278 = year 2288.
  • 16 bits are set to a random value. Assuming an instance is internally consistent with itself, it can ensure to not reuse the same 16 bits in two consecutive requests and/or throttle itself to one request per millisecond. Using random value reduces to 2**-15 the probability of collision on exact same timestamp at 1ms resolution, so a maximum theoretical rate of 65536000 requests/sec but an effective rate in the range of ~64k qps without much transaction conflicts. We should be fine.
  • 4 bits are 0. This is to represent the 'version' of the entity schema.

The idea is taken from Swarming TaskRequest entity: https://source.chromium.org/chromium/_/chromium/infra/luci/luci-py/+/a4a91d5e1e14b8b866b68b68bc1055b0b8ffef3b:appengine/swarming/server/task_request.py;l=1380-1404

Index

Constants

View Source
const (

	// BuildIDMax is the maximum theoretical build ID.
	// Based on time = beginningOfTheWorld, and max values for random and version bits.
	BuildIDMax = int64(0x7FFFFFFFFFFFFFFF)
)

Variables

This section is empty.

Functions

func IDRange

func IDRange(low, high time.Time) (int64, int64)

IDRange converts a creation time range to the build id range. Low/high bounds are inclusive/exclusive respectively for both time and id ranges.

func MayContainBuilds

func MayContainBuilds(low, high time.Time) bool

MayContainBuilds returns true if the time range can possibly contain builds. Zero low/high value means no boundary for low/high.

func NewBuildIDs

func NewBuildIDs(ctx context.Context, t time.Time, n int) []int64

NewBuildIDs generates the given number of build IDs in descending order.

Types

This section is empty.

Jump to

Keyboard shortcuts

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