state

package
v0.0.0-...-2c4dd60 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2022 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const StructTag = "tree"

Variables

View Source
var (
	ErrWrongType         = errors.New("wrong type")
	ErrNodeEncoding      = errors.New("corrupted encoding for node")
	ErrInvalidRange      = errors.New("invalid range")
	ErrRangeOverNonSlice = errors.New("range over non-slice")
	ErrNilKeypath        = errors.New("nil keypath")
)
View Source
var (
	CurrentVersion = Version{}
)
View Source
var ErrBadKeypath = errors.New("bad keypath")
View Source
var KeypathSeparator = Keypath("/")

Functions

func DecodeSliceIndex

func DecodeSliceIndex(k Keypath) uint64

func DecodeSliceLen

func DecodeSliceLen(k Keypath) uint64

func ParseKeypathAndRange

func ParseKeypathAndRange(s []byte, keypathSeparator byte) (Keypath, *Range, error)

Types

type DBNode

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

func (*DBNode) BoolValue

func (tx *DBNode) BoolValue(keypath Keypath) (bool, bool, error)

func (*DBNode) BytesValue

func (tx *DBNode) BytesValue(keypath Keypath) ([]byte, bool, error)

func (*DBNode) ChildIterator

func (n *DBNode) ChildIterator(relKeypath Keypath, prefetchValues bool, prefetchSize int) Iterator

func (*DBNode) Close

func (tx *DBNode) Close()

func (*DBNode) CopyToMemory

func (tx *DBNode) CopyToMemory(relKeypath Keypath, rng *Range) (n Node, err error)

func (*DBNode) DebugPrint

func (tx *DBNode) DebugPrint(printFn func(inFormat string, args ...interface{}), newlines bool, indentLevel int)

func (*DBNode) Delete

func (tx *DBNode) Delete(relKeypath Keypath, rng *Range) (err error)

func (*DBNode) DepthFirstIterator

func (n *DBNode) DepthFirstIterator(relKeypath Keypath, prefetchValues bool, prefetchSize int) Iterator

func (*DBNode) Diff

func (tx *DBNode) Diff() *Diff

func (*DBNode) Exists

func (n *DBNode) Exists(relKeypath Keypath) (bool, error)

func (*DBNode) FloatValue

func (tx *DBNode) FloatValue(keypath Keypath) (float64, bool, error)

func (*DBNode) IndexOfMapSubkey

func (node *DBNode) IndexOfMapSubkey(relKeypathOfMap Keypath, subkey Keypath) (uint64, error)

func (*DBNode) IntValue

func (tx *DBNode) IntValue(keypath Keypath) (int64, bool, error)

func (*DBNode) Iterator

func (n *DBNode) Iterator(relKeypath Keypath, prefetchValues bool, prefetchSize int) Iterator

func (*DBNode) Keypath

func (tx *DBNode) Keypath() Keypath

func (*DBNode) Length

func (tx *DBNode) Length() (uint64, error)

func (*DBNode) MapValue

func (tx *DBNode) MapValue(keypath Keypath) (map[string]interface{}, bool, error)

func (*DBNode) MarshalJSON

func (n *DBNode) MarshalJSON() ([]byte, error)

func (*DBNode) NodeAt

func (n *DBNode) NodeAt(keypath Keypath, rng *Range) Node

func (*DBNode) NodeInfo

func (n *DBNode) NodeInfo(keypath Keypath) (NodeType, ValueType, uint64, error)

func (*DBNode) NthMapSubkey

func (node *DBNode) NthMapSubkey(relKeypathOfMap Keypath, n uint64) Keypath

NthSubkey finds the Nth direct subkey in a map.

func (*DBNode) NumSubkeys

func (tx *DBNode) NumSubkeys() uint64

func (*DBNode) ParentNodeFor

func (n *DBNode) ParentNodeFor(keypath Keypath) (Node, Keypath)

func (*DBNode) ResetDiff

func (tx *DBNode) ResetDiff()

func (*DBNode) Save

func (tx *DBNode) Save() error

func (*DBNode) Scan

func (node *DBNode) Scan(into interface{}) error

func (*DBNode) Set

func (tx *DBNode) Set(relKeypath Keypath, rng *Range, val interface{}) error

func (*DBNode) SliceValue

func (tx *DBNode) SliceValue(keypath Keypath) ([]interface{}, bool, error)

func (*DBNode) StringValue

func (tx *DBNode) StringValue(keypath Keypath) (string, bool, error)

