storageUnit

package
v1.999.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2022 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCache

func NewCache(config CacheConfig) (storage.Cacher, error)

NewCache creates a new cache from a cache config

func NewDB

func NewDB(argDB ArgDB) (storage.Persister, error)

NewDB creates a new database from database config

Types

type ArgDB

type ArgDB struct {
	DBType            DBType
	Path              string
	BatchDelaySeconds int
	MaxBatchSize      int
	MaxOpenFiles      int
}

ArgDB is a structure that is used to create a new storage.Persister implementation

type CacheConfig

type CacheConfig struct {
	Name                 string
	Type                 CacheType
	SizeInBytes          uint64
	SizeInBytesPerSender uint32
	Capacity             uint32
	SizePerSender        uint32
	Shards               uint32
}

CacheConfig holds the configurable elements of a cache

func (*CacheConfig) String

func (config *CacheConfig) String() string

String returns a readable representation of the object

type CacheType

type CacheType string

CacheType represents the type of the supported caches

const (
	LRUCache         CacheType = "LRU"
	SizeLRUCache     CacheType = "SizeLRU"
	FIFOShardedCache CacheType = "FIFOSharded"
)

LRUCache is currently the only supported Cache type

type DBConfig

type DBConfig struct {
	FilePath          string
	Type              DBType
	BatchDelaySeconds int
	MaxBatchSize      int
	MaxOpenFiles      int
}

DBConfig holds the configurable elements of a database

type DBType

type DBType string

DBType represents the type of the supported databases

const (
	LvlDB       DBType = "LvlDB"
	LvlDBSerial DBType = "LvlDBSerial"
	MemoryDB    DBType = "MemoryDB"
)

LvlDB currently the only supported DBs More to be added

type HasherType

type HasherType string

HasherType represents the type of the supported hash functions

const (
	// Keccak is the string representation of the keccak hashing function
	Keccak HasherType = "Keccak"
	// Blake2b is the string representation of the blake2b hashing function
	Blake2b HasherType = "Blake2b"
	// Fnv is the string representation of the fnv hashing function
	Fnv HasherType = "Fnv"
)

func (HasherType) NewHasher

func (h HasherType) NewHasher() (hashing.Hasher, error)

NewHasher will return a hasher implementation form the string HasherType

type NilStorer

type NilStorer struct {
}

NilStorer resembles a disabled implementation of the Storer interface

func NewNilStorer

func NewNilStorer() *NilStorer

NewNilStorer will return a nil storer

func (*NilStorer) ClearCache

func (ns *NilStorer) ClearCache()

ClearCache will do nothing

func (*NilStorer) Close

func (ns *NilStorer) Close() error

Close will do nothing

func (*NilStorer) DestroyUnit

func (ns *NilStorer) DestroyUnit() error

DestroyUnit will do nothing

func (*NilStorer) Get

func (ns *NilStorer) Get(_ []byte) ([]byte, error)

Get will do nothing

func (*NilStorer) GetBulkFromEpoch

func (ns *NilStorer) GetBulkFromEpoch(_ [][]byte, _ uint32) ([]storageCore.KeyValuePair, error)

GetBulkFromEpoch will do nothing

func (*NilStorer) GetFromEpoch

func (ns *NilStorer) GetFromEpoch(_ []byte, _ uint32) ([]byte, error)

GetFromEpoch will do nothing

func (*NilStorer) GetOldestEpoch

func (ns *NilStorer) GetOldestEpoch() (uint32, error)

GetOldestEpoch will return an error that signals that the oldest epoch fetching is not available

func (*NilStorer) Has

func (ns *NilStorer) Has(_ []byte) error

Has will do nothing

func (*NilStorer) IsInterfaceNil

func (ns *NilStorer) IsInterfaceNil() bool

IsInterfaceNil returns true if there is no value under the interface

func (*NilStorer) Put

func (ns *NilStorer) Put(_, _ []byte) error

Put will do nothing

func (*NilStorer) PutInEpoch

