database

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2020 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxExcessCapacityFactor ...
	// If, when a batch is reset, the cap(batch)/len(batch) > MaxExcessCapacityFactor,
	// the underlying array's capacity will be reduced by a factor of capacityReductionFactor.
	// Higher value for MaxExcessCapacityFactor --> less aggressive array downsizing --> less memory allocations
	// but more unnecessary data in the underlying array that can't be garbage collected.
	// Higher value for CapacityReductionFactor --> more aggressive array downsizing --> more memory allocations
	// but less unnecessary data in the underlying array that can't be garbage collected.
	MaxExcessCapacityFactor = 4
	// CapacityReductionFactor ...
	CapacityReductionFactor = 2
)

Variables

View Source
var (
	ErrClosed   = errors.New("closed")
	ErrNotFound = errors.New("not found")
)

common errors

Functions

func TestBatchDelete

func TestBatchDelete(t *testing.T, db Database)

TestBatchDelete ...

func TestBatchInner

func TestBatchInner(t *testing.T, db Database)

TestBatchInner ...

func TestBatchPut

func TestBatchPut(t *testing.T, db Database)

TestBatchPut ...

func TestBatchReplay

func TestBatchReplay(t *testing.T, db Database)

TestBatchReplay ...

func TestBatchReset

func TestBatchReset(t *testing.T, db Database)

TestBatchReset ...

func TestBatchReuse

func TestBatchReuse(t *testing.T, db Database)

TestBatchReuse ...

func TestBatchRewrite

func TestBatchRewrite(t *testing.T, db Database)

TestBatchRewrite ...

func TestCompactNoPanic

func TestCompactNoPanic(t *testing.T, db Database)

TestCompactNoPanic ...

func TestIterator

func TestIterator(t *testing.T, db Database)

TestIterator ...

func TestIteratorClosed

func TestIteratorClosed(t *testing.T, db Database)

TestIteratorClosed ...

func TestIteratorMemorySafety added in v0.5.0

func TestIteratorMemorySafety(t *testing.T, db Database)

TestIteratorMemorySafety ...

func TestIteratorPrefix

func TestIteratorPrefix(t *testing.T, db Database)

TestIteratorPrefix ...

func TestIteratorStart

func TestIteratorStart(t *testing.T, db Database)

TestIteratorStart ...

func TestIteratorStartPrefix

func TestIteratorStartPrefix(t *testing.T, db Database)

TestIteratorStartPrefix ...

func TestSimpleKeyValue

func TestSimpleKeyValue(t *testing.T, db Database)

TestSimpleKeyValue ...

func TestSimpleKeyValueClosed

func TestSimpleKeyValueClosed(t *testing.T, db Database)

TestSimpleKeyValueClosed ...

func TestStatNoPanic

func TestStatNoPanic(t *testing.T, db Database)

TestStatNoPanic ...

Types

type Batch

type Batch interface {
	KeyValueWriter

	// ValueSize retrieves the amount of data queued up for writing.
	ValueSize() int

	// Write flushes any accumulated data to disk.
	Write() error

	// Reset resets the batch for reuse.
	Reset()

	// Replay replays the batch contents.
	Replay(w KeyValueWriter) error

	// Inner returns a Batch writing to the inner database, if one exists. If
	// this batch is already writing to the base DB, then itself should be
	// returned.
	Inner() Batch
}

Batch is a write-only database that commits changes to its host database when Write is called. A batch cannot be used concurrently.

type Batcher

type Batcher interface {
	// NewBatch creates a write-only database that buffers changes to its host db
	// until a final write is called.
	NewBatch() Batch
}

Batcher wraps the NewBatch method of a backing data store.

type Compacter

type Compacter interface {
	// Compact the underlying DB for the given key range.
	// Specifically, deleted and overwritten versions are discarded,
	// and the data is rearranged to reduce the cost of operations
	// needed to access the data. This operation should typically only
	// be invoked by users who understand the underlying implementation.
	//
	// A nil start is treated as a key before all keys in the DB.
	// And a nil limit is treated as a key after all keys in the DB.
	// Therefore if both are nil then it will compact entire DB.
	Compact(start []byte, limit []byte) error
}

Compacter wraps the Compact method of a backing data store.

type Database

Database contains all the methods required to allow handling different key-value data stores backing the database.

type Iteratee

type Iteratee interface {
	// NewIterator creates a binary-alphabetical iterator over the entire
	// keyspace contained within the key-value database.
	NewIterator() Iterator

	// NewIteratorWithStart creates a binary-alphabetical iterator over a subset
	// of database content starting at a particular initial key (or after, if it
	// does not exist).
	NewIteratorWithStart(start []byte) Iterator

	// NewIteratorWithPrefix creates a binary-alphabetical iterator over a
	// subset of database content with a particular key prefix.
	NewIteratorWithPrefix(prefix []byte) Iterator

	// NewIteratorWithStartAndPrefix creates a binary-alphabetical iterator over
	// a subset of database content with a particular key prefix starting at a
	// specified key.
	NewIteratorWithStartAndPrefix(start, prefix []byte) Iterator
}

Iteratee wraps the NewIterator methods of a backing data store.

type Iterator

type Iterator interface {
	// Next moves the iterator to the next key/value pair. It returns whether
	// the iterator is exhausted.
	Next() bool

	// Error returns any accumulated error. Exhausting all the key/value pairs
	// is not considered to be an error.
	Error() error

	// Key returns the key of the current key/value pair, or nil if done.
	Key() []byte

	// Value returns the value of the current key/value pair, or nil if done.
	Value() []byte

	// Release releases associated resources. Release should always succeed and
	// can be called multiple times without causing error.
	Release()
}

Iterator iterates over a database's key/value pairs in ascending key order.

When it encounters an error any seek will return false and will yield no key/ value pairs. The error can be queried by calling the Error method. Calling Release is still necessary.

An iterator must be released after use, but it is not necessary to read an iterator until exhaustion. An iterator is not safe for concurrent use, but it is safe to use multiple iterators concurrently.

type KeyValueReader

type KeyValueReader interface {
	// Has retrieves if a key is present in the key-value data store.
	Has(key []byte) (bool, error)

	// Get retrieves the given key if it's present in the key-value data store.
	Get(key []byte) ([]byte, error)
}

KeyValueReader wraps the Has and Get method of a backing data store.

type KeyValueWriter

type KeyValueWriter interface {
	// Put inserts the given value into the key-value data store.
	Put(key []byte, value []byte) error

	// Delete removes the key from the key-value data store.
	Delete(key []byte) error
}

KeyValueWriter wraps the Put method of a backing data store.

type Stater

type Stater interface {
	// Stat returns a particular internal stat of the database.
	Stat(property string) (string, error)
}

Stater wraps the Stat method of a backing data store.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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