func (*DBNode) Subkeys

func (tx *DBNode) Subkeys() []Keypath

func (*DBNode) UintValue

func (tx *DBNode) UintValue(keypath Keypath) (uint64, bool, error)

func (*DBNode) Value

func (tx *DBNode) Value(relKeypath Keypath, rng *Range) (_ interface{}, _ bool, err error)

type DBTree

type DBTree struct {
	log.Logger
	// contains filtered or unexported fields
}

func NewDBTree

func NewDBTree(badgerOpts badger.Options) (*DBTree, error)

func (*DBTree) Close

func (t *DBTree) Close() error

func (*DBTree) DebugPrint

func (t *DBTree) DebugPrint(keypathPrefix Keypath, rng *Range) ([]Keypath, []interface{}, error)

func (*DBTree) DeleteDB

func (t *DBTree) DeleteDB() error

func (*DBTree) Filename

func (t *DBTree) Filename() string

func (*DBTree) State

func (t *DBTree) State(mutable bool) *DBNode

type Diff

type Diff struct {
	Added       map[string]struct{}
	AddedList   []Keypath
	Removed     map[string]struct{}
	RemovedList []Keypath
	// contains filtered or unexported fields
}

func NewDiff

func NewDiff() *Diff

func (*Diff) Add

func (d *Diff) Add(keypath Keypath)

func (*Diff) AddMany

func (d *Diff) AddMany(keypaths []Keypath)

func (*Diff) Copy

func (d *Diff) Copy() *Diff

func (*Diff) Enabled

func (d *Diff) Enabled() bool

func (*Diff) Remove

func (d *Diff) Remove(keypath Keypath)

func (*Diff) RemoveMany

func (d *Diff) RemoveMany(keypaths []Keypath)

func (*Diff) SetEnabled

func (d *Diff) SetEnabled(enabled bool)

type EncryptionConfig

type EncryptionConfig struct {
	Key                 []byte        `json:"key"`
	KeyRotationInterval time.Duration `json:"rotationInterval"`
}

type Indexer

type Indexer interface {
	IndexNode(relKeypath Keypath, state Node) (Keypath, Node, error)
}

type Iterator

type Iterator interface {
	RootKeypath() Keypath
	Rewind()
	SeekTo(relKeypath Keypath)
	Valid() bool
	Next()
	Node() Node
	NodeCopy() Node
	Close()
	// contains filtered or unexported methods
}

type Keypath

type Keypath []byte

func EncodeSliceIndex

func EncodeSliceIndex(x uint64) Keypath

func EncodeSliceLen

func EncodeSliceLen(x uint64) Keypath

func JoinKeypaths

func JoinKeypaths(s []Keypath) Keypath

func NewPopulatedKeypath

func NewPopulatedKeypath(_ gogoprotobufTest) *Keypath

func (Keypath) CommonAncestor

func (k Keypath) CommonAncestor(other Keypath) Keypath

func (Keypath) Compare

func (k Keypath) Compare(other Keypath) int

func (Keypath) ContainsByte

func (k Keypath) ContainsByte(b byte) bool

func (Keypath) ContainsPart

func (k Keypath) ContainsPart(part Keypath) bool

func (Keypath) ContainsSeparator

func (k Keypath) ContainsSeparator() bool

func (Keypath) Copy

func (k Keypath) Copy() Keypath

func (Keypath) Equal

func (k Keypath) Equal(other Keypath) bool

func (Keypath) Equals

func (k Keypath) Equals(other Keypath) bool

func (Keypath) FirstNParts

func (k Keypath) FirstNParts(n int) Keypath

func (Keypath) IndexByte

func (k Keypath) IndexByte(b byte) int

func (Keypath) LastNParts

func (k Keypath) LastNParts(n int) Keypath

LastNParts returns the N right-most Keypath components (or nil if there less than the requested number of components). Any trailing path sep chars are effectively ignored.

"1/22/333".LastNParts(1) => "333"

"1/22/333".LastNParts(2) => "22/333"

"1/22/333/".LastNParts(2) => "22/333"

"1/22/333/".LastNParts(4) => nil

func (Keypath) LengthAsParent

func (k Keypath) LengthAsParent() int

func (Keypath) Marshal

func (k Keypath) Marshal() ([]byte, error)

func (Keypath) MarshalJSON

func (k Keypath) MarshalJSON() ([]byte, error)

func (*Keypath) MarshalTo

