database

package
v0.2.12-beta-0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package database defines interfaces to key value type databases used by various components in go-spacemesh node

Index

Constants

View Source
const IdealBatchSize = 100 * 1024

IdealBatchSize is the best batch size Code using batches should try to add this much data to the batch. The value was determined empirically.

Variables

View Source
var ErrNotFound = errors.ErrNotFound

ErrNotFound is special type error for not found in DB.

Functions

This section is empty.

Types

type Batch

type Batch interface {
	Putter
	Deleter
	ValueSize() int // amount of data in the batch
	Write() error
	// Reset resets the batch for reuse
	Reset()
}

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

type Database

type Database interface {
	Putter
	Deleter
	Get(key []byte) ([]byte, error)
	Has(key []byte) (bool, error)
	Close()
	NewBatch() Batch
	Find(key []byte) Iterator
}

Database wraps all database operations. All methods are safe for concurrent use.

type Deleter

type Deleter interface {
	Delete(key []byte) error
}

Deleter wraps the database delete operation supported by both batches and regular databases.

type Getter

type Getter interface {
	Get(key []byte) ([]byte, error)
}

Getter wraps the database read operation.

type Iterator

type Iterator = iterator.Iterator

Iterator defined basic iterator interface.

type LDBDatabase

type LDBDatabase struct {
	// contains filtered or unexported fields
}

LDBDatabase is a wrapper for leveldb database with concurrent access.

func NewLDBDatabase

func NewLDBDatabase(file string, cache int, handles int, logger log.Log) (*LDBDatabase, error)

NewLDBDatabase returns a LevelDB wrapped object.

func NewMemDatabase

func NewMemDatabase() *LDBDatabase

NewMemDatabase returns a memory database instance.

func (*LDBDatabase) Close

func (db *LDBDatabase) Close()

Close closes database, flushing writes and denying all new write requests.

func (*LDBDatabase) Delete

func (db *LDBDatabase) Delete(key []byte) error

Delete deletes the key from the queue and database.

func (*LDBDatabase) Find

func (db *LDBDatabase) Find(key []byte) Iterator

Find returns iterator to iterate over values with given prefix key.

func (*LDBDatabase) Get

func (db *LDBDatabase) Get(key []byte) ([]byte, error)

Get returns the given key if it's present.

func (*LDBDatabase) Has

func (db *LDBDatabase) Has(key []byte) (bool, error)

Has returns whether the db contains the key.

func (*LDBDatabase) Iterator

func (db *LDBDatabase) Iterator() iterator.Iterator

Iterator returns iterator iterating over all database keys.

func (*LDBDatabase) LDB

func (db *LDBDatabase) LDB() *leveldb.DB

LDB returns the actual inner leveldb struct reference.

func (*LDBDatabase) Meter

func (db *LDBDatabase) Meter(prefix string)

Meter configures the database metrics collectors and.

func (*LDBDatabase) NewBatch

func (db *LDBDatabase) NewBatch() Batch

NewBatch creates a new batch write struct, able to add multiple values in a single operation.

func (*LDBDatabase) NewIterator

func (db *LDBDatabase) NewIterator() iterator.Iterator

NewIterator creates a new leveldb iterator struct compliant with Iterator interface.

func (*LDBDatabase) NewIteratorWithPrefix

func (db *LDBDatabase) NewIteratorWithPrefix(prefix []byte) iterator.Iterator

NewIteratorWithPrefix returns a iterator to iterate over subset of database content with a particular prefix.

func (*LDBDatabase) Path

func (db *LDBDatabase) Path() string

Path returns the path to the database directory.

func (*LDBDatabase) Put

func (db *LDBDatabase) Put(key []byte, value []byte) error

Put puts the given key / value to the queue.

type Putter

type Putter interface {
	Put(key []byte, value []byte) error
}

Putter wraps the database write operation supported by both batches and regular databases.

type Store

type Store interface {
	Putter
	Getter
}

Store wraps basic get and put operations, All methods are safe for concurrent use.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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