Documentation ¶
Index ¶
- Constants
- Variables
- type CacheStore
- func (cs *CacheStore) Close()
- func (cs *CacheStore) Delete(key []byte)
- func (cs *CacheStore) Get(key []byte) (res []byte, status types.CacheStatus)
- func (cs *CacheStore) RealDelete(key []byte)
- func (cs *CacheStore) ScanAllEntries(fn func(k, v []byte, isDeleted bool))
- func (cs *CacheStore) ScanAllEntriesInShard(shardID int, fn func(k, v []byte, isDeleted bool))
- func (cs *CacheStore) Set(key, value []byte)
- func (cs *CacheStore) Size() int
- type MockRootStore
- func (rs *MockRootStore) ActiveCount() int
- func (rs *MockRootStore) BeginWrite()
- func (rs *MockRootStore) CheckConsistency()
- func (rs *MockRootStore) Close()
- func (rs *MockRootStore) Delete(key []byte)
- func (rs *MockRootStore) EndWrite()
- func (rs *MockRootStore) Get(key []byte) []byte
- func (rs *MockRootStore) GetAtHeight(key []byte, height uint64) []byte
- func (rs *MockRootStore) GetTrunkStore(cacheSize int) interface{}
- func (rs *MockRootStore) Has(key []byte) bool
- func (rs *MockRootStore) Lock()
- func (rs *MockRootStore) PrepareForDeletion(key []byte)
- func (rs *MockRootStore) PrepareForUpdate(key []byte)
- func (rs *MockRootStore) RLock()
- func (rs *MockRootStore) RUnlock()
- func (rs *MockRootStore) Set(key, value []byte)
- func (rs *MockRootStore) SetHeight(h int64)
- func (rs *MockRootStore) Unlock()
- func (rs *MockRootStore) Update(updater func(db types.SetDeleter))
- type RootStore
- func (root *RootStore) ActiveCount() int
- func (root *RootStore) BeginWrite()
- func (root *RootStore) Close()
- func (root *RootStore) Delete(key []byte)
- func (root *RootStore) EndWrite()
- func (root *RootStore) Get(key []byte) []byte
- func (root *RootStore) GetAtHeight(key []byte, height uint64) []byte
- func (root *RootStore) GetReadOnlyTrunkStore(cacheSize int) interface{}
- func (root *RootStore) GetRootHash() []byte
- func (root *RootStore) GetTrunkStore(cacheSize int) interface{}
- func (root *RootStore) Lock()
- func (root *RootStore) PrepareForDeletion(key []byte)
- func (root *RootStore) PrepareForUpdate(key []byte)
- func (root *RootStore) RLock()
- func (root *RootStore) RUnlock()
- func (root *RootStore) Set(key, value []byte)
- func (root *RootStore) SetHeight(h int64)
- func (root *RootStore) Unlock()
- func (root *RootStore) Update(updater func(db types.SetDeleter))
- type TrunkStore
- func (ts *TrunkStore) ActiveCount() int
- func (ts *TrunkStore) CacheSize() int
- func (ts *TrunkStore) Close(writeBack bool)
- func (ts *TrunkStore) Get(key []byte) []byte
- func (ts *TrunkStore) GetAtHeight(key []byte, height uint64) []byte
- func (ts *TrunkStore) PrepareForDeletion(key []byte)
- func (ts *TrunkStore) PrepareForUpdate(key []byte)
- func (ts *TrunkStore) RLock()
- func (ts *TrunkStore) RUnlock()
- func (ts *TrunkStore) Update(updater func(db types.SetDeleter))
- func (ts *TrunkStore) WriteBack()
Constants ¶
const (
EvictTryDist = 16
)
Variables ¶
var PhaseTrunkTime, PhaseEndWriteTime uint64 //nolint:unused
Functions ¶
This section is empty.
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 (*RootStore) ActiveCount ¶
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) GetAtHeight ¶ added in v0.4.0
func (*RootStore) GetReadOnlyTrunkStore ¶
func (*RootStore) GetRootHash ¶
func (*RootStore) GetTrunkStore ¶
func (*RootStore) PrepareForDeletion ¶
func (*RootStore) PrepareForUpdate ¶
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) 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) 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()