func (k *Keypath) MarshalTo(data []byte) (n int, err error)

func (Keypath) Normalized

func (k Keypath) Normalized() Keypath

func (Keypath) NumParts

func (k Keypath) NumParts() int

func (Keypath) Part

func (k Keypath) Part(partIdx int) Keypath

func (Keypath) PartStrings

func (k Keypath) PartStrings() []string

func (Keypath) Parts

func (k Keypath) Parts() []Keypath

func (Keypath) Pop

func (k Keypath) Pop() (rest Keypath, top Keypath)

func (Keypath) Push

func (k Keypath) Push(part Keypath) Keypath

func (Keypath) PushIndex

func (k Keypath) PushIndex(idx uint64) Keypath

func (Keypath) Pushb

func (k Keypath) Pushb(part []byte) Keypath

func (Keypath) Pushs

func (k Keypath) Pushs(part string) Keypath

func (Keypath) RelativeTo

func (k Keypath) RelativeTo(root Keypath) Keypath

func (Keypath) Shift

func (k Keypath) Shift() (top Keypath, rest Keypath)

func (*Keypath) Size

func (k *Keypath) Size() int

func (Keypath) StartsWith

func (k Keypath) StartsWith(prefixParts Keypath) bool

func (Keypath) String

func (k Keypath) String() string

func (*Keypath) Unmarshal

func (k *Keypath) Unmarshal(data []byte) error

func (*Keypath) UnmarshalJSON

func (k *Keypath) UnmarshalJSON(data []byte) error

func (Keypath) Unshift

func (k Keypath) Unshift(part Keypath) Keypath

type MapKey

type MapKey interface {
	MapKey() (Keypath, error)
}

type MapKeyScanner

type MapKeyScanner interface {
	ScanMapKey(keypath Keypath) error
}

type MemoryNode

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

func NewMemoryNode

func NewMemoryNode() *MemoryNode

func NewMemoryNodeWithValue

func NewMemoryNodeWithValue(value interface{}) *MemoryNode

func (*MemoryNode) BoolValue

func (n *MemoryNode) BoolValue(keypath Keypath) (bool, bool, error)

func (*MemoryNode) BytesValue

func (n *MemoryNode) BytesValue(keypath Keypath) ([]byte, bool, error)

func (*MemoryNode) ChildIterator

func (n *MemoryNode) ChildIterator(keypath Keypath, prefetchValues bool, prefetchSize int) Iterator

func (*MemoryNode) Close

func (n *MemoryNode) Close()

func (*MemoryNode) CopyToMemory

func (t *MemoryNode) CopyToMemory(keypath Keypath, rng *Range) (Node, error)

CopyToMemory returns a copy of the node at the given keypath.

func (*MemoryNode) DebugContents

func (n *MemoryNode) DebugContents(keypathPrefix Keypath, rng *[2]uint64) ([]Keypath, []interface{}, map[string]NodeType, error)

func (*MemoryNode) DebugPrint

func (t *MemoryNode) DebugPrint(printFn func(inFormat string, args ...interface{}), newlines bool, indentLevel int)

func (*MemoryNode) Delete

func (n *MemoryNode) Delete(keypath Keypath, rng *Range) error

func (*MemoryNode) DepthFirstIterator

func (n *MemoryNode) DepthFirstIterator(keypath Keypath, prefetchValues bool, prefetchSize int) Iterator

func (*MemoryNode) Diff

func (n *MemoryNode) Diff() *Diff

func (*MemoryNode) Exists

func (n *MemoryNode) Exists(keypath Keypath) (bool, error)

Exists returns a boolean representing whether the given keypath has been set in the subtree for this node. For a MemoryNode, it never returns an error.

func (*MemoryNode) FloatValue

func (n *MemoryNode) FloatValue(keypath Keypath) (float64, bool, error)

func (*MemoryNode) IndexOfMapSubkey

func (node *MemoryNode) IndexOfMapSubkey(rootKeypath Keypath, subkey Keypath) (uint64, error)

func (*MemoryNode) IntValue

func (n *MemoryNode) IntValue(keypath Keypath) (int64, bool, error)

func (*MemoryNode) Iterator

func (n *MemoryNode) Iterator(keypath Keypath, prefetchValues bool, prefetchSize int) Iterator

func (*MemoryNode) Keypath

func (n *MemoryNode) Keypath() Keypath

func (*MemoryNode) Length

func (n *MemoryNode) Length() (uint64, error)

func (*MemoryNode) MapValue

func (n *MemoryNode) MapValue(keypath Keypath) (map[string]interface{}, bool, error)

func (*MemoryNode) MarshalJSON

func (n *MemoryNode) MarshalJSON() ([]byte, error)

func (*MemoryNode) NodeAt

func (n *MemoryNode) NodeAt(relKeypath Keypath, rng *Range) Node

NodeAt returns the tree.Node corresponding to the given keypath in the state tree. If the keypath doesn't exist, a MemoryNode is still returned, but calling .Value on it will return a result with NodeTypeInvalid.

func (*MemoryNode) NodeInfo

func (n *MemoryNode) NodeInfo(relKeypath Keypath) (NodeType, ValueType, uint64, error)

NodeInfo returns metadata about the node: its NodeType, its ValueType (if applicable), and the Content-Length of its value.

func (*MemoryNode) NthMapSubkey

func (node *MemoryNode) NthMapSubkey(rootKeypath Keypath, n uint64) (Keypath, error)

func (*MemoryNode) NumSubkeys

func (n *MemoryNode) NumSubkeys() uint64

func (*MemoryNode) ParentNodeFor

func (n *MemoryNode) ParentNodeFor(relKeypath Keypath) (x Node, y Keypath)

ParentNodeFor in most cases returns the method's receiver. But in the case where another tree.Node has been .Set into the receiver's state tree at some point in the provided keypath, it will return the deepest tree.Node corresponding to that keypath. The returned keypath is the provided keypath, relative to the deepest tree.Node.

func (*MemoryNode) ResetDiff

func (n *MemoryNode) ResetDiff()

func (*MemoryNode) Scan

func (n *MemoryNode) Scan(into interface{}) error

func (*MemoryNode) Set

func (t *MemoryNode) Set(keypath Keypath, rng *Range, value interface{}) error

func (*MemoryNode) SliceValue

func (n *MemoryNode) SliceValue(keypath Keypath) ([]interface{}, bool, error)

func (*MemoryNode) StringValue

func (n *MemoryNode) StringValue(keypath Keypath) (string, bool, error)

func (*MemoryNode) Subkeys

func (n *MemoryNode) Subkeys() []Keypath

Subkeys returns only the keys that are direct descendants of the given node.

func (*MemoryNode) UintValue

func (n *MemoryNode) UintValue(keypath Keypath) (uint64, bool, error)

func (*MemoryNode) UnmarshalJSON

func (n *MemoryNode) UnmarshalJSON(bs []byte) error

func (*MemoryNode) Value

func (n *MemoryNode) Value(keypath Keypath, rng *Range) (interface{}, bool, error)

Value returns the native Go value at the given keypath and range.

type Node

type Node interface {
	Close()

	Keypath() Keypath
	NodeInfo(keypath Keypath) (NodeType, ValueType, uint64, error)
	Length() (uint64, error)
	Subkeys() []Keypath
	NumSubkeys() uint64
	IndexOfMapSubkey(rootKeypath Keypath, subkey Keypath) (uint64, error)
	// NthMapSubkey(rootKeypath Keypath, n uint64) (Keypath, error)
	Exists(keypath Keypath) (bool, error)
	NodeAt(keypath Keypath, rng *Range) Node
	ParentNodeFor(keypath Keypath) (Node, Keypath)
	DebugPrint(printFn func(inFormat string, args ...interface{}), newlines bool, indentLevel int)

	Value(keypath Keypath, rng *Range) (interface{}, bool, error)
	UintValue(keypath Keypath) (uint64, bool, error)
	IntValue(keypath Keypath) (int64, bool, error)
	FloatValue(keypath Keypath) (float64, bool, error)
	BoolValue(keypath Keypath) (bool, bool, error)
	StringValue(keypath Keypath) (string, bool, error)
	BytesValue(keypath Keypath) ([]byte, bool, error)
	MapValue(keypath Keypath) (map[string]interface{}, bool, error)
	SliceValue(keypath Keypath) ([]interface{}, bool, error)
	Scan(into interface{}) error

	Set(keypath Keypath, rng *Range, val interface{}) error
	Delete(keypath Keypath, rng *Range) error

	Diff() *Diff
	ResetDiff()
	CopyToMemory(keypath Keypath, rng *Range) (Node, error)

	Iterator(keypath Keypath, prefetchValues bool, prefetchSize int) Iterator
	ChildIterator(keypath Keypath, prefetchValues bool, prefetchSize int) Iterator
	DepthFirstIterator(keypath Keypath, prefetchValues bool, prefetchSize int) Iterator
	// contains filtered or unexported methods
}

A Node is a view over the database at a particular keypath

type NodeRange

type NodeRange interface {
	Length() (uint64, error)
	Subkeys() []Keypath
	NumSubkeys() uint64
	Value(keypath Keypath, rng *Range) (interface{}, bool, error)
}

type NodeType

type NodeType uint8
const (
	NodeTypeInvalid NodeType = iota
	NodeTypeValue
	NodeTypeMap
	NodeTypeSlice
	NodeTypeNode
)

func (NodeType) String

func (nt NodeType) String() string

type Range

type Range = pb.Range

type StateBytesMarshaler

type StateBytesMarshaler interface {
	MarshalStateBytes() ([]byte, error)
}

type StateBytesUnmarshaler

type StateBytesUnmarshaler interface {
	UnmarshalStateBytes(bs []byte) error
}

type ValueType

type ValueType uint8
const (
	ValueTypeInvalid ValueType = iota
	ValueTypeString
	ValueTypeBytes
	ValueTypeUint
	ValueTypeInt
	ValueTypeFloat
	ValueTypeBool
	ValueTypeNil
)

func (ValueType) String

func (vt ValueType) String() string

type Version

type Version [32]byte

func NewPopulatedVersion

func NewPopulatedVersion(_ gogoprotobufTest) *Version

func RandomVersion

func RandomVersion() Version

func VersionFromBytes

func VersionFromBytes(bs []byte) Version

func VersionFromHex

func VersionFromHex(h string) (Version, error)

func VersionFromString

func VersionFromString(s string) Version

func (Version) Bytes

func (id Version) Bytes() []byte

func (Version) Compare

func (id Version) Compare(other Version) int

func (Version) Equal

func (id Version) Equal(other Version) bool

func (Version) Hex

func (id Version) Hex() string

func (Version) MapKey

func (id Version) MapKey() (Keypath, error)

func (Version) Marshal

func (id Version) Marshal() ([]byte, error)

func (Version) MarshalJSON

func (id Version) MarshalJSON() ([]byte, error)

func (Version) MarshalText

func (id Version) MarshalText() ([]byte, error)

func (*Version) MarshalTo

func (id *Version) MarshalTo(data []byte) (n int, err error)

func (Version) Pretty

func (id Version) Pretty() string

func (*Version) ScanMapKey

func (id *Version) ScanMapKey(keypath Keypath) error

func (*Version) Size

func (id *Version) Size() int

func (Version) String

func (id Version) String() string

func (*Version) Unmarshal

func (id *Version) Unmarshal(data []byte) error

func (*Version) UnmarshalJSON

func (id *Version) UnmarshalJSON(data []byte) error

func (*Version) UnmarshalText

func (id *Version) UnmarshalText(text []byte) error

type VersionSet

type VersionSet map[Version]struct{}

func NewVersionSet

func NewVersionSet(vals []Version) VersionSet

func (VersionSet) Add

func (s VersionSet) Add(val Version) VersionSet

func (VersionSet) Any

func (s VersionSet) Any() Version

func (VersionSet) Copy

func (s VersionSet) Copy() VersionSet

func (VersionSet) Remove

func (s VersionSet) Remove(val Version) VersionSet

func (VersionSet) Slice

func (s VersionSet) Slice() []Version

type VersionedDBTree

type VersionedDBTree struct {
	log.Logger
	// contains filtered or unexported fields
}

func NewVersionedDBTree

func NewVersionedDBTree(badgerOpts badger.Options) (*VersionedDBTree, error)

func (*VersionedDBTree) BuildIndex

func (t *VersionedDBTree) BuildIndex(version *Version, node Node, indexName Keypath, indexer Indexer) (err error)

func (*VersionedDBTree) Close

func (t *VersionedDBTree) Close() error

func (*VersionedDBTree) CopyVersion

func (t *VersionedDBTree) CopyVersion(dstVersion, srcVersion Version) error

func (*VersionedDBTree) DeleteDB

func (t *VersionedDBTree) DeleteDB() error

func (*VersionedDBTree) IndexAtVersion

func (t *VersionedDBTree) IndexAtVersion(version *Version, keypath Keypath, indexName Keypath, mutable bool) *DBNode

func (*VersionedDBTree) StateAtVersion

func (t *VersionedDBTree) StateAtVersion(version *Version, mutable bool) *DBNode

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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