func (ns *NilStorer) PutInEpoch(_, _ []byte, _ uint32) error

PutInEpoch will do nothing

func (*NilStorer) RangeKeys

func (ns *NilStorer) RangeKeys(_ func(key []byte, val []byte) bool)

RangeKeys does nothing

func (*NilStorer) Remove

func (ns *NilStorer) Remove(_ []byte) error

Remove will do nothing

func (*NilStorer) RemoveFromCurrentEpoch

func (ns *NilStorer) RemoveFromCurrentEpoch(_ []byte) error

RemoveFromCurrentEpoch will do nothing

func (*NilStorer) SearchFirst

func (ns *NilStorer) SearchFirst(_ []byte) ([]byte, error)

SearchFirst will do nothing

type Unit

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

Unit represents a storer's data bank holding the cache and persistence unit

func NewStorageUnit

func NewStorageUnit(c storage.Cacher, p storage.Persister) (*Unit, error)

NewStorageUnit is the constructor for the storage unit, creating a new storage unit from the given cacher and persister.

func NewStorageUnitFromConf

func NewStorageUnitFromConf(cacheConf CacheConfig, dbConf DBConfig) (*Unit, error)

NewStorageUnitFromConf creates a new storage unit from a storage unit config

func (*Unit) ClearCache

func (u *Unit) ClearCache()

ClearCache cleans up the entire cache

func (*Unit) Close

func (u *Unit) Close() error

Close will close unit

func (*Unit) DestroyUnit

func (u *Unit) DestroyUnit() error

DestroyUnit cleans up the cache, and the db

func (*Unit) Get

func (u *Unit) Get(key []byte) ([]byte, error)

Get searches the key in the cache. In case it is not found, it further searches it in the associated database. In case it is found in the database, the cache is updated with the value as well.

func (*Unit) GetBulkFromEpoch

func (u *Unit) GetBulkFromEpoch(keys [][]byte, _ uint32) ([]storageCore.KeyValuePair, error)

GetBulkFromEpoch will call the Get method for all keys as this storer doesn't handle epochs

func (*Unit) GetFromEpoch

func (u *Unit) GetFromEpoch(key []byte, _ uint32) ([]byte, error)

GetFromEpoch will call the Get method as this storer doesn't handle epochs

func (*Unit) GetOldestEpoch

func (u *Unit) GetOldestEpoch() (uint32, error)

GetOldestEpoch will return an error that signals that the oldest epoch fetching is not available

func (*Unit) Has

func (u *Unit) Has(key []byte) error

Has checks if the key is in the Unit. It first checks the cache. If it is not found, it checks the db

func (*Unit) IsInterfaceNil

func (u *Unit) IsInterfaceNil() bool

IsInterfaceNil returns true if there is no value under the interface

func (*Unit) Put

func (u *Unit) Put(key, data []byte) error

Put adds data to both cache and persistence medium

func (*Unit) PutInEpoch

func (u *Unit) PutInEpoch(key, data []byte, _ uint32) error

PutInEpoch will call the Put method as this storer doesn't handle epochs

func (*Unit) RangeKeys

func (u *Unit) RangeKeys(handler func(key []byte, value []byte) bool)

RangeKeys can iterate over the persisted (key, value) pairs calling the provided handler

func (*Unit) Remove

func (u *Unit) Remove(key []byte) error

Remove removes the data associated to the given key from both cache and persistence medium

func (*Unit) RemoveFromCurrentEpoch

func (u *Unit) RemoveFromCurrentEpoch(key []byte) error

RemoveFromCurrentEpoch removes the data associated to the given key from both cache and persistence medium

func (*Unit) SearchFirst

func (u *Unit) SearchFirst(key []byte) ([]byte, error)

SearchFirst will call the Get method as this storer doesn't handle epochs

type UnitConfig

type UnitConfig struct {
	CacheConf CacheConfig
	DBConf    DBConfig
}

UnitConfig holds the configurable elements of the storage unit

Jump to

Keyboard shortcuts

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