cache

package
v3.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCacheWrapToDBHandle

func NewCacheWrapToDBHandle(c Cache, innerDb protocol.DBHandle, l protocol.Logger) protocol.DBHandle

NewCacheWrapToDBHandle return a cacheWrapToDB which cache , db and log

@Description:
@param c
@param innerDb
@param l
@return protocol.DBHandle

func QuickSort

func QuickSort(arr []uint64) []uint64

QuickSort 快排,获得从小到大排序后的结果,返回

@Description:
@param arr
@return []uint64

func SystemQuickSort

func SystemQuickSort(arr []uint64)

SystemQuickSort 快排,获得从大到小排序后的结果,返回

@Description:
@param arr
@return []uint64

Types

type Cache

type Cache interface {

	// Get get key from cache or db
	//  @Description:
	//  @param key
	//  @return []byte
	//  @return error
	Get(key string) ([]byte, error)

	// Set set k/v
	//  @Description:
	//  @param key
	//  @param entry
	//  @return error
	Set(key string, entry []byte) error

	// Delete del k
	//  @Description:
	//  @param key
	//  @return error
	Delete(key string) error

	// Reset set cache to initial state
	//  @Description:
	//  @return error
	Reset() error

	// Close  close cache
	//  @Description:
	//  @return error
	Close() error
}

Cache interface

@Description:

type CacheWrapToDBHandle

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

CacheWrapToDBHandle struct

@Description:

func (*CacheWrapToDBHandle) Close

func (c *CacheWrapToDBHandle) Close() error

Close close cache and db

@Description:
@receiver c
@return error

func (*CacheWrapToDBHandle) CompactRange

func (c *CacheWrapToDBHandle) CompactRange(start, limit []byte) error

CompactRange compacts the underlying DB for the given key range

@Description:
@receiver c
@param start
@param limit
@return error

func (*CacheWrapToDBHandle) Delete

func (c *CacheWrapToDBHandle) Delete(key []byte) error

Delete delete key/value from cache and db

@Description:
@receiver c
@param key
@return error

func (*CacheWrapToDBHandle) Get

func (c *CacheWrapToDBHandle) Get(key []byte) ([]byte, error)

Get get value by key from cache and db

@Description:
@receiver c
@param key
@return []byte
@return error

func (*CacheWrapToDBHandle) GetDbType

func (c *CacheWrapToDBHandle) GetDbType() string

GetDbType get db type from db

@Description:
@receiver c
@return string

func (*CacheWrapToDBHandle) GetKeys

func (c *CacheWrapToDBHandle) GetKeys(keys [][]byte) ([][]byte, error)

GetKeys batch get key's value; if not found , batch get from db then refill them in cache @Description: @receiver c @param keys @return [][]byte @return error

func (*CacheWrapToDBHandle) GetWriteBatchSize

func (c *CacheWrapToDBHandle) GetWriteBatchSize() uint64

GetWriteBatchSize not implement , will panic

@Description:
@receiver c
@return uint64

func (*CacheWrapToDBHandle) Has

func (c *CacheWrapToDBHandle) Has(key []byte) (bool, error)

Has check key whether exist in cache and db

@Description:
@receiver c
@param key
@return bool
@return error

func (*CacheWrapToDBHandle) NewIteratorWithPrefix

func (c *CacheWrapToDBHandle) NewIteratorWithPrefix(prefix []byte) (protocol.Iterator, error)

NewIteratorWithPrefix returns an iterator that contains all the key-values with given prefix

@Description:
@receiver c
@param prefix
@return protocol.Iterator
@return error

func (*CacheWrapToDBHandle) NewIteratorWithRange

func (c *CacheWrapToDBHandle) NewIteratorWithRange(start []byte, limit []byte) (protocol.Iterator, error)

NewIteratorWithRange return iterator from db that contains all the key-values between given key ranges start is included in the results and limit is excluded.

@Description:
@receiver c
@param start
@param limit
@return protocol.Iterator
@return error

func (*CacheWrapToDBHandle) Put

func (c *CacheWrapToDBHandle) Put(key []byte, value []byte) error

Put set key/value include cache and db @Description: @receiver c @param key @param value @return error

func (*CacheWrapToDBHandle) WriteBatch

func (c *CacheWrapToDBHandle) WriteBatch(batch protocol.StoreBatcher, sync bool) error

WriteBatch write a batch to cache and db

@Description:
@receiver c
@param batch
@param sync
@return error

type StoreCacheMgr

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

StoreCacheMgr provide handle to cache instances

@Description:

func NewStoreCacheMgr

func NewStoreCacheMgr(chainId string, blockWriteBufferSize int, logger protocol.Logger) *StoreCacheMgr

NewStoreCacheMgr construct a new `StoreCacheMgr` with given chainId

@Description:
@param chainId
@param blockWriteBufferSize
@param logger
@return *StoreCacheMgr

func (*StoreCacheMgr) AddBlock

func (mgr *StoreCacheMgr) AddBlock(blockHeight uint64, updateBatch protocol.StoreBatcher)

AddBlock cache a block with given block height and update batch

@Description:
@receiver mgr
@param blockHeight
@param updateBatch

func (*StoreCacheMgr) Clear

func (mgr *StoreCacheMgr) Clear()

Clear 清除缓存,目前未做任何清除操作

@Description:
@receiver mgr

func (*StoreCacheMgr) DelBlock

func (mgr *StoreCacheMgr) DelBlock(blockHeight uint64)

DelBlock delete block for the given block height

@Description:
@receiver mgr
@param blockHeight

func (*StoreCacheMgr) Get

func (mgr *StoreCacheMgr) Get(key string) ([]byte, bool)

Get returns value if the key in cache, or returns nil if none exists.

@Description:
@receiver mgr
@param key
@return []byte
@return bool

func (*StoreCacheMgr) GetBatch

func (mgr *StoreCacheMgr) GetBatch(height uint64) (protocol.StoreBatcher, error)

GetBatch 根据块高,返回 块对应的cache

@Description:
@receiver mgr
@param height
@return protocol.StoreBatcher
@return error

func (*StoreCacheMgr) GetLength

func (mgr *StoreCacheMgr) GetLength() int

GetLength returns the length of the pendingBlockUpdates

func (*StoreCacheMgr) Has

func (mgr *StoreCacheMgr) Has(key string) (bool, bool)

Has returns true if the key in cache, or returns false if none exists. 如果这个key 对应value 是 nil,说明这个key被删除了 所以查找到第一个key,要判断 这个key 是否是被删除的

@Description:
@receiver mgr
@param key
@return bool isDelete
@return bool isExist

func (*StoreCacheMgr) HasFromHeight

func (mgr *StoreCacheMgr) HasFromHeight(key string, startHeight uint64, endHeight uint64) (bool, bool)

HasFromHeight returns true if the key in cache, or returns false if none exists by given startHeight, endHeight. 如果这个key 对应value 是 nil,说明这个key被删除了 所以查找到第一个key,要判断 这个key 是否是被删除的

@Description:
@receiver mgr
@param key, startHeight, endHeight
@return bool isDelete
@return bool isExist

func (*StoreCacheMgr) KVRange

func (mgr *StoreCacheMgr) KVRange(startKey []byte, endKey []byte) (map[string][]byte, error)

KVRange get data from mgr , [startKey,endKey)

@Description:
@receiver mgr
@param startKey
@param endKey
@return map[string][]byte
@return error

func (*StoreCacheMgr) LockForFlush

func (mgr *StoreCacheMgr) LockForFlush()

LockForFlush used to lock cache until all cache item be flushed to db

@Description:
@receiver mgr

func (*StoreCacheMgr) UnLockFlush

func (mgr *StoreCacheMgr) UnLockFlush()

UnLockFlush used to unlock cache by release all semaphore

@Description:
@receiver mgr

Jump to

Keyboard shortcuts

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