mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
core: fix txindexer db access bottleneck
This commit is contained in:
parent
701df4baad
commit
9796c1bda1
1 changed files with 7 additions and 6 deletions
|
|
@ -216,9 +216,10 @@ func (indexer *txIndexer) loop(chain *BlockChain) {
|
||||||
|
|
||||||
// Listening to chain events and manipulate the transaction indexes.
|
// Listening to chain events and manipulate the transaction indexes.
|
||||||
var (
|
var (
|
||||||
stop chan struct{} // Non-nil if background routine is active
|
stop chan struct{} // Non-nil if background routine is active
|
||||||
done chan struct{} // Non-nil if background routine is active
|
done chan struct{} // Non-nil if background routine is active
|
||||||
head = indexer.resolveHead() // The latest announced chain head
|
head = indexer.resolveHead() // The latest announced chain head
|
||||||
|
lastTail = rawdb.ReadTxIndexTail(indexer.db) // // The oldest indexed block, nil means nothing indexed
|
||||||
|
|
||||||
headCh = make(chan ChainHeadEvent)
|
headCh = make(chan ChainHeadEvent)
|
||||||
sub = chain.SubscribeChainHeadEvent(headCh)
|
sub = chain.SubscribeChainHeadEvent(headCh)
|
||||||
|
|
@ -247,8 +248,9 @@ func (indexer *txIndexer) loop(chain *BlockChain) {
|
||||||
case <-done:
|
case <-done:
|
||||||
stop = nil
|
stop = nil
|
||||||
done = nil
|
done = nil
|
||||||
|
lastTail = rawdb.ReadTxIndexTail(indexer.db)
|
||||||
case ch := <-indexer.progress:
|
case ch := <-indexer.progress:
|
||||||
ch <- indexer.report(head)
|
ch <- indexer.report(head, lastTail)
|
||||||
case ch := <-indexer.term:
|
case ch := <-indexer.term:
|
||||||
if stop != nil {
|
if stop != nil {
|
||||||
close(stop)
|
close(stop)
|
||||||
|
|
@ -264,7 +266,7 @@ func (indexer *txIndexer) loop(chain *BlockChain) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// report returns the tx indexing progress.
|
// report returns the tx indexing progress.
|
||||||
func (indexer *txIndexer) report(head uint64) TxIndexProgress {
|
func (indexer *txIndexer) report(head uint64, tail *uint64) TxIndexProgress {
|
||||||
// Special case if the head is even below the cutoff,
|
// Special case if the head is even below the cutoff,
|
||||||
// nothing to index.
|
// nothing to index.
|
||||||
if head < indexer.cutoff {
|
if head < indexer.cutoff {
|
||||||
|
|
@ -284,7 +286,6 @@ func (indexer *txIndexer) report(head uint64) TxIndexProgress {
|
||||||
}
|
}
|
||||||
// Compute how many blocks have been indexed
|
// Compute how many blocks have been indexed
|
||||||
var indexed uint64
|
var indexed uint64
|
||||||
tail := rawdb.ReadTxIndexTail(indexer.db)
|
|
||||||
if tail != nil {
|
if tail != nil {
|
||||||
indexed = head - *tail + 1
|
indexed = head - *tail + 1
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue