db

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2023 License: LGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LastBlockInfo = "rpl_last_bk"
	DBInfo        = "rpl_db_info"
)

Variables

This section is empty.

Functions

func BytesPrefixRange

func BytesPrefixRange(prefix, start []byte) *util.Range

BytesPrefixRange returns key range that satisfy - the given prefix, and - the given seek position

Types

type Batch

type Batch interface {
	KeyValueWriter
	BatchWriter

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

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

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

Batch is a write-only put/del op set.

type BatchWithID

type BatchWithID struct {
	ID int32
	B  BatchWriter
}

type BatchWriter

type BatchWriter interface {
	// Write flushes any accumulated data to disk.
	Write() error
	// Load loads given slice into the batch.
	Load(data []byte) error
	// Dump dumps the batch into a byte slice.
	Dump() []byte
}

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

	// NewBatchWithSize creates a write-only database batch with pre-allocated buffer.
	NewBatchWithSize(size int) Batch
}

Batcher wraps the NewBatch method of a backing data store.

type Compacter

type Compacter interface {
	// Compact flattens the underlying data store for the given key range. In essence,
	// deleted and overwritten versions are discarded, and the data is rearranged to
	// reduce the cost of operations needed to access them.
	//
	// A nil start is treated as a key before all keys in the data store; a nil limit
	// is treated as a key after all keys in the data store. If both is nil then it
	// will compact entire data store.
	Compact(start []byte, limit []byte) error
}

Compacter wraps the Compact method of a backing data store.

type DB

DB is the interface that wraps the basic operations of a key-value data store.

type DBPool

type DBPool struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

DBPool is a pool of Chain's All DBs.

func NewDBPool

func NewDBPool() *DBPool

func (*DBPool) Close

func (p *DBPool) Close()

func (*DBPool) GetBlockInfo

func (p *DBPool) GetBlockInfo() (header *pb.BlockInfo, err error)

GetBlockInfo returns the last BlockInfo from metaDB.

func (*DBPool) GetDB

func (p *DBPool) GetDB(id int32) (db DB, err error)

GetDB returns a DB by id.

func (*DBPool) GetDBID

func (p *DBPool) GetDBID(path string) (id int32, err error)

GetDBID returns a DB's id by path.

func (*DBPool) GetDBInfo

func (p *DBPool) GetDBInfo() (info *pb.DBInfoList, err error)

GetDBInfo returns all opened DBs.

func (*DBPool) Marshal

func (p *DBPool) Marshal(batchs []BatchWithID) (batchItems []*pb.Data, err error)

Marshal marshals write batchs to bytes.

func (*DBPool) Open

func (p *DBPool) Open(dbInfo *pb.DBInfo, cacheSize int) (err error)

Open opens DB

func (*DBPool) Register

func (p *DBPool) Register(id int32, path string, dbType string, db DB, isMetaDB bool)

RegisterMetaDB registers a DB. if isMetaDB is true, this DB will be used to store msgHead.

func (*DBPool) WriteBatchItems

func (p *DBPool) WriteBatchItems(items []*pb.Data) (err error)

WriteBatchItems writes batchItems to DBs.

func (*DBPool) WriteBatchs

func (p *DBPool) WriteBatchs(batchs []BatchWithID) (err error)

WriteBatchs writes batchs to DBs.

func (*DBPool) WriteBlockInfo

func (p *DBPool) WriteBlockInfo(header *pb.BlockInfo) (err error)

WriteBlockInfo writes header Info to metaDB.

type Iteratee

type Iteratee interface {
	// NewIterator creates a binary-alphabetical iterator over a subset
	// of database content with a particular key prefix, starting at a particular
	// initial key (or after, if it does not exist).
	//
	// Note: This method assumes that the prefix is NOT part of the start, so there's
	// no need for the caller to prepend the prefix to the start
	NewIterator(prefix []byte, start []byte) Iterator

	// NewIteratorWithRange creates an iterator over a domain of keys in ascending order. The caller must call
	NewIteratorWithRange(start []byte, limit []byte) (Iterator, error)
}

Iteratee wraps the NewIterator methods of a backing data store.

type Iterator

type Iterator interface {
	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. The caller
	// should not modify the contents of the returned slice, and its contents may
	// change on the next call to Next.
	Key() []byte

	// Value returns the value of the current key/value pair, or nil if done. The
	// caller should not modify the contents of the returned slice, and its contents
	// may change on the next call to Next.
	Value() []byte

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

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 KeyValueStater

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

	// Stats returns a map of property values for all keys and the size of the cache.
	Stats() (map[string]string, error)
}

KeyValueStater wraps the Stat 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
}

type LBatch

type LBatch struct {
	DB    *LDB
	Batch *leveldb.Batch
	// contains filtered or unexported fields
}

func (*LBatch) Delete

func (l *LBatch) Delete(key []byte) error

func (*LBatch) Dump

func (l *LBatch) Dump() []byte

func (*LBatch) Load

func (l *LBatch) Load(data []byte) error

func (*LBatch) Put

func (l *LBatch) Put(key, value []byte) error

func (*LBatch) Replay

func (l *LBatch) Replay(w KeyValueWriter) error

func (*LBatch) Reset

func (l *LBatch) Reset()

func (*LBatch) ValueSize

func (l *LBatch) ValueSize() int

func (*LBatch) Write

func (l *LBatch) Write() error

type LDB

type LDB struct {
	Id int32
	DB *leveldb.DB
}

func NewLDB

func NewLDB(path string, cacheSize int) (*LDB, error)

func (*LDB) Close

func (l *LDB) Close() error

func (*LDB) Compact

func (l *LDB) Compact(start, limit []byte) error

func (*LDB) Delete

func (l *LDB) Delete(key []byte) error

func (*LDB) Get

func (l *LDB) Get(key []byte) ([]byte, error)

func (*LDB) Has

func (l *LDB) Has(key []byte) (bool, error)

func (*LDB) NewBatch

func (l *LDB) NewBatch() Batch

func (*LDB) NewBatchWithSize

func (l *LDB) NewBatchWithSize(size int) Batch

func (*LDB) NewIterator

func (l *LDB) NewIterator(prefix []byte, start []byte) Iterator

func (*LDB) NewIteratorWithRange

func (l *LDB) NewIteratorWithRange(start, limit []byte) (Iterator, error)

func (*LDB) NewSnapshot

func (l *LDB) NewSnapshot() (Snapshot, error)

func (*LDB) Put

func (l *LDB) Put(key, value []byte) error

func (*LDB) Stat

func (l *LDB) Stat(property string) (string, error)

func (*LDB) Stats

func (l *LDB) Stats() (map[string]string, error)

type LIterator

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

func (*LIterator) Error

func (iter *LIterator) Error() error

func (*LIterator) Key

func (iter *LIterator) Key() []byte

func (*LIterator) Next

func (iter *LIterator) Next() bool

func (*LIterator) Release

func (iter *LIterator) Release()

func (*LIterator) Value

func (iter *LIterator) Value() []byte

type LSnapshot

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

func (*LSnapshot) Get

func (snap *LSnapshot) Get(key []byte) ([]byte, error)

func (*LSnapshot) Has

func (snap *LSnapshot) Has(key []byte) (bool, error)

func (*LSnapshot) Release

func (snap *LSnapshot) Release()

type Replayer

type Replayer struct {
	Writer  KeyValueWriter
	Failure error
}

func (*Replayer) Delete

func (r *Replayer) Delete(key []byte)

func (*Replayer) Put

func (r *Replayer) Put(key, value []byte)

type Snapshot

type Snapshot interface {
	KeyValueReader

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

type Snapshotter

type Snapshotter interface {
	// NewSnapshot creates a database snapshot based on the current state.
	// The created snapshot will not be affected by all following mutations
	// happened on the database.
	// Note don't forget to release the snapshot once it's used up, otherwise
	// the stale data will never be cleaned up by the underlying compactor.
	NewSnapshot() (Snapshot, error)
}

Snapshotter wraps the Snapshot method of a backing data store.

Jump to

Keyboard shortcuts

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