store

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: Apache-2.0 Imports: 9 Imported by: 2

Documentation

Index

Constants

View Source
const (
	EvictTryDist = 16
)

Variables

View Source
var PhaseTrunkTime, PhaseEndWriteTime uint64 //nolint:unused

Functions

func SyncUpdateTo added in v0.4.1

func SyncUpdateTo(m map[string]string, root types.RootStoreI)

Types

type CacheStore

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

CacheStore is used in two places: 1. as the temporal cache in TrunkStore, and 2. as the underlying storage in MockRootStore The 'Delete' function is used in place 1, which only marks a KV pair should be later deleted in the underlying RootStore. THe 'RealDelete' function is used in place 2.

func NewCacheStore

func NewCacheStore(size int) *CacheStore

func (*CacheStore) Close

func (cs *CacheStore) Close()

func (*CacheStore) Delete

func (cs *CacheStore) Delete(key []byte)

func (*CacheStore) Get

func (cs *CacheStore) Get(key []byte) (res []byte, status types.CacheStatus)

func (*CacheStore) RealDelete

func (cs *CacheStore) RealDelete(key []byte)

func (*CacheStore) ScanAllEntries

func (cs *CacheStore) ScanAllEntries(fn func(k, v []byte, isDeleted bool))

func (*CacheStore) ScanAllEntriesInShard added in v0.2.0

func (cs *CacheStore) ScanAllEntriesInShard(shardID int, fn func(k, v []byte, isDeleted bool))

func (*CacheStore) Set

func (cs *CacheStore) Set(key, value []byte)

func (*CacheStore) Size

func (cs *CacheStore) Size() int

type MockRootStore

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

MockRootStore mimics RootStore's behavior, with an in-memory CacheStore

func NewMockRootStore

func NewMockRootStore() *MockRootStore

func (*MockRootStore) ActiveCount

func (rs *MockRootStore) ActiveCount() int

func (*MockRootStore) BeginWrite

func (rs *MockRootStore) BeginWrite()

func (*MockRootStore) CheckConsistency

func (rs *MockRootStore) CheckConsistency()

func (*MockRootStore) Close

func (rs *MockRootStore) Close()

func (*MockRootStore) Delete

func (rs *MockRootStore) Delete(key []byte)

func (*MockRootStore) EndWrite

func (rs *MockRootStore) EndWrite()

func (*MockRootStore) Get

func (rs *MockRootStore) Get(key []byte) []byte

func (*MockRootStore) GetAtHeight added in v0.4.0

func (rs *MockRootStore) GetAtHeight(key []byte, height uint64) []byte

func (*MockRootStore) GetTrunkStore

func (rs *MockRootStore) GetTrunkStore(cacheSize int) interface{}

func (*MockRootStore) Has

func (rs *MockRootStore) Has(key []byte) bool

func (*MockRootStore) Lock

func (rs *MockRootStore) Lock()

func (*MockRootStore) PrepareForDeletion

func (rs *MockRootStore) PrepareForDeletion(key []byte)

func (*MockRootStore) PrepareForUpdate

func (rs *MockRootStore) PrepareForUpdate(key []byte)

func (*MockRootStore) RLock

func (rs *MockRootStore) RLock()

func (*MockRootStore) RUnlock

func (rs *MockRootStore) RUnlock()

func (*MockRootStore) Set

func (rs *MockRootStore) Set(key, value []byte)

func (*MockRootStore) SetHeight

func (rs *MockRootStore) SetHeight(h int64)

func (*MockRootStore) Unlock

func (rs *MockRootStore) Unlock()

func (*MockRootStore) Update

func (rs *MockRootStore) Update(updater func(db types.SetDeleter))

type RootStore

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

RootStore wraps a cache and a moeingads. This cache can hold written data from many blocks, and when it reaches size limit, the older data are evicted out. This cache is write-through, which means the data written to it are also written to MoeingADS. When cache misses, we can always fetch data from MoeingADS A RWMutex protects MoeingADS and cache, making sure when data are written to them, no read operation is permitted.

func NewRootStore

func NewRootStore(mads *moeingads.MoeingADS, isCacheableKey func(k []byte) bool) *RootStore

func (*RootStore) ActiveCount

func (root *RootStore) ActiveCount() int

func (*RootStore) BeginWrite

func (root *RootStore) BeginWrite()

When the client code writes RootStore, it must follow 'BeginWrite -> Set&Delete -> EndWrite' sequence, or it can use the 'Update' function which ensures such a sequence.

func (*RootStore) Close

func (root *RootStore) Close()

func (*RootStore) Delete

func (root *RootStore) Delete(key []byte)

func (*RootStore) EndWrite

func (root *RootStore) EndWrite()

func (*RootStore) Get

func (root *RootStore) Get(key []byte) []byte

func (*RootStore) GetAtHeight added in v0.4.0

func (root *RootStore) GetAtHeight(key []byte, height uint64) []byte

func (*RootStore) GetReadOnlyTrunkStore

func (root *RootStore) GetReadOnlyTrunkStore(cacheSize int) interface{}

func (*RootStore) GetRootHash

func (root *RootStore) GetRootHash() []byte

func (*RootStore) GetTrunkStore

func (root *RootStore) GetTrunkStore(cacheSize int) interface{}

func (*RootStore) Lock

func (root *RootStore) Lock()

func (*RootStore) PrepareForDeletion

func (root *RootStore) PrepareForDeletion(key []byte)

func (*RootStore) PrepareForUpdate

func (root *RootStore) PrepareForUpdate(key []byte)

func (*RootStore) RLock

func (root *RootStore) RLock()

One RootStore can be used by many TrunkStores and RabbitStores. There can be only one writter and many readers. RootStore is written in TruckStore's WriteBack, which protect the writing process with the write-lock, and is read during the life time of RabbitStores. So RabbitStores acquire read-lock at creation and release read-lock when closing. Writer won't starve: https://stackoverflow.com/questions/46786900/the-implementions-of-rwmutex-lock-in-golang

func (*RootStore) RUnlock

func (root *RootStore) RUnlock()

func (*RootStore) Set

func (root *RootStore) Set(key, value []byte)

func (*RootStore) SetHeight

func (root *RootStore) SetHeight(h int64)

func (*RootStore) Unlock

func (root *RootStore) Unlock()

func (*RootStore) Update

func (root *RootStore) Update(updater func(db types.SetDeleter))

type TrunkStore

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

TrunkStore use a temporal cache to buffer the written data from successive transactions, such that the latter transactions can read the data which were written by previous transactions. When these transactions are running, isWriting is always 0. When a transaction is writting back to TrunkStore, isWriting is setting to 1. When the writting process is finished, isWritting is setting back to 0. The client code should manages the transactions to make sure their writing-back processes are performed in serial. When a TrunkStore closes after servicing all the transactions, it may write the temporal cache's content to the underlying RootStore, if isReadOnly==false. A transaction usually access a TrunkStore through a RabbitStore.

func (*TrunkStore) ActiveCount

func (ts *TrunkStore) ActiveCount() int

func (*TrunkStore) CacheSize added in v0.2.0

func (ts *TrunkStore) CacheSize() int

func (*TrunkStore) Close

func (ts *TrunkStore) Close(writeBack bool)

func (*TrunkStore) Get

func (ts *TrunkStore) Get(key []byte) []byte

func (*TrunkStore) GetAtHeight added in v0.4.0

func (ts *TrunkStore) GetAtHeight(key []byte, height uint64) []byte

func (*TrunkStore) GetCacheContent added in v0.4.1

func (ts *TrunkStore) GetCacheContent() map[string]string

func (*TrunkStore) PrepareForDeletion

func (ts *TrunkStore) PrepareForDeletion(key []byte)

func (*TrunkStore) PrepareForUpdate

func (ts *TrunkStore) PrepareForUpdate(key []byte)

func (*TrunkStore) RLock

func (ts *TrunkStore) RLock()

func (*TrunkStore) RUnlock

func (ts *TrunkStore) RUnlock()

func (*TrunkStore) Update

func (ts *TrunkStore) Update(updater func(db types.SetDeleter))

func (*TrunkStore) WriteBack

func (ts *TrunkStore) WriteBack()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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