storageUnit

package
v1.0.81 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2020 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewBloomFilter

func NewBloomFilter(conf BloomConfig) (storage.BloomFilter, error)

NewBloomFilter creates a new bloom filter from bloom filter config

func NewCache

func NewCache(cacheType CacheType, size uint32, shards uint32) (storage.Cacher, error)

NewCache creates a new cache from a cache config TODO: add a cacher factory or a cacheConfig param instead

func NewDB

func NewDB(dbType DBType, path string, batchDelaySeconds int, maxBatchSize int, maxOpenFiles int) (storage.Persister, error)

NewDB creates a new database from database config

func NewNilStorer

func NewNilStorer() *nilStorer

NewNilStorer will return a nil storer

Types

type BloomConfig

type BloomConfig struct {
	Size     uint
	HashFunc []HasherType
}

BloomConfig holds the configurable elements of a bloom filter

type CacheConfig

type CacheConfig struct {
	Size   uint32
	Type   CacheType
	Shards uint32
}

CacheConfig holds the configurable elements of a cache

type CacheType

type CacheType string

CacheType represents the type of the supported caches

const (
	LRUCache         CacheType = "LRU"
	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"
	BadgerDB    DBType = "BadgerDB"
	BoltDB      DBType = "BoltDB"
)

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 Unit

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

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

func NewShardedStorageUnitFromConf added in v1.0.3

func NewShardedStorageUnitFromConf(cacheConf CacheConfig, dbConf DBConfig, bloomFilterConf BloomConfig, shardId uint32) (*Unit, error)

NewShardedStorageUnitFromConf creates a new sharded storage unit from a storage unit config

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, bloomFilterConf BloomConfig) (*Unit, error)

NewStorageUnitFromConf creates a new storage unit from a storage unit config

func NewStorageUnitWithBloomFilter

func NewStorageUnitWithBloomFilter(c storage.Cacher, p storage.Persister, b storage.BloomFilter) (*Unit, error)

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

func (*Unit) ClearCache

func (u *Unit) ClearCache()

ClearCache cleans up the entire cache

func (*Unit) Close

func (s *Unit) Close() error

Close will close unit

func (*Unit) DestroyUnit

func (u *Unit) DestroyUnit() error

DestroyUnit cleans up the bloom filter, 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 searches for the key in bloom filter first and if 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) 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) 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 bloom filter and if present it checks the db

func (*Unit) HasInEpoch

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

HasInEpoch will call the Has method as this storer doesn't handle epochs

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 and updates the bloom filter

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) 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
	BloomConf BloomConfig
}

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