xidmap

package
v25.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2025 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Trie

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

Trie is an implementation of Ternary Search Tries to store XID to UID map. It uses Arena to allocate nodes in the trie. It is not thread-safe.

func NewTrie

func NewTrie() *Trie

NewTrie would return back a Trie backed by the provided Arena. Trie would assume ownership of the Arena. Release must be called at the end to release Arena's resources.

func (*Trie) Get

func (t *Trie) Get(key string) uint64

Get would return the UID for the key. If the key is not found, it would return 0.

func (*Trie) Iterate

func (t *Trie) Iterate(fn iterFn) error

func (*Trie) Put

func (t *Trie) Put(key string, uid uint64)

Put would store the UID for the key.

func (*Trie) Release

func (t *Trie) Release()

Release would release the resources used by the Arena.

func (*Trie) Size

func (t *Trie) Size() uint32

Size returns the size of Arena used by this Trie so far.

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(opts XidMapOptions) *XidMap

New creates an XidMap. zero conn must be valid for UID allocations to happen. Optionally, a badger.DB can be provided to persist the xid to uid allocations. This would add latency to the assignment operations. XidMap creates the temporary buffers inside dir directory. The caller must ensure that the dir exists.

func (*XidMap) AllocateUid

func (m *XidMap) AllocateUid() uint64

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

func (*XidMap) AssignUid

func (m *XidMap) AssignUid(xid string) (uint64, bool)

AssignUid creates new or looks up existing XID to UID mappings. It also returns if UID was created.

func (*XidMap) BumpTo

func (m *XidMap) BumpTo(uid uint64)

BumpTo can be used to make Zero allocate UIDs up to this given number. Attempts are made to ensure all future allocations of UIDs be higher than this one, but results are not guaranteed.

func (*XidMap) CheckUid

func (m *XidMap) CheckUid(xid string) bool

func (*XidMap) Flush

func (m *XidMap) Flush() error

Flush must be called if DB is provided to XidMap.

func (*XidMap) SetUid

func (m *XidMap) SetUid(xid string, uid uint64)

type XidMapOptions

type XidMapOptions struct {
	UidAssigner *grpc.ClientConn
	DgClient    *dgo.Dgraph
	DB          *badger.DB
	Dir         string
}

XidMapOptions specifies the options for creating a new xidmap.

Jump to

Keyboard shortcuts

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