Documentation
¶
Overview ¶
Package memtable is an in-memory ordered key-value table with copy-on-write snapshots, which its owner persists through a commit function.
Published tables are never changed, so a read transaction sees one snapshot for its whole life without locks. A write transaction holds the writer lock and changes its own copy, recording each change for the owner to persist.
Index ¶
- type CommitFunc
- type Op
- type Snapshot
- type Table
- type Tx
- func (t *Tx) Commit(ctx context.Context) error
- func (t *Tx) CommitOrdered(ctx context.Context) error
- func (t *Tx) Delete(ctx context.Context, key []byte) error
- func (t *Tx) Discard()
- func (t *Tx) Exists(ctx context.Context, key []byte) (bool, error)
- func (t *Tx) Get(ctx context.Context, key []byte) ([]byte, bool, error)
- func (t *Tx) Iterate(ctx context.Context, prefix []byte, sort, reverse bool) kvtx.Iterator
- func (t *Tx) ScanPrefix(ctx context.Context, prefix []byte, cb func(key, value []byte) error) error
- func (t *Tx) ScanPrefixKeys(ctx context.Context, prefix []byte, cb func(key []byte) error) error
- func (t *Tx) Set(ctx context.Context, key, value []byte) error
- func (t *Tx) Size(ctx context.Context) (uint64, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommitFunc ¶
CommitFunc persists ops, which turn the published table into next, before the table publishes next. With ordered set it may persist them with write ordering only, as kvtx.OrderedCommitTx describes. Calls never overlap.
type Op ¶
type Op struct {
// Key is the key.
Key []byte
// Value is the value a set stores.
Value []byte
// Delete deletes the key.
Delete bool
}
Op is one change a write transaction made.
type Snapshot ¶
type Snapshot struct {
// contains filtered or unexported fields
}
Snapshot is one immutable version of the table.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table is the key-value table.
func New ¶
func New(commit CommitFunc) *Table
New returns an empty table that persists write transactions with commit.
func (*Table) Apply ¶
Apply applies ops to the published table. It serves recovery before the table is shared.
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Tx is a transaction on one table snapshot. A write transaction changes its own copy of the table and records each change for the commit function.
func (*Tx) Commit ¶
Commit persists a write transaction's changes and publishes them. A write transaction without changes skips the commit function.
func (*Tx) CommitOrdered ¶
CommitOrdered persists a write transaction's changes with write ordering only and publishes them.
func (*Tx) Discard ¶
func (t *Tx) Discard()
Discard ends the transaction, dropping uncommitted changes.
func (*Tx) ScanPrefix ¶
ScanPrefix calls cb with each key with prefix and its value in key order.
func (*Tx) ScanPrefixKeys ¶
ScanPrefixKeys calls cb with each key with prefix in key order.