Documentation ¶
Overview ¶
BundleDB provides several abstractions of common collections which map onto a key-value store. It also looks to optimize reads and writes of collections which have small, nested and/or sequential keys. Writing one big row compared to several smaller rows is more efficient in most KV stores. For this reason, it provides an abstraction which groups keys together.
Index ¶
- Constants
- Variables
- type Bundle
- func (bndl *Bundle) Delete(key Key) (bool, error)
- func (bndl *Bundle) FindBundle(final Decoder, keys ...Key) (*Bundle, error)
- func (bndl *Bundle) FindBundleWithCycle(final Decoder, cycle []Decoder, keys ...Key) (*Bundle, error)
- func (bndl *Bundle) FindList(keys ...Key) (*List, error)
- func (bndl *Bundle) FindMap(keys ...Key) (*Map, error)
- func (bndl *Bundle) FindSet(keys ...Key) (*Set, error)
- func (bndl *Bundle) FindTimeline(keys ...Key) (*Timeline, error)
- func (bndl *Bundle) Iterator() (BundleIterator, error)
- func (bndl *Bundle) Primitive(key Key) (Primitive, error)
- func (bndl *Bundle) Read(key Key) (Value, bool, error)
- func (bndl *Bundle) Write(key Key, value Value) (bool, error)
- type BundleIterator
- type Decoder
- type Key
- type List
- func (d *List) Iterator() (BundleIterator, error)
- func (d *List) LPeek(index Key) ([]byte, bool, error)
- func (d *List) LPop() ([]byte, bool, error)
- func (d *List) LPush(val []byte) error
- func (d *List) RPeek(index Key) ([]byte, bool, error)
- func (d *List) RPop() ([]byte, bool, error)
- func (d *List) RPush(val []byte) error
- type Map
- type Primitive
- type RawVal
- type Root
- type RootList
- type RootMap
- type RootSet
- type RootTimeline
- type Set
- type Timeline
- func (d *Timeline) Current() ([]byte, Key, error)
- func (d *Timeline) Iterator() (BundleIterator, error)
- func (d *Timeline) Past(key Key) ([]byte, bool, error)
- func (d *Timeline) Set(key Key, val []byte) (bool, error)
- func (d *Timeline) SetLatest(val []byte) (bool, error)
- func (d *Timeline) SetNext(val []byte) (bool, error)
- type UserVal
- type Value
Constants ¶
const ( KeyLength = 8 MaxKey = Key(1<<64 - 1) MinKey = Key(0) )
const ( ListLeft = Key(0) ListRight = Key(1) ListTree = Key(2) ListStart = MaxKey / 2 )
const ( MAX_SHARD_MAP_SIZE = 10 MAX_EMBEDDED_MAP_SIZE = 5 MAX_EMBEDDED_MAP_BYTES = 1920 )
const ( MAX_SHARD_SET_SIZE = 10 MAX_EMBEDDED_SET_SIZE = 5 )
const ( TimelineCurrent = Key(0) TimelinePast = Key(1) TimelineCurrentKey = Key(2) )
const ( TupleLeft = Key(0) TupleRight = Key(1) )
Variables ¶
var ( InvalidHeader = errors.New("Invalid Header for object") EmbeddedNotFound = errors.New("Invalid Header for object") // When using FixMap or FixSet, keys are fixed size and values are in fixed locations so // all intermediate nodes are strictly maps. MapPaths = []Decoder{DecodeMap} DecodeSet = setType{} DecodeTuple = tupleType{} DecodeMap = mapType{} DecodeList = listType{} DecodeTimeline = timelineType{} )
Functions ¶
This section is empty.
Types ¶
type Bundle ¶
type Bundle struct {
// contains filtered or unexported fields
}
A bundle Represents a collection that has the ability to automatically shard. The underlying datastructure of a Bundle is determined by what Primitive is backing it. A bundle's primitive can be embedded, in which case no additional database fetches happen, or it can be sharded in which case it will go to the database to fetch the key (if the shard isn't in cache already)
func (*Bundle) FindBundle ¶
Traverse the keys and assume all intermediate nodes are maps. The last key will populate a bundle with the type of `final` and return.
func (*Bundle) FindBundleWithCycle ¶
func (bndl *Bundle) FindBundleWithCycle(final Decoder, cycle []Decoder, keys ...Key) (*Bundle, error)
Traverse the keys and will cycling through Decoders in cycle for the intermediate nodes, repeating the cycle in a loop until all keys are exhausted.
func (*Bundle) FindTimeline ¶
Shortcut to find a Timeline collection
func (*Bundle) Iterator ¶
func (bndl *Bundle) Iterator() (BundleIterator, error)
Start a new key Iterator
func (*Bundle) Primitive ¶
Retrieve the Primitive for `key`, fetching the shard in the DB if necassary.
type BundleIterator ¶
func Chain ¶
func Chain(its ...BundleIterator) BundleIterator
Chain should only be used if you can guarantee that each iterator does not have overlapping keys and the min keys of each iterator are sequential.
func ListIterator ¶
func ListIterator(keys []Key) BundleIterator
Simple Iterator from a slice of keys (Keys should be in order)
func NilIterator ¶
func NilIterator() BundleIterator
type Decoder ¶
type Decoder interface { Table() byte NewPrimitive() Primitive IsPrimitive([]byte) bool IsPointer([]byte) bool }
Holds information about how to decode a Primitive. These are passed when fetching Bundles, so the Bundle knows how to decode the underlying structure.
type List ¶
type List struct {
// contains filtered or unexported fields
}
func (*List) Iterator ¶
func (d *List) Iterator() (BundleIterator, error)
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
func (*Map) Iterator ¶
func (m *Map) Iterator() (BundleIterator, error)
type Primitive ¶
type Primitive interface { Value Max() Key Keys() []Key Write(Key, Value) bool Read(Key) (Value, bool) Delete(Key) bool // Make a pointer to the shard group. This will be embedded as the bundle's new value MakePointer([]byte) []byte // Signal that a shard has data that has changed and needs to be commited. CanDelete() bool // Signal that a shard has data that has changed and needs to be commited. IsDirty() bool // Signal that the Primitive is too big to be embedded and should be copied to a shard CanPopEmbed() bool // Signal that a shard has data that has changed and needs to be commited. CanSplitShard() bool // Split the primitive in 2. The split should place all the highest keys on the object that was called and return a new Primitive with the lowest keys. Split() Primitive // Typically Primitives can be read in a Zero-Copy fashion through pointer casting. This speeds up reads, but is unsafe. FromBytesReadOnly([]byte) error // Returns a write-safe copy of the datastructure. FromBytesWritable([]byte) error // Is a Key in Range of this Primitive's key range InRange(Key) bool }
Primitives are the heart of BundleDB. They define the storage behavior and give the ability to split and shard. Each primitive type has an API much like a DB, you can Write, Read, and Delete values from a primitive. This API gets exposed through a Bundle.
type Root ¶
type Root struct { *Bundle // contains filtered or unexported fields }
Root is a top level bundle. Make sure to defer Close() after opening and Commit() any changes that need to be persisted.
func NewRootWithDecoder ¶
An application will be divided into different Roots. There might be several Root for different indexes and different roots for different collections of data.
type RootTimeline ¶
type RootTimeline struct { *Timeline // contains filtered or unexported fields }
func GetRootTimeline ¶
func GetRootTimeline(root Key, txn *store.Txn) (*RootTimeline, error)
func (*RootTimeline) Close ¶
func (m *RootTimeline) Close()
func (*RootTimeline) Commit ¶
func (m *RootTimeline) Commit() error
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
func (*Set) Iterator ¶
func (d *Set) Iterator() (BundleIterator, error)
type Timeline ¶
type Timeline struct {
// contains filtered or unexported fields
}
func (*Timeline) Iterator ¶
func (d *Timeline) Iterator() (BundleIterator, error)