Documentation
¶
Overview ¶
Package llrb implement a self-balancing verions of binary-tree, called, LLRB (Left Leaning Red Black).
- Index key, value (value is optional).
- Each key shall be unique within the index sample-set.
- Configurable memory backend.
- In single-threaded settings, reads and writes are serialized.
MVCC instances support serialized writes and concurrent reads.
Index ¶
- func Defaultsettings() s.Settings
- func LogComponents(components ...string)
- type Cursor
- func (cur *Cursor) Delcursor(lsm bool)
- func (cur *Cursor) Delete(key, oldvalue []byte, lsm bool) []byte
- func (cur *Cursor) GetNext() (key, value []byte, deleted bool, err error)
- func (cur *Cursor) Key() (key []byte, deleted bool)
- func (cur *Cursor) Set(key, value, oldvalue []byte) []byte
- func (cur *Cursor) Value() []byte
- func (cur *Cursor) YNext(fin bool) (key, value []byte, seqno uint64, deleted bool, err error)
- type LLRB
- func (llrb *LLRB) BeginTxn(id uint64) api.Transactor
- func (llrb *LLRB) Clone(name string) *LLRB
- func (llrb *LLRB) Close()
- func (llrb *LLRB) Count() int64
- func (llrb *LLRB) Delete(key, oldvalue []byte, lsm bool) ([]byte, uint64)
- func (llrb *LLRB) Destroy()
- func (llrb *LLRB) Dotdump(buffer io.Writer)
- func (llrb *LLRB) Footprint() int64
- func (llrb *LLRB) Get(key, value []byte) (v []byte, cas uint64, deleted, ok bool)
- func (llrb *LLRB) Getseqno() uint64
- func (llrb *LLRB) ID() string
- func (llrb *LLRB) Log()
- func (llrb *LLRB) Scan() api.Iterator
- func (llrb *LLRB) ScanEntries() api.EntryIterator
- func (llrb *LLRB) Set(key, value, oldvalue []byte) (ov []byte, cas uint64)
- func (llrb *LLRB) SetCAS(key, value, oldvalue []byte, cas uint64) ([]byte, uint64, error)
- func (llrb *LLRB) Setseqno(seqno uint64)
- func (llrb *LLRB) Stats() map[string]interface{}
- func (llrb *LLRB) Validate()
- func (llrb *LLRB) View(id uint64) api.Transactor
- type Llrbnode
- type MVCC
- func (mvcc *MVCC) BeginTxn(id uint64) api.Transactor
- func (mvcc *MVCC) Clone(name string) *MVCC
- func (mvcc *MVCC) Close()
- func (mvcc *MVCC) Count() int64
- func (mvcc *MVCC) Delete(key, oldvalue []byte, lsm bool) ([]byte, uint64)
- func (mvcc *MVCC) Destroy()
- func (mvcc *MVCC) Dotdump(buffer io.Writer)
- func (mvcc *MVCC) Finalize()
- func (mvcc *MVCC) Footprint() int64
- func (mvcc *MVCC) Get(key, value []byte) (v []byte, cas uint64, deleted, ok bool)
- func (mvcc *MVCC) Getseqno() uint64
- func (mvcc *MVCC) ID() string
- func (mvcc *MVCC) Log()
- func (mvcc *MVCC) Scan() api.Iterator
- func (mvcc *MVCC) ScanEntries() api.EntryIterator
- func (mvcc *MVCC) Set(key, value, oldvalue []byte) (ov []byte, cas uint64)
- func (mvcc *MVCC) SetCAS(key, value, oldvalue []byte, cas uint64) ([]byte, uint64, error)
- func (mvcc *MVCC) Setseqno(seqno uint64)
- func (mvcc *MVCC) Stats() map[string]interface{}
- func (mvcc *MVCC) Validate()
- func (mvcc *MVCC) View(id uint64) api.Transactor
- type Txn
- func (txn *Txn) Abort()
- func (txn *Txn) Commit() error
- func (txn *Txn) Delete(key, oldvalue []byte, lsm bool) []byte
- func (txn *Txn) Get(key, value []byte) (v []byte, cas uint64, deleted, ok bool)
- func (txn *Txn) ID() uint64
- func (txn *Txn) OpenCursor(key []byte) (api.Cursor, error)
- func (txn *Txn) Set(key, value, oldvalue []byte) []byte
- type View
- func (view *View) Abort()
- func (view *View) Commit() error
- func (view *View) Delete(key, oldvalue []byte, lsm bool) []byte
- func (view *View) Get(key, value []byte) (v []byte, cas uint64, deleted, ok bool)
- func (view *View) ID() uint64
- func (view *View) OpenCursor(key []byte) (api.Cursor, error)
- func (view *View) Set(key, value, oldvalue []byte) []byte
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Defaultsettings ¶
Defaultsettings for llrb instance.
"memcapacity" (int64, default: available free-ram)
Memory capacity required for keys / values. Default will be ramsize.
"snapshottick" (int64, default: 4)
Used only in MVCC, time period in millisecond, for generating read-snapshots.
"allocator" (string, default: "flist")
Type of allocator to use.
func LogComponents ¶
func LogComponents(components ...string)
LogComponents enable logging. By default logging is disabled, if applications want log information for llrb components call this function with "self" or "all" or "llrb" or "mvcc" as argument.
Types ¶
type Cursor ¶
type Cursor struct {
// contains filtered or unexported fields
}
Cursor object maintains an active pointer into the index. Use OpenCursor on Txn object to create a new cursor.
func (*Cursor) Delete ¶
Delete is an alias to txn.Delete call. The current position of the cursor does not affect the delete operation.
func (*Cursor) GetNext ¶
GetNext move cursor to next entry in snapshot and return its key and value. Returned byte slices will be a reference to index entry, hence must not be used after transaction is committed or aborted.
func (*Cursor) Key ¶
Key return current key under the cursor. Returned byte slice will be a reference to index-key, hence must not be used after transaction is commited or aborted.
func (*Cursor) Set ¶
Set is an alias to txn.Set call. The current position of the cursor does not affect the set operation.
type LLRB ¶
type LLRB struct {
// contains filtered or unexported fields
}
LLRB to manage a single instance of in-memory sorted index using left-leaning-red-black tree. LLRB instance shall implement api.Index interface, and compliant with api.Getter and api.Iterator APIs.
func LoadLLRB ¶
LoadLLRB creates an LLRB instance and populate it with initial set of data (key, value) from iterator. After loading the data, applications shall use Setseqno() to update the latest sequence number.
func (*LLRB) BeginTxn ¶
func (llrb *LLRB) BeginTxn(id uint64) api.Transactor
BeginTxn starts a read-write transaction. Transactions must satisfy ACID properties. Structure will be locked, no other read or write operation can be performed, until transaction is committed or aborted.
func (*LLRB) Delete ¶
Delete key from index. Key should not be nil, if key found return its value. If lsm is true, then don't delete the node instead mark the node as deleted. Again, if lsm is true but key is not found in index, a new entry will inserted.
func (*LLRB) Destroy ¶
func (llrb *LLRB) Destroy()
Destroy releases all resources held by the tree. No other method call are allowed after Destroy.
func (*LLRB) Dotdump ¶
Dotdump to convert whole tree into dot script that can be visualized using graphviz. Until dotdump exits concurrent write operations will block.
func (*LLRB) Get ¶
Get value for key, if value argument points to valid buffer it will, be used to copy the entry's value. Also returns entry's cas, whether entry is marked as deleted by LSM. If ok is false, then key is not found.
func (*LLRB) Scan ¶
Scan return a full table iterator, if iteration is stopped before reaching end of table (io.EOF), application should call iterator with fin as true. EG: iter(true)
func (*LLRB) ScanEntries ¶
func (llrb *LLRB) ScanEntries() api.EntryIterator
ScanEntries return a full table iterator, if iteration is stopped before reaching end of table (io.EOF), application should call iterator with fin as true. EG: iter(true)
func (*LLRB) Set ¶
Set a key, value pair in the index, if key is already present, its value will be over-written. Make sure key is not nil. Return old value if oldvalue points to valid buffer.
func (*LLRB) SetCAS ¶
SetCAS a key, value pair in the index, if CAS is ZERO then key should not be present in the index, otherwise existing CAS should match the supplied CAS. Value will be over-written. Make sure key is not nil. Return old value if oldvalue points to valid buffer.
func (*LLRB) Setseqno ¶
Setseqno can be called immediately after creating the LLRB instance. All futher mutating APIs will start counting seqno from this value.
type Llrbnode ¶
type Llrbnode struct {
// contains filtered or unexported fields
}
Llrbnode defines a node in LLRB tree.
type MVCC ¶
type MVCC struct {
// contains filtered or unexported fields
}
MVCC manages a single instance of in-memory sorted index using left-leaning-red-black tree. This implementations supports copy on write for all write operations and enables concurrent read operations. MVCC instance implement api.Index interface, and compliant with api.Getter and api.Iterator.
func LoadMVCC ¶
LoadMVCC creates an MVCC instance and populate it with initial set of data (key, value) from iterator. After loading the data applications can use Setseqno() to update the latest sequence number.
func (*MVCC) BeginTxn ¶
func (mvcc *MVCC) BeginTxn(id uint64) api.Transactor
BeginTxn starts a read-write transaction. All transactions should either be committed or aborted. Every transaction holds on to a MVCC snapshot. If transactions are not released for long time accumulating too many background mutations, it will increase the memory pressure on the system. Concurrent transactions are allowed, and serialized internally.
func (*MVCC) Clone ¶
Clone mvcc instance and return the clone. Clone walks the entire tree and concurrent reads and writes will block until call returns.
func (*MVCC) Delete ¶
Delete key from index. Key should not be nil, if key found return its value. If lsm is true, then don't delete the node instead mark the node as deleted. Again, if lsm is true but key is not found in index, a new entry will be inserted.
func (*MVCC) Destroy ¶
func (mvcc *MVCC) Destroy()
Destroy releases all resources held by the tree. No other method call are allowed after Destroy.
func (*MVCC) Dotdump ¶
Dotdump to convert whole tree into dot script that can be visualized using graphviz. Until dotdump exits concurrent write operations will block.
func (*MVCC) Finalize ¶
func (mvcc *MVCC) Finalize()
Finalize will wait for read snapshot to catchup with the tip. To be careful when calling with background mutations, call may never return.
func (*MVCC) Get ¶
Get value for key, if value argument points to valid buffer, it will be used to copy the entry's value. Also returns entry's cas, whether entry is marked as deleted by LSM. If ok is false, then key is not found.
func (*MVCC) Scan ¶
Scan return a full table iterator, if iteration is stopped before reaching end of table (io.EOF), application should call iterator with fin as true. EG: iter(true)
func (*MVCC) ScanEntries ¶
func (mvcc *MVCC) ScanEntries() api.EntryIterator
ScanEntries return a full table iterator, if iteration is stopped before reaching end of table (io.EOF), application should call iterator with fin as true. EG: iter(true)
func (*MVCC) Set ¶
Set a key, value pair in the index, if key is already present, its value will be over-written. Make sure key is not nil. Return old value if oldvalue points to a valid buffer.
func (*MVCC) SetCAS ¶
SetCAS a key, value pair in the index, if CAS is ZERO then key should not be present in the index, otherwise existing CAS should match the supplied CAS. Value will be over-written. Make sure key is not nil. Return old value if oldvalue points to valid buffer.
func (*MVCC) Setseqno ¶
Setseqno can be called immediately after creating the MVCC instance. All futher mutating APIs will start counting seqno from this value.
type Txn ¶
type Txn struct {
// contains filtered or unexported fields
}
Txn transaction definition. Transaction gives a gaurantee of isolation and atomicity on the latest snapshot.
func (*Txn) Commit ¶
Commit transaction, commit will block until all write operations under the transaction are successfully applied. Return ErrorRollback if ACID properties are not met while applying the write operations. Transactions are never partially committed.
func (*Txn) Delete ¶
Delete key from index. The Delete operation will be remembered as a log entry and applied on the underlying structure during commit.
func (*Txn) OpenCursor ¶
OpenCursor open an active cursor inside the index.
type View ¶
type View struct {
// contains filtered or unexported fields
}
View transaction definition. Read only version of Txn.
func (*View) OpenCursor ¶
OpenCursor open an active cursor inside the index.