db

package
v2.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package db is a generated GoMock package.

Index

Constants

View Source
const (
	DBBolt   string = "boltdb"
	DBPebble        = "pebbledb"
)

Database types

Variables

View Source
var (
	// CountKey is the special key to store the size of index, it satisfies bytes.Compare(CountKey, MinUint64) = -1
	CountKey = []byte{0, 0, 0, 0, 0, 0, 0}
	// ZeroIndex is 8-byte of 0
	ZeroIndex = byteutil.Uint64ToBytesBigEndian(0)
	// ErrInvalid indicates an invalid input
	ErrInvalid = errors.New("invalid input")
)
View Source
var (
	// ErrBucketNotExist indicates certain bucket does not exist in db
	ErrBucketNotExist = errors.New("bucket not exist in DB")
	// ErrNotExist indicates certain item does not exist in Blockchain database
	ErrNotExist = errors.New("not exist in DB")
	// ErrIO indicates the generic error of DB I/O operation
	ErrIO = errors.New("DB I/O operation error")
	// ErrNotSupported indicates that api is not supported
	ErrNotSupported = errors.New("not supported")
)
View Source
var (
	// MaxKey is the special key such that bytes.Compare(MaxUint64, MaxKey) = -1
	MaxKey = []byte{255, 255, 255, 255, 255, 255, 255, 255, 0}
	// NotExist is the empty byte slice to indicate a key does not exist (as a result of calling Purge())
	NotExist = []byte{}
)
View Source
var DefaultConfig = Config{
	NumRetries:            3,
	MaxCacheSize:          64,
	BlockStoreBatchSize:   16,
	V2BlocksToSplitDB:     1000000,
	Compressor:            "Snappy",
	CompressLegacy:        false,
	SplitDBSizeMB:         0,
	SplitDBHeight:         900000,
	HistoryStateRetention: 2000,
	DBType:                DBBolt,
}

DefaultConfig returns the default config

View Source
var (
	// ErrDBNotStarted represents the error when a db has not started
	ErrDBNotStarted = errors.New("db has not started")
)
View Source
var (
	// ErrEmptyDBPath is the error when db path is empty
	ErrEmptyDBPath = errors.New("empty db path")
)

Functions

This section is empty.

Types

type BoltDB

type BoltDB struct {
	lifecycle.Readiness
	// contains filtered or unexported fields
}

BoltDB is KVStore implementation based bolt DB

func NewBoltDB

func NewBoltDB(cfg Config) *BoltDB

NewBoltDB instantiates an BoltDB with implements KVStore

func (*BoltDB) BucketExists

func (b *BoltDB) BucketExists(namespace string) bool

BucketExists returns true if bucket exists

func (*BoltDB) Delete

func (b *BoltDB) Delete(namespace string, key []byte) (err error)

Delete deletes a record,if key is nil,this will delete the whole bucket

func (*BoltDB) Filter

func (b *BoltDB) Filter(namespace string, cond Condition, minKey, maxKey []byte) ([][]byte, [][]byte, error)

Filter returns <k, v> pair in a bucket that meet the condition

func (*BoltDB) Get

func (b *BoltDB) Get(namespace string, key []byte) ([]byte, error)

Get retrieves a record

func (*BoltDB) GetBucketByPrefix

func (b *BoltDB) GetBucketByPrefix(namespace []byte) ([][]byte, error)

GetBucketByPrefix retrieves all bucket those with const namespace prefix

func (*BoltDB) GetKeyByPrefix

func (b *BoltDB) GetKeyByPrefix(namespace, prefix []byte) ([][]byte, error)

GetKeyByPrefix retrieves all keys those with const prefix

func (*BoltDB) Insert

func (b *BoltDB) Insert(name []byte, key uint64, value []byte) error

Insert inserts a value into the index

func (*BoltDB) Purge

func (b *BoltDB) Purge(name []byte, key uint64) error

Purge deletes an existing key and all keys before it

func (*BoltDB) Put

func (b *BoltDB) Put(namespace string, key, value []byte) (err error)

Put inserts a <key, value> record

func (*BoltDB) Range

func (b *BoltDB) Range(namespace string, key []byte, count uint64) ([][]byte, error)

Range retrieves values for a range of keys

func (*BoltDB) Remove

func (b *BoltDB) Remove(name []byte, key uint64) error

Remove removes an existing key

func (*BoltDB) SeekNext

func (b *BoltDB) SeekNext(name []byte, key uint64) ([]byte, error)

SeekNext returns value by the key (if key not exist, use next key)

func (*BoltDB) SeekPrev

func (b *BoltDB) SeekPrev(name []byte, key uint64) ([]byte, error)

SeekPrev returns value by the key (if key not exist, use previous key)

func (*BoltDB) Start

func (b *BoltDB) Start(_ context.Context) error

Start opens the BoltDB (creates new file if not existing yet)

func (*BoltDB) Stop

func (b *BoltDB) Stop(_ context.Context) error

Stop closes the BoltDB

func (*BoltDB) WriteBatch

func (b *BoltDB) WriteBatch(kvsb batch.KVStoreBatch) (err error)

WriteBatch commits a batch

type BoltDBVersioned

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

BoltDBVersioned is KvVersioned implementation based on bolt DB

func NewBoltDBVersioned

func NewBoltDBVersioned(cfg Config, opts ...Option) *BoltDBVersioned

NewBoltDBVersioned instantiates an BoltDB which implements KvVersioned

func (*BoltDBVersioned) Delete

func (b *BoltDBVersioned) Delete(ns string, key []byte) error

Delete deletes a record,if key is nil,this will delete the whole bucket

func (*BoltDBVersioned) Get

func (b *BoltDBVersioned) Get(ns string, version uint64, key []byte) ([]byte, error)

Get retrieves the most recent version

func (*BoltDBVersioned) Put

func (b *BoltDBVersioned) Put(ns string, version uint64, key, value []byte) error

Put writes a <key, value> record

func (*BoltDBVersioned) SetVersion

func (b *BoltDBVersioned) SetVersion(v uint64) KVStoreBasic

SetVersion sets the version, and returns a KVStore to call Put()/Get()

func (*BoltDBVersioned) Start

func (b *BoltDBVersioned) Start(ctx context.Context) error

Start starts the DB

func (*BoltDBVersioned) Stop

func (b *BoltDBVersioned) Stop(ctx context.Context) error

Stop stops the DB

func (*BoltDBVersioned) Version

func (b *BoltDBVersioned) Version(ns string, key []byte) (uint64, error)

Version returns the key's most recent version

type Condition

type Condition func(k, v []byte) bool

Condition spells the condition for <k, v> to be filtered out

type Config

type Config struct {
	DbPath string `yaml:"dbPath"`
	// NumRetries is the number of retries
	NumRetries uint8 `yaml:"numRetries"`
	// MaxCacheSize is the max number of blocks that will be put into an LRU cache. 0 means disabled
	MaxCacheSize int `yaml:"maxCacheSize"`
	// BlockStoreBatchSize is the number of blocks to be stored together as a unit (to get better compression)
	BlockStoreBatchSize int `yaml:"blockStoreBatchSize"`
	// V2BlocksToSplitDB is the accumulated number of blocks to split a new file after v1.1.2
	V2BlocksToSplitDB uint64 `yaml:"v2BlocksToSplitDB"`
	// Compressor is the compression used on block data, used by new DB file after v1.1.2
	Compressor string `yaml:"compressor"`
	// CompressLegacy enables gzip compression on block data, used by legacy DB file before v1.1.2
	CompressLegacy bool `yaml:"compressLegacy"`
	// SplitDBSize is the config for DB's split file size
	SplitDBSizeMB uint64 `yaml:"splitDBSizeMB"`
	// SplitDBHeight is the config for DB's split start height
	SplitDBHeight uint64 `yaml:"splitDBHeight"`
	// HistoryStateRetention is the number of blocks account/contract state will be retained
	HistoryStateRetention uint64 `yaml:"historyStateRetention"`
	// ReadOnly is set db to be opened in read only mode
	ReadOnly bool `yaml:"readOnly"`
	// DBType is the type of database
	DBType string `yaml:"dbType"`
}

Config is the config for database

func (Config) SplitDBSize

func (cfg Config) SplitDBSize() uint64

SplitDBSize returns the configured SplitDBSizeMB

type CountingIndex

type CountingIndex interface {
	// Size returns the total number of keys so far
	Size() uint64
	// Add inserts a value into the index
	Add([]byte, bool) error
	// Get return value of key[slot]
	Get(uint64) ([]byte, error)
	// Range return value of keys [start, start+count)
	Range(uint64, uint64) ([][]byte, error)
	// Revert removes entries from end
	Revert(uint64) error
	// Close makes the index not usable
	Close()
	// Commit commits the batch
	Commit() error
	// UseBatch
	UseBatch(batch.KVStoreBatch) error
	// Finalize
	Finalize() error
}

CountingIndex is a bucket of <k, v> where k consists of 8-byte whose value increments (0, 1, 2 ... n) upon each insertion the special key CountKey stores the total number of items in bucket so far

func GetCountingIndex

func GetCountingIndex(kv KVStore, name []byte) (CountingIndex, error)

GetCountingIndex return an existing counting index

func NewCountingIndexNX

func NewCountingIndexNX(kv KVStore, name []byte) (CountingIndex, error)

NewCountingIndexNX creates a new counting index if it does not exist, otherwise return existing index

type KVStore

type KVStore interface {
	KVStoreBasic
	// WriteBatch commits a batch
	WriteBatch(batch.KVStoreBatch) error
	// Filter returns <k, v> pair in a bucket that meet the condition
	Filter(string, Condition, []byte, []byte) ([][]byte, [][]byte, error)
}

KVStore is a KVStore with WriteBatch API

func CreateKVStore

func CreateKVStore(cfg Config, dbPath string) (KVStore, error)

CreateKVStore creates db from config and db path

func CreateKVStoreWithCache

func CreateKVStoreWithCache(cfg Config, dbPath string, cacheSize int) (KVStore, error)

CreateKVStoreWithCache creates db with cache from config and db path, cacheSize

func NewKvStoreWithCache

func NewKvStoreWithCache(kvstore KVStore, cacheSize int) KVStore

NewKvStoreWithCache wraps kvstore with stateCaches

type KVStoreBasic

type KVStoreBasic interface {
	lifecycle.StartStopper

	// Put insert or update a record identified by (namespace, key)
	Put(string, []byte, []byte) error
	// Get gets a record by (namespace, key)
	Get(string, []byte) ([]byte, error)
	// Delete deletes a record by (namespace, key)
	Delete(string, []byte) error
}

KVStoreBasic is the interface of basic KV store.

type KVStoreFlusher

type KVStoreFlusher interface {
	SerializeQueue() []byte
	Flush() error
	KVStoreWithBuffer() KVStoreWithBuffer
	BaseKVStore() KVStore
}

KVStoreFlusher is a wrapper of KVStoreWithBuffer, which has flush api

func NewKVStoreFlusher

func NewKVStoreFlusher(store KVStore, buffer batch.CachedBatch, opts ...KVStoreFlusherOption) (KVStoreFlusher, error)

NewKVStoreFlusher returns kv store flusher

type KVStoreFlusherOption

type KVStoreFlusherOption func(*flusher) error

KVStoreFlusherOption sets option for KVStoreFlusher

func FlushTranslateOption

func FlushTranslateOption(wit batch.WriteInfoTranslate) KVStoreFlusherOption

FlushTranslateOption sets the translate for flush

func SerializeFilterOption

func SerializeFilterOption(filter batch.WriteInfoFilter) KVStoreFlusherOption

SerializeFilterOption sets the filter for serialize write queue

func SerializeOption

func SerializeOption(wis batch.WriteInfoSerialize) KVStoreFlusherOption

SerializeOption sets the serialize function for write queue

type KVStoreForRangeIndex

type KVStoreForRangeIndex interface {
	KVStore
	// Insert inserts a value into the index
	Insert([]byte, uint64, []byte) error
	// SeekNext returns value by the key (if key not exist, use next key)
	SeekNext([]byte, uint64) ([]byte, error)
	// Remove removes an existing key
	Remove([]byte, uint64) error
	// Purge deletes an existing key and all keys before it
	Purge([]byte, uint64) error
	// GetBucketByPrefix retrieves all bucket those with const namespace prefix
	GetBucketByPrefix([]byte) ([][]byte, error)
	// GetKeyByPrefix retrieves all keys those with const prefix
	GetKeyByPrefix(namespace, prefix []byte) ([][]byte, error)
	// SeekPrev returns value by the key (if key not exist, use previous key)
	SeekPrev([]byte, uint64) ([]byte, error)
}

KVStoreForRangeIndex is KVStore for range index

func NewMemKVStore

func NewMemKVStore() KVStoreForRangeIndex

NewMemKVStore instantiates an in-memory KV store

type KVStoreWithBuffer

type KVStoreWithBuffer interface {
	KVStore
	// contains filtered or unexported methods
}

KVStoreWithBuffer defines a KVStore with a buffer, which enables snapshot, revert, and transaction with multiple writes

type KVStoreWithRange

type KVStoreWithRange interface {
	KVStore
	// Range gets a range of records by (namespace, key, count)
	Range(string, []byte, uint64) ([][]byte, error)
}

KVStoreWithRange is KVStore with Range() API

type KvVersioned

type KvVersioned interface {
	lifecycle.StartStopper

	// Version returns the key's most recent version
	Version(string, []byte) (uint64, error)

	// SetVersion sets the version, and returns a KVStore to call Put()/Get()
	SetVersion(uint64) KVStoreBasic
}

type KvWithVersion

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

KvWithVersion wraps the BoltDBVersioned with a certain version

func (*KvWithVersion) Delete

func (b *KvWithVersion) Delete(ns string, key []byte) error

Delete deletes a key

func (*KvWithVersion) Get

func (b *KvWithVersion) Get(ns string, key []byte) ([]byte, error)

Get retrieves a key's value

func (*KvWithVersion) Put

func (b *KvWithVersion) Put(ns string, key, value []byte) error

Put writes a <key, value> record

func (*KvWithVersion) Start

func (b *KvWithVersion) Start(context.Context) error

Start starts the DB

func (*KvWithVersion) Stop

Stop stops the DB

type MockKVStore

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

MockKVStore is a mock of KVStore interface.

func NewMockKVStore

func NewMockKVStore(ctrl *gomock.Controller) *MockKVStore

NewMockKVStore creates a new mock instance.

func (*MockKVStore) Delete

func (m *MockKVStore) Delete(arg0 string, arg1 []byte) error

Delete mocks base method.

func (*MockKVStore) EXPECT

func (m *MockKVStore) EXPECT() *MockKVStoreMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockKVStore) Filter

func (m *MockKVStore) Filter(arg0 string, arg1 Condition, arg2, arg3 []byte) ([][]byte, [][]byte, error)

Filter mocks base method.

func (*MockKVStore) Get

func (m *MockKVStore) Get(arg0 string, arg1 []byte) ([]byte, error)

Get mocks base method.

func (*MockKVStore) Put

func (m *MockKVStore) Put(arg0 string, arg1, arg2 []byte) error

Put mocks base method.

func (*MockKVStore) Start

func (m *MockKVStore) Start(arg0 context.Context) error

Start mocks base method.

func (*MockKVStore) Stop

func (m *MockKVStore) Stop(arg0 context.Context) error

Stop mocks base method.

func (*MockKVStore) WriteBatch

func (m *MockKVStore) WriteBatch(arg0 batch.KVStoreBatch) error

WriteBatch mocks base method.

type MockKVStoreBasic

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

MockKVStoreBasic is a mock of KVStoreBasic interface.

func NewMockKVStoreBasic

func NewMockKVStoreBasic(ctrl *gomock.Controller) *MockKVStoreBasic

NewMockKVStoreBasic creates a new mock instance.

func (*MockKVStoreBasic) Delete

func (m *MockKVStoreBasic) Delete(arg0 string, arg1 []byte) error

Delete mocks base method.

func (*MockKVStoreBasic) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockKVStoreBasic) Get

func (m *MockKVStoreBasic) Get(arg0 string, arg1 []byte) ([]byte, error)

Get mocks base method.

func (*MockKVStoreBasic) Put

func (m *MockKVStoreBasic) Put(arg0 string, arg1, arg2 []byte) error

Put mocks base method.

func (*MockKVStoreBasic) Start

func (m *MockKVStoreBasic) Start(arg0 context.Context) error

Start mocks base method.

func (*MockKVStoreBasic) Stop

func (m *MockKVStoreBasic) Stop(arg0 context.Context) error

Stop mocks base method.

type MockKVStoreBasicMockRecorder

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

MockKVStoreBasicMockRecorder is the mock recorder for MockKVStoreBasic.

func (*MockKVStoreBasicMockRecorder) Delete

func (mr *MockKVStoreBasicMockRecorder) Delete(arg0, arg1 interface{}) *gomock.Call

Delete indicates an expected call of Delete.

func (*MockKVStoreBasicMockRecorder) Get

func (mr *MockKVStoreBasicMockRecorder) Get(arg0, arg1 interface{}) *gomock.Call

Get indicates an expected call of Get.

func (*MockKVStoreBasicMockRecorder) Put

func (mr *MockKVStoreBasicMockRecorder) Put(arg0, arg1, arg2 interface{}) *gomock.Call

Put indicates an expected call of Put.

func (*MockKVStoreBasicMockRecorder) Start

func (mr *MockKVStoreBasicMockRecorder) Start(arg0 interface{}) *gomock.Call

Start indicates an expected call of Start.

func (*MockKVStoreBasicMockRecorder) Stop

func (mr *MockKVStoreBasicMockRecorder) Stop(arg0 interface{}) *gomock.Call

Stop indicates an expected call of Stop.

type MockKVStoreForRangeIndex

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

MockKVStoreForRangeIndex is a mock of KVStoreForRangeIndex interface.

func NewMockKVStoreForRangeIndex

func NewMockKVStoreForRangeIndex(ctrl *gomock.Controller) *MockKVStoreForRangeIndex

NewMockKVStoreForRangeIndex creates a new mock instance.

func (*MockKVStoreForRangeIndex) Delete

func (m *MockKVStoreForRangeIndex) Delete(arg0 string, arg1 []byte) error

Delete mocks base method.

func (*MockKVStoreForRangeIndex) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockKVStoreForRangeIndex) Filter

func (m *MockKVStoreForRangeIndex) Filter(arg0 string, arg1 Condition, arg2, arg3 []byte) ([][]byte, [][]byte, error)

Filter mocks base method.

func (*MockKVStoreForRangeIndex) Get

func (m *MockKVStoreForRangeIndex) Get(arg0 string, arg1 []byte) ([]byte, error)

Get mocks base method.

func (*MockKVStoreForRangeIndex) GetBucketByPrefix

func (m *MockKVStoreForRangeIndex) GetBucketByPrefix(arg0 []byte) ([][]byte, error)

GetBucketByPrefix mocks base method.

func (*MockKVStoreForRangeIndex) GetKeyByPrefix

func (m *MockKVStoreForRangeIndex) GetKeyByPrefix(namespace, prefix []byte) ([][]byte, error)

GetKeyByPrefix mocks base method.

func (*MockKVStoreForRangeIndex) Insert

func (m *MockKVStoreForRangeIndex) Insert(arg0 []byte, arg1 uint64, arg2 []byte) error

Insert mocks base method.

func (*MockKVStoreForRangeIndex) Purge

func (m *MockKVStoreForRangeIndex) Purge(arg0 []byte, arg1 uint64) error

Purge mocks base method.

func (*MockKVStoreForRangeIndex) Put

func (m *MockKVStoreForRangeIndex) Put(arg0 string, arg1, arg2 []byte) error

Put mocks base method.

func (*MockKVStoreForRangeIndex) Remove

func (m *MockKVStoreForRangeIndex) Remove(arg0 []byte, arg1 uint64) error

Remove mocks base method.

func (*MockKVStoreForRangeIndex) SeekNext

func (m *MockKVStoreForRangeIndex) SeekNext(arg0 []byte, arg1 uint64) ([]byte, error)

SeekNext mocks base method.

func (*MockKVStoreForRangeIndex) SeekPrev

func (m *MockKVStoreForRangeIndex) SeekPrev(arg0 []byte, arg1 uint64) ([]byte, error)

SeekPrev mocks base method.

func (*MockKVStoreForRangeIndex) Start

Start mocks base method.

func (*MockKVStoreForRangeIndex) Stop

Stop mocks base method.

func (*MockKVStoreForRangeIndex) WriteBatch

func (m *MockKVStoreForRangeIndex) WriteBatch(arg0 batch.KVStoreBatch) error

WriteBatch mocks base method.

type MockKVStoreForRangeIndexMockRecorder

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

MockKVStoreForRangeIndexMockRecorder is the mock recorder for MockKVStoreForRangeIndex.

func (*MockKVStoreForRangeIndexMockRecorder) Delete

func (mr *MockKVStoreForRangeIndexMockRecorder) Delete(arg0, arg1 interface{}) *gomock.Call

Delete indicates an expected call of Delete.

func (*MockKVStoreForRangeIndexMockRecorder) Filter

func (mr *MockKVStoreForRangeIndexMockRecorder) Filter(arg0, arg1, arg2, arg3 interface{}) *gomock.Call

Filter indicates an expected call of Filter.

func (*MockKVStoreForRangeIndexMockRecorder) Get

func (mr *MockKVStoreForRangeIndexMockRecorder) Get(arg0, arg1 interface{}) *gomock.Call

Get indicates an expected call of Get.

func (*MockKVStoreForRangeIndexMockRecorder) GetBucketByPrefix

func (mr *MockKVStoreForRangeIndexMockRecorder) GetBucketByPrefix(arg0 interface{}) *gomock.Call

GetBucketByPrefix indicates an expected call of GetBucketByPrefix.

func (*MockKVStoreForRangeIndexMockRecorder) GetKeyByPrefix

func (mr *MockKVStoreForRangeIndexMockRecorder) GetKeyByPrefix(namespace, prefix interface{}) *gomock.Call

GetKeyByPrefix indicates an expected call of GetKeyByPrefix.

func (*MockKVStoreForRangeIndexMockRecorder) Insert

func (mr *MockKVStoreForRangeIndexMockRecorder) Insert(arg0, arg1, arg2 interface{}) *gomock.Call

Insert indicates an expected call of Insert.

func (*MockKVStoreForRangeIndexMockRecorder) Purge

func (mr *MockKVStoreForRangeIndexMockRecorder) Purge(arg0, arg1 interface{}) *gomock.Call

Purge indicates an expected call of Purge.

func (*MockKVStoreForRangeIndexMockRecorder) Put

func (mr *MockKVStoreForRangeIndexMockRecorder) Put(arg0, arg1, arg2 interface{}) *gomock.Call

Put indicates an expected call of Put.

func (*MockKVStoreForRangeIndexMockRecorder) Remove

func (mr *MockKVStoreForRangeIndexMockRecorder) Remove(arg0, arg1 interface{}) *gomock.Call

Remove indicates an expected call of Remove.

func (*MockKVStoreForRangeIndexMockRecorder) SeekNext

func (mr *MockKVStoreForRangeIndexMockRecorder) SeekNext(arg0, arg1 interface{}) *gomock.Call

SeekNext indicates an expected call of SeekNext.

func (*MockKVStoreForRangeIndexMockRecorder) SeekPrev

func (mr *MockKVStoreForRangeIndexMockRecorder) SeekPrev(arg0, arg1 interface{}) *gomock.Call

SeekPrev indicates an expected call of SeekPrev.

func (*MockKVStoreForRangeIndexMockRecorder) Start

func (mr *MockKVStoreForRangeIndexMockRecorder) Start(arg0 interface{}) *gomock.Call

Start indicates an expected call of Start.

func (*MockKVStoreForRangeIndexMockRecorder) Stop

func (mr *MockKVStoreForRangeIndexMockRecorder) Stop(arg0 interface{}) *gomock.Call

Stop indicates an expected call of Stop.

func (*MockKVStoreForRangeIndexMockRecorder) WriteBatch

func (mr *MockKVStoreForRangeIndexMockRecorder) WriteBatch(arg0 interface{}) *gomock.Call

WriteBatch indicates an expected call of WriteBatch.

type MockKVStoreMockRecorder

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

MockKVStoreMockRecorder is the mock recorder for MockKVStore.

func (*MockKVStoreMockRecorder) Delete

func (mr *MockKVStoreMockRecorder) Delete(arg0, arg1 interface{}) *gomock.Call

Delete indicates an expected call of Delete.

func (*MockKVStoreMockRecorder) Filter

func (mr *MockKVStoreMockRecorder) Filter(arg0, arg1, arg2, arg3 interface{}) *gomock.Call

Filter indicates an expected call of Filter.

func (*MockKVStoreMockRecorder) Get

func (mr *MockKVStoreMockRecorder) Get(arg0, arg1 interface{}) *gomock.Call

Get indicates an expected call of Get.

func (*MockKVStoreMockRecorder) Put

func (mr *MockKVStoreMockRecorder) Put(arg0, arg1, arg2 interface{}) *gomock.Call

Put indicates an expected call of Put.

func (*MockKVStoreMockRecorder) Start

func (mr *MockKVStoreMockRecorder) Start(arg0 interface{}) *gomock.Call

Start indicates an expected call of Start.

func (*MockKVStoreMockRecorder) Stop

func (mr *MockKVStoreMockRecorder) Stop(arg0 interface{}) *gomock.Call

Stop indicates an expected call of Stop.

func (*MockKVStoreMockRecorder) WriteBatch

func (mr *MockKVStoreMockRecorder) WriteBatch(arg0 interface{}) *gomock.Call

WriteBatch indicates an expected call of WriteBatch.

type MockKVStoreWithRange

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

MockKVStoreWithRange is a mock of KVStoreWithRange interface.

func NewMockKVStoreWithRange

func NewMockKVStoreWithRange(ctrl *gomock.Controller) *MockKVStoreWithRange

NewMockKVStoreWithRange creates a new mock instance.

func (*MockKVStoreWithRange) Delete

func (m *MockKVStoreWithRange) Delete(arg0 string, arg1 []byte) error

Delete mocks base method.

func (*MockKVStoreWithRange) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockKVStoreWithRange) Filter

func (m *MockKVStoreWithRange) Filter(arg0 string, arg1 Condition, arg2, arg3 []byte) ([][]byte, [][]byte, error)

Filter mocks base method.

func (*MockKVStoreWithRange) Get

func (m *MockKVStoreWithRange) Get(arg0 string, arg1 []byte) ([]byte, error)

Get mocks base method.

func (*MockKVStoreWithRange) Put

func (m *MockKVStoreWithRange) Put(arg0 string, arg1, arg2 []byte) error

Put mocks base method.

func (*MockKVStoreWithRange) Range

func (m *MockKVStoreWithRange) Range(arg0 string, arg1 []byte, arg2 uint64) ([][]byte, error)

Range mocks base method.

func (*MockKVStoreWithRange) Start

func (m *MockKVStoreWithRange) Start(arg0 context.Context) error

Start mocks base method.

func (*MockKVStoreWithRange) Stop

func (m *MockKVStoreWithRange) Stop(arg0 context.Context) error

Stop mocks base method.

func (*MockKVStoreWithRange) WriteBatch

func (m *MockKVStoreWithRange) WriteBatch(arg0 batch.KVStoreBatch) error

WriteBatch mocks base method.

type MockKVStoreWithRangeMockRecorder

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

MockKVStoreWithRangeMockRecorder is the mock recorder for MockKVStoreWithRange.

func (*MockKVStoreWithRangeMockRecorder) Delete

func (mr *MockKVStoreWithRangeMockRecorder) Delete(arg0, arg1 interface{}) *gomock.Call

Delete indicates an expected call of Delete.

func (*MockKVStoreWithRangeMockRecorder) Filter

func (mr *MockKVStoreWithRangeMockRecorder) Filter(arg0, arg1, arg2, arg3 interface{}) *gomock.Call

Filter indicates an expected call of Filter.

func (*MockKVStoreWithRangeMockRecorder) Get

func (mr *MockKVStoreWithRangeMockRecorder) Get(arg0, arg1 interface{}) *gomock.Call

Get indicates an expected call of Get.

func (*MockKVStoreWithRangeMockRecorder) Put

func (mr *MockKVStoreWithRangeMockRecorder) Put(arg0, arg1, arg2 interface{}) *gomock.Call

Put indicates an expected call of Put.

func (*MockKVStoreWithRangeMockRecorder) Range

func (mr *MockKVStoreWithRangeMockRecorder) Range(arg0, arg1, arg2 interface{}) *gomock.Call

Range indicates an expected call of Range.

func (*MockKVStoreWithRangeMockRecorder) Start

func (mr *MockKVStoreWithRangeMockRecorder) Start(arg0 interface{}) *gomock.Call

Start indicates an expected call of Start.

func (*MockKVStoreWithRangeMockRecorder) Stop

func (mr *MockKVStoreWithRangeMockRecorder) Stop(arg0 interface{}) *gomock.Call

Stop indicates an expected call of Stop.

func (*MockKVStoreWithRangeMockRecorder) WriteBatch

func (mr *MockKVStoreWithRangeMockRecorder) WriteBatch(arg0 interface{}) *gomock.Call

WriteBatch indicates an expected call of WriteBatch.

type Option

type Option func(b *BoltDBVersioned)

Option sets an option

type PebbleDB

type PebbleDB struct {
	lifecycle.Readiness
	// contains filtered or unexported fields
}

PebbleDB is KVStore implementation based on pebble DB

func NewPebbleDB

func NewPebbleDB(cfg Config) *PebbleDB

NewPebbleDB creates a new PebbleDB instance

func (*PebbleDB) Delete

func (b *PebbleDB) Delete(ns string, key []byte) (err error)

Delete deletes a record,if key is nil,this will delete the whole bucket

func (*PebbleDB) Filter

func (b *PebbleDB) Filter(ns string, cond Condition, minKey []byte, maxKey []byte) (keys [][]byte, vals [][]byte, err error)

Filter returns <k, v> pair in a bucket that meet the condition

func (*PebbleDB) ForEach

func (b *PebbleDB) ForEach(ns string, fn func(k, v []byte) error) error

ForEach iterates over all <k, v> pairs in a bucket

func (*PebbleDB) Get

func (b *PebbleDB) Get(ns string, key []byte) ([]byte, error)

Get retrieves a record

func (*PebbleDB) Put

func (b *PebbleDB) Put(ns string, key, value []byte) (err error)

Put inserts a <key, value> record

func (*PebbleDB) Start

func (b *PebbleDB) Start(_ context.Context) error

Start opens the DB (creates new file if not existing yet)

func (*PebbleDB) Stop

func (b *PebbleDB) Stop(_ context.Context) error

Stop closes the DB

func (*PebbleDB) WriteBatch

func (b *PebbleDB) WriteBatch(kvsb batch.KVStoreBatch) error

WriteBatch commits a batch

type RangeIndex

type RangeIndex interface {
	// Insert inserts a value into the index
	Insert(uint64, []byte) error
	// Get returns value by the key
	Get(uint64) ([]byte, error)
	// Delete deletes an existing key
	Delete(uint64) error
	// Purge deletes an existing key and all keys before it
	Purge(uint64) error
	// Close makes the index not usable
	Close()
}

RangeIndex is a bucket of sparse <k, v> pair, where k consists of 8-byte value and all keys that falls in 2 consecutive k have the same v for example, given 3 entries in the bucket:

k = 0x0000000000000004 ==> v1 k = 0x0000000000000123 ==> v2 k = 0x0000000000005678 ==> v3

we have: for all key 0x0 <= k < 0x4, value[k] = initial value for all key 0x4 <= k < 0x123, value[k] = v1 for all key 0x123 <= k < 0x5678, value[k] = v2 for all key k >= 0x5678, value[k] = v3

func NewRangeIndex

func NewRangeIndex(kv KVStore, name, init []byte) (RangeIndex, error)

NewRangeIndex creates a new instance of rangeIndex

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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