Documentation ¶
Index ¶
- Constants
- func DecodeInt64(b []byte) (int64, error)
- func NewMutationDel(k Key) *mutationDel
- func NewMutationSet(k Key, v []byte) *mutationSet
- type Array
- type BufferedKVStore
- type Codec
- type DBError
- type Dictionary
- func (d *Dictionary) DelAt(key []byte) error
- func (d *Dictionary) Erase()
- func (d *Dictionary) GetAt(key []byte) ([]byte, error)
- func (d *Dictionary) HasAt(key []byte) (bool, error)
- func (d *Dictionary) Iterate(f func(elemKey []byte, value []byte) bool) error
- func (d *Dictionary) Len() uint32
- func (d *Dictionary) SetAt(key []byte, value []byte) error
- type KVStore
- type Key
- type Map
- type MustArray
- type MustCodec
- type MustDictionary
- type MustRCodec
- type MustTimestampedLog
- type Mutation
- type MutationSequence
- type RCodec
- type TimeSlice
- type TimestampedLog
- func (l *TimestampedLog) Append(ts int64, data []byte) error
- func (l *TimestampedLog) Earliest() int64
- func (l *TimestampedLog) Erase()
- func (l *TimestampedLog) Latest() int64
- func (l *TimestampedLog) Len() uint32
- func (l *TimestampedLog) LoadRecordsRaw(fromIdx, toIdx uint32, descending bool) ([][]byte, error)
- func (l *TimestampedLog) TakeTimeSlice(fromTs, toTs int64) (*TimeSlice, error)
- type TimestampedLogRecord
- type WCodec
Constants ¶
const EmptyPrefix = Key("")
Variables ¶
This section is empty.
Functions ¶
func DecodeInt64 ¶
func NewMutationDel ¶
func NewMutationDel(k Key) *mutationDel
func NewMutationSet ¶
Types ¶
type BufferedKVStore ¶
type BufferedKVStore interface { KVStore // the uncommitted mutations Mutations() MutationSequence ClearMutations() Clone() BufferedKVStore Codec() Codec // only for testing! DangerouslyDumpToMap() Map // only for testing! DangerouslyDumpToString() string }
BufferedKVStore represents a KVStore backed by a database. Writes are cached in-memory as a MutationSequence; reads are delegated to the backing database when not cached.
func NewBufferedKVStore ¶
func NewBufferedKVStore(db kvstore.KVStore) BufferedKVStore
type Codec ¶
type Codec interface { RCodec WCodec GetArray(Key) (*Array, error) GetDictionary(Key) (*Dictionary, error) GetTimestampedLog(Key) (*TimestampedLog, error) }
Codec is an interface that offers easy conversions between []byte (scalar) and other types (including complex) when manipulating a KVStore
type DBError ¶
type DBError struct {
// contains filtered or unexported fields
}
Any failed access to the DB will return an instance of DBError
type Dictionary ¶
type Dictionary struct {
// contains filtered or unexported fields
}
func (*Dictionary) DelAt ¶
func (d *Dictionary) DelAt(key []byte) error
func (*Dictionary) Erase ¶
func (d *Dictionary) Erase()
func (*Dictionary) Iterate ¶
func (d *Dictionary) Iterate(f func(elemKey []byte, value []byte) bool) error
func (*Dictionary) Len ¶
func (d *Dictionary) Len() uint32
type KVStore ¶
type KVStore interface { Set(key Key, value []byte) Del(key Key) // Get returns the value, or nil if not found Get(key Key) ([]byte, error) Has(key Key) (bool, error) Iterate(prefix Key, f func(key Key, value []byte) bool) error IterateKeys(prefix Key, f func(key Key) bool) error }
KVStore represents a key-value store where both keys and values are arbitrary byte slices.
type Key ¶
type Key string
Since map cannot have []byte as key, to avoid unnecessary conversions between string and []byte, we use string as key data type, but it does not necessarily have to be a valid UTF-8 string.
func ArrayElemKey ¶
func ArrayRangeKeys ¶
ArrayRangeKeys returns the KVStore keys for the items between [from, to) (`to` being not inclusive), assuming it has `length` elements.
func ArraySizeKey ¶
type Map ¶
type Map interface { KVStore IsEmpty() bool ToGoMap() map[Key][]byte ForEach(func(key Key, value []byte) bool) ForEachDeterministic(func(key Key, value []byte) bool) Clone() Map Read(io.Reader) error Write(io.Writer) error String() string Mutations() MutationSequence Codec() Codec MustCodec() MustCodec }
Map is a KVStore backed by an in-memory map
type MustCodec ¶
type MustCodec interface { MustRCodec WCodec GetArray(Key) *MustArray GetDictionary(Key) *MustDictionary GetTimestampedLog(Key) *MustTimestampedLog }
MustCodec is like a Codec that automatically panics on error
func NewMustCodec ¶
type MustDictionary ¶
type MustDictionary struct {
// contains filtered or unexported fields
}
func (*MustDictionary) DelAt ¶
func (d *MustDictionary) DelAt(key []byte)
func (*MustDictionary) GetAt ¶
func (d *MustDictionary) GetAt(key []byte) []byte
func (*MustDictionary) SetAt ¶
func (d *MustDictionary) SetAt(key []byte, value []byte)
type MustRCodec ¶
type MustRCodec interface { Has(key Key) bool Get(key Key) []byte GetString(key Key) (string, bool) GetInt64(key Key) (int64, bool) GetAddress(key Key) (*address.Address, bool) GetHashValue(key Key) (*hashing.HashValue, bool) }
MustrCodec is like a RCodec that automatically panics on error
type MustTimestampedLog ¶
type MustTimestampedLog struct {
// contains filtered or unexported fields
}
func (*MustTimestampedLog) Append ¶
func (l *MustTimestampedLog) Append(ts int64, data []byte)
func (*MustTimestampedLog) Earliest ¶
func (l *MustTimestampedLog) Earliest() int64
func (*MustTimestampedLog) Latest ¶
func (l *MustTimestampedLog) Latest() int64
func (*MustTimestampedLog) Len ¶
func (l *MustTimestampedLog) Len() uint32
func (*MustTimestampedLog) TakeTimeSlice ¶
func (l *MustTimestampedLog) TakeTimeSlice(fromTs, toTs int64) *TimeSlice
type Mutation ¶
type Mutation interface { Read(io.Reader) error Write(io.Writer) error String() string ApplyTo(kv KVStore) // Key returns the key that is mutated Key() Key // Value returns the value after the mutation (nil if deleted) Value() []byte // contains filtered or unexported methods }
Mutation represents a single "set" or "del" operation over a KVStore
type MutationSequence ¶
type MutationSequence interface { Read(io.Reader) error Write(io.Writer) error String() string Clone() MutationSequence Len() int // Iterate over all mutations in order, even ones affecting the same key repeatedly Iterate(func(mut Mutation) bool) // Iterate over the latest mutation recorded for each key IterateLatest(func(key Key, mut Mutation) bool) // Iterate over the latest value recorded for each non-deleted key IterateValues(prefix Key, f func(key Key, value []byte) bool) (map[Key]bool, bool) Latest(key Key) Mutation Add(mut Mutation) ApplyTo(kv KVStore) }
func NewMutationSequence ¶
func NewMutationSequence() MutationSequence
type RCodec ¶
type RCodec interface { Has(key Key) (bool, error) Get(key Key) ([]byte, error) GetString(key Key) (string, bool, error) GetInt64(key Key) (int64, bool, error) GetAddress(key Key) (*address.Address, bool, error) GetHashValue(key Key) (*hashing.HashValue, bool, error) }
RCodec is an interface that offers easy conversions between []byte and other types when manipulating a read-only KVStore
type TimeSlice ¶
type TimeSlice struct {
// contains filtered or unexported fields
}
func (*TimeSlice) FromToIndices ¶
type TimestampedLog ¶
type TimestampedLog struct {
// contains filtered or unexported fields
}
TimestampedLog implement limitless append-only array of records where each record is indexed sequentially and consistently timestamped sequence of timestamps is considered consistent if for any indices i<j, Ti<=Tj, i.e. non-decreasing
func (*TimestampedLog) Append ¶
func (l *TimestampedLog) Append(ts int64, data []byte) error
Append appends data with timestamp to the end of the log. Returns error if timestamp is inconsistent, i.e. less than the latest timestamp
func (*TimestampedLog) Earliest ¶
func (l *TimestampedLog) Earliest() int64
Earliest returns timestamp of the first record in the log, if any, or otherwise it is 0
func (*TimestampedLog) Erase ¶
func (l *TimestampedLog) Erase()
func (*TimestampedLog) Latest ¶
func (l *TimestampedLog) Latest() int64
Latest returns latest timestamp in the log
func (*TimestampedLog) Len ¶
func (l *TimestampedLog) Len() uint32
Len == 0/empty/non-existent are equivalent
func (*TimestampedLog) LoadRecordsRaw ¶
func (l *TimestampedLog) LoadRecordsRaw(fromIdx, toIdx uint32, descending bool) ([][]byte, error)
LoadRecords returns all records in the slice
func (*TimestampedLog) TakeTimeSlice ¶
func (l *TimestampedLog) TakeTimeSlice(fromTs, toTs int64) (*TimeSlice, error)
TakeTimeSlice returns a slice structure, which contains existing indices firstIdx and lastIdx. Timestamps of all records between indices (inclusive) satisfy the condition >= T(firstIdx) and <=T(lastIdx) Any other pair of indices i1<fistId and/or i2>lastIdx does not satisfy the condition. In other words, returned slice contains all possible indices with timestamps between the two given Returned slice may be empty
type TimestampedLogRecord ¶
func ParseRawLogRecord ¶
func ParseRawLogRecord(raw []byte) (*TimestampedLogRecord, error)
type WCodec ¶
type WCodec interface { Del(key Key) Set(key Key, value []byte) SetString(key Key, value string) SetInt64(key Key, value int64) SetAddress(key Key, value *address.Address) SetHashValue(key Key, value *hashing.HashValue) }
WCodec is an interface that offers easy conversions between []byte and other types when manipulating a write-only KVStore