mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 05:36:46 +00:00
index writer/deleter also read from cache
Signed-off-by: Delweng <delweng@gmail.com>
This commit is contained in:
parent
26a17bc410
commit
da3abe3fe7
1 changed files with 49 additions and 16 deletions
|
|
@ -80,11 +80,11 @@ type indexReader struct {
|
|||
}
|
||||
|
||||
// loadIndexData loads the index data associated with the specified state.
|
||||
func loadIndexData(db ethdb.KeyValueReader, state stateIdent, timings *readTimings, cacheRead bool, cacher *historyCacher) ([]*indexBlockDesc, error) {
|
||||
func loadIndexData(db ethdb.KeyValueReader, state stateIdent, timings *readTimings, cacher *historyCacher) ([]*indexBlockDesc, error) {
|
||||
start := time.Now()
|
||||
key := state.String()
|
||||
var blob []byte
|
||||
if cacheRead && cacher != nil && cacher.index.Contains(key) {
|
||||
if cacher != nil && cacher.index.Contains(key) {
|
||||
blob, _ = cacher.index.Get(key)
|
||||
} else {
|
||||
if state.account {
|
||||
|
|
@ -113,7 +113,7 @@ func newIndexReader(db ethdb.KeyValueReader, state stateIdent, cacher *historyCa
|
|||
|
||||
// Helper to allow passing timings
|
||||
func newIndexReaderWithTimings(db ethdb.KeyValueReader, state stateIdent, timings *readTimings, cacher *historyCacher) (*indexReader, error) {
|
||||
descList, err := loadIndexData(db, state, timings, true, cacher)
|
||||
descList, err := loadIndexData(db, state, timings, cacher)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -138,7 +138,7 @@ func (r *indexReader) refresh() error {
|
|||
delete(r.readers, last.id)
|
||||
}
|
||||
}
|
||||
descList, err := loadIndexData(r.db, r.state, r.timings, false, r.cacher)
|
||||
descList, err := loadIndexData(r.db, r.state, r.timings, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -211,11 +211,20 @@ type indexWriter struct {
|
|||
// newIndexWriter constructs the index writer for the specified state.
|
||||
func newIndexWriter(db ethdb.KeyValueReader, state stateIdent, cacher *historyCacher) (*indexWriter, error) {
|
||||
var blob []byte
|
||||
|
||||
key := state.String()
|
||||
if cacher != nil && cacher.index.Contains(key) {
|
||||
blob, _ = cacher.index.Get(key)
|
||||
} else {
|
||||
if state.account {
|
||||
blob = rawdb.ReadAccountHistoryIndex(db, state.addressHash)
|
||||
} else {
|
||||
blob = rawdb.ReadStorageHistoryIndex(db, state.addressHash, state.storageHash)
|
||||
}
|
||||
if cacher != nil {
|
||||
cacher.index.Add(key, blob)
|
||||
}
|
||||
}
|
||||
if len(blob) == 0 {
|
||||
desc := newIndexBlockDesc(0)
|
||||
bw, _ := newBlockWriter(nil, desc)
|
||||
|
|
@ -235,11 +244,19 @@ func newIndexWriter(db ethdb.KeyValueReader, state stateIdent, cacher *historyCa
|
|||
indexBlock []byte
|
||||
lastDesc = descList[len(descList)-1]
|
||||
)
|
||||
key = fmt.Sprintf("%s:%d", state.String(), lastDesc.id)
|
||||
if cacher != nil && cacher.block.Contains(key) {
|
||||
indexBlock, _ = cacher.block.Get(key)
|
||||
} else {
|
||||
if state.account {
|
||||
indexBlock = rawdb.ReadAccountHistoryIndexBlock(db, state.addressHash, lastDesc.id)
|
||||
} else {
|
||||
indexBlock = rawdb.ReadStorageHistoryIndexBlock(db, state.addressHash, state.storageHash, lastDesc.id)
|
||||
}
|
||||
if cacher != nil {
|
||||
cacher.block.Add(key, indexBlock)
|
||||
}
|
||||
}
|
||||
bw, err := newBlockWriter(indexBlock, lastDesc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -352,11 +369,19 @@ type indexDeleter struct {
|
|||
// newIndexDeleter constructs the index deleter for the specified state.
|
||||
func newIndexDeleter(db ethdb.KeyValueReader, state stateIdent, cacher *historyCacher) (*indexDeleter, error) {
|
||||
var blob []byte
|
||||
key := state.String()
|
||||
if cacher != nil && cacher.index.Contains(key) {
|
||||
blob, _ = cacher.index.Get(key)
|
||||
} else {
|
||||
if state.account {
|
||||
blob = rawdb.ReadAccountHistoryIndex(db, state.addressHash)
|
||||
} else {
|
||||
blob = rawdb.ReadStorageHistoryIndex(db, state.addressHash, state.storageHash)
|
||||
}
|
||||
if cacher != nil {
|
||||
cacher.index.Add(key, blob)
|
||||
}
|
||||
}
|
||||
if len(blob) == 0 {
|
||||
// TODO(rjl493456442) we can probably return an error here,
|
||||
// deleter with no data is meaningless.
|
||||
|
|
@ -378,11 +403,19 @@ func newIndexDeleter(db ethdb.KeyValueReader, state stateIdent, cacher *historyC
|
|||
indexBlock []byte
|
||||
lastDesc = descList[len(descList)-1]
|
||||
)
|
||||
key = fmt.Sprintf("%s:%d", state.String(), lastDesc.id)
|
||||
if cacher != nil && cacher.block.Contains(key) {
|
||||
indexBlock, _ = cacher.block.Get(key)
|
||||
} else {
|
||||
if state.account {
|
||||
indexBlock = rawdb.ReadAccountHistoryIndexBlock(db, state.addressHash, lastDesc.id)
|
||||
} else {
|
||||
indexBlock = rawdb.ReadStorageHistoryIndexBlock(db, state.addressHash, state.storageHash, lastDesc.id)
|
||||
}
|
||||
if cacher != nil {
|
||||
cacher.block.Add(key, indexBlock)
|
||||
}
|
||||
}
|
||||
bw, err := newBlockWriter(indexBlock, lastDesc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
Loading…
Reference in a new issue