xidmap

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2017 License: AGPL-3.0, Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// NumShards controls the number of shards the XidMap is broken into. More
	// shards reduces lock contention.
	NumShards int
	// LRUSize controls the total size of the LRU cache. The LRU is split
	// between all shards, so with 4 shards and an LRUSize of 100, each shard
	// receives 25 LRU slots.
	LRUSize int
}

Options controls the performance characteristics of the XidMap.

type UidProvider

type UidProvider interface {
	// ReserveUidRange should give a range of new uids from start to end
	// (start and end are both inclusive).
	ReserveUidRange() (start, end uint64, err error)
}

UidProvider allows the XidMap to obtain ranges of uids that it can then allocate freely. Implementations should expect to be called concurrently.

type XidMap

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

XidMap allocates and tracks mappings between Xids and Uids in a threadsafe manner. It's memory friendly because the mapping is stored on disk, but fast because it uses an LRU cache.

func New

func New(kv *badger.DB, up UidProvider, opt Options) *XidMap

New creates an XidMap with given badger and uid provider.

func (*XidMap) AllocateUid

func (m *XidMap) AllocateUid() (uint64, error)

AllocateUid gives a single uid without creating an xid to uid mapping.

func (*XidMap) AssignUid

func (m *XidMap) AssignUid(xid string) (uid uint64, isNew bool, err error)

AssignUid creates new or looks up existing XID to UID mappings. Any errors returned originate from the UidProvider.

Jump to

Keyboard shortcuts

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