cockroach: github.com/cockroachdb/cockroach/pkg/kv/kvserver/idalloc Index | Files

package idalloc

import "github.com/cockroachdb/cockroach/pkg/kv/kvserver/idalloc"

Index

Package Files

id_alloc.go

type Allocator Uses

type Allocator struct {
    log.AmbientContext
    // contains filtered or unexported fields
}

An Allocator is used to increment a key in allocation blocks of arbitrary size.

func NewAllocator Uses

func NewAllocator(opts Options) (*Allocator, error)

NewAllocator creates a new ID allocator which increments the specified key in allocation blocks of size blockSize. If the key exists, it's assumed to have an int value (and it needs to be positive since id 0 is a sentinel used internally by the allocator that can't be generated). The first value returned is the existing value + 1, or 1 if the key did not previously exist.

func (*Allocator) Allocate Uses

func (ia *Allocator) Allocate(ctx context.Context) (int64, error)

Allocate allocates a new ID from the global KV DB.

type Incrementer Uses

type Incrementer func(_ context.Context, _ roachpb.Key, inc int64) (updated int64, _ error)

Incrementer abstracts over the database which holds the key counter.

func DBIncrementer Uses

func DBIncrementer(
    db interface {
        Inc(ctx context.Context, key interface{}, value int64) (kv.KeyValue, error)
    },
) Incrementer

DBIncrementer wraps a suitable subset of *kv.DB for use with an allocator.

type Options Uses

type Options struct {
    AmbientCtx  log.AmbientContext
    Key         roachpb.Key
    Incrementer Incrementer
    BlockSize   int64
    Stopper     *stop.Stopper
    Fatalf      func(context.Context, string, ...interface{}) // defaults to log.Fatalf
}

Options are the options passed to NewAllocator.

Package idalloc imports 9 packages (graph) and is imported by 2 packages. Updated 2020-08-12. Refresh now. Tools for package owners.