mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
core/filtermaps: allow log search while syncing / head indexing
This commit is contained in:
parent
c4f0450710
commit
666dbc19c6
4 changed files with 20 additions and 12 deletions
|
|
@ -70,6 +70,7 @@ type FilterMaps struct {
|
||||||
indexLock sync.RWMutex
|
indexLock sync.RWMutex
|
||||||
indexedRange filterMapsRange
|
indexedRange filterMapsRange
|
||||||
indexedView *ChainView // always consistent with the log index
|
indexedView *ChainView // always consistent with the log index
|
||||||
|
hasTempRange bool
|
||||||
|
|
||||||
// also accessed by indexer and matcher backend but no locking needed.
|
// also accessed by indexer and matcher backend but no locking needed.
|
||||||
filterMapCache *lru.Cache[uint32, filterMap]
|
filterMapCache *lru.Cache[uint32, filterMap]
|
||||||
|
|
@ -94,7 +95,7 @@ type FilterMaps struct {
|
||||||
ptrTailUnindexMap uint32
|
ptrTailUnindexMap uint32
|
||||||
|
|
||||||
targetView *ChainView
|
targetView *ChainView
|
||||||
matcherSyncRequest *FilterMapsMatcherBackend
|
matcherSyncRequests []*FilterMapsMatcherBackend
|
||||||
historyCutoff uint64
|
historyCutoff uint64
|
||||||
finalBlock, lastFinal uint64
|
finalBlock, lastFinal uint64
|
||||||
lastFinalEpoch uint32
|
lastFinalEpoch uint32
|
||||||
|
|
@ -330,7 +331,7 @@ func (f *FilterMaps) init() error {
|
||||||
fmr.blocks = common.NewRange(cp.BlockNumber+1, 0)
|
fmr.blocks = common.NewRange(cp.BlockNumber+1, 0)
|
||||||
fmr.maps = common.NewRange(uint32(bestLen)<<f.logMapsPerEpoch, 0)
|
fmr.maps = common.NewRange(uint32(bestLen)<<f.logMapsPerEpoch, 0)
|
||||||
}
|
}
|
||||||
f.setRange(batch, f.targetView, fmr)
|
f.setRange(batch, f.targetView, fmr, false)
|
||||||
return batch.Write()
|
return batch.Write()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -373,9 +374,10 @@ func (f *FilterMaps) removeDbWithPrefix(prefix []byte, action string) bool {
|
||||||
// setRange updates the indexed chain view and covered range and also adds the
|
// setRange updates the indexed chain view and covered range and also adds the
|
||||||
// changes to the given batch.
|
// changes to the given batch.
|
||||||
// Note that this function assumes that the index write lock is being held.
|
// Note that this function assumes that the index write lock is being held.
|
||||||
func (f *FilterMaps) setRange(batch ethdb.KeyValueWriter, newView *ChainView, newRange filterMapsRange) {
|
func (f *FilterMaps) setRange(batch ethdb.KeyValueWriter, newView *ChainView, newRange filterMapsRange, isTempRange bool) {
|
||||||
f.indexedView = newView
|
f.indexedView = newView
|
||||||
f.indexedRange = newRange
|
f.indexedRange = newRange
|
||||||
|
f.hasTempRange = isTempRange
|
||||||
f.updateMatchersValidRange()
|
f.updateMatchersValidRange()
|
||||||
if newRange.initialized {
|
if newRange.initialized {
|
||||||
rs := rawdb.FilterMapsRange{
|
rs := rawdb.FilterMapsRange{
|
||||||
|
|
@ -666,7 +668,7 @@ func (f *FilterMaps) deleteTailEpoch(epoch uint32) error {
|
||||||
} else {
|
} else {
|
||||||
return errors.New("invalid tail epoch number")
|
return errors.New("invalid tail epoch number")
|
||||||
}
|
}
|
||||||
f.setRange(f.db, f.indexedView, fmr)
|
f.setRange(f.db, f.indexedView, fmr, false)
|
||||||
first := f.mapRowIndex(firstMap, 0)
|
first := f.mapRowIndex(firstMap, 0)
|
||||||
count := f.mapRowIndex(firstMap+f.mapsPerEpoch, 0) - first
|
count := f.mapRowIndex(firstMap+f.mapsPerEpoch, 0) - first
|
||||||
rawdb.DeleteFilterMapRows(f.db, common.NewRange(first, count))
|
rawdb.DeleteFilterMapRows(f.db, common.NewRange(first, count))
|
||||||
|
|
|
||||||
|
|
@ -136,15 +136,18 @@ func (f *FilterMaps) processEvents() {
|
||||||
// processSingleEvent processes a single event either in a blocking or
|
// processSingleEvent processes a single event either in a blocking or
|
||||||
// non-blocking manner.
|
// non-blocking manner.
|
||||||
func (f *FilterMaps) processSingleEvent(blocking bool) bool {
|
func (f *FilterMaps) processSingleEvent(blocking bool) bool {
|
||||||
if f.matcherSyncRequest != nil && f.targetHeadIndexed() {
|
if !f.hasTempRange {
|
||||||
f.matcherSyncRequest.synced()
|
for _, mb := range f.matcherSyncRequests {
|
||||||
f.matcherSyncRequest = nil
|
mb.synced()
|
||||||
|
}
|
||||||
|
f.matcherSyncRequests = nil
|
||||||
}
|
}
|
||||||
if blocking {
|
if blocking {
|
||||||
select {
|
select {
|
||||||
case target := <-f.targetCh:
|
case target := <-f.targetCh:
|
||||||
f.setTarget(target)
|
f.setTarget(target)
|
||||||
case f.matcherSyncRequest = <-f.matcherSyncCh:
|
case mb := <-f.matcherSyncCh:
|
||||||
|
f.matcherSyncRequests = append(f.matcherSyncRequests, mb)
|
||||||
case f.blockProcessing = <-f.blockProcessingCh:
|
case f.blockProcessing = <-f.blockProcessingCh:
|
||||||
case <-f.closeCh:
|
case <-f.closeCh:
|
||||||
f.stop = true
|
f.stop = true
|
||||||
|
|
@ -160,7 +163,8 @@ func (f *FilterMaps) processSingleEvent(blocking bool) bool {
|
||||||
select {
|
select {
|
||||||
case target := <-f.targetCh:
|
case target := <-f.targetCh:
|
||||||
f.setTarget(target)
|
f.setTarget(target)
|
||||||
case f.matcherSyncRequest = <-f.matcherSyncCh:
|
case mb := <-f.matcherSyncCh:
|
||||||
|
f.matcherSyncRequests = append(f.matcherSyncRequests, mb)
|
||||||
case f.blockProcessing = <-f.blockProcessingCh:
|
case f.blockProcessing = <-f.blockProcessingCh:
|
||||||
case <-f.closeCh:
|
case <-f.closeCh:
|
||||||
f.stop = true
|
f.stop = true
|
||||||
|
|
|
||||||
|
|
@ -397,7 +397,9 @@ func (r *mapRenderer) writeFinishedMaps(pauseCb func() bool) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
r.f.setRange(batch, r.f.indexedView, tempRange)
|
if tempRange != r.f.indexedRange {
|
||||||
|
r.f.setRange(batch, r.f.indexedView, tempRange, true)
|
||||||
|
}
|
||||||
// add or update filter rows
|
// add or update filter rows
|
||||||
for rowIndex := uint32(0); rowIndex < r.f.mapHeight; rowIndex++ {
|
for rowIndex := uint32(0); rowIndex < r.f.mapHeight; rowIndex++ {
|
||||||
var (
|
var (
|
||||||
|
|
@ -469,7 +471,7 @@ func (r *mapRenderer) writeFinishedMaps(pauseCb func() bool) error {
|
||||||
}
|
}
|
||||||
r.finishedMaps = make(map[uint32]*renderedMap)
|
r.finishedMaps = make(map[uint32]*renderedMap)
|
||||||
r.finished.SetFirst(r.finished.AfterLast())
|
r.finished.SetFirst(r.finished.AfterLast())
|
||||||
r.f.setRange(batch, renderedView, newRange)
|
r.f.setRange(batch, renderedView, newRange, false)
|
||||||
if err := batch.Write(); err != nil {
|
if err := batch.Write(); err != nil {
|
||||||
log.Crit("Error writing log index update batch", "error", err)
|
log.Crit("Error writing log index update batch", "error", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,7 @@ func (fm *FilterMapsMatcherBackend) synced() {
|
||||||
indexedBlocks.SetAfterLast(indexedBlocks.Last()) // remove partially indexed last block
|
indexedBlocks.SetAfterLast(indexedBlocks.Last()) // remove partially indexed last block
|
||||||
}
|
}
|
||||||
fm.syncCh <- SyncRange{
|
fm.syncCh <- SyncRange{
|
||||||
HeadNumber: fm.f.indexedView.headNumber,
|
HeadNumber: fm.f.targetView.headNumber,
|
||||||
ValidBlocks: fm.validBlocks,
|
ValidBlocks: fm.validBlocks,
|
||||||
IndexedBlocks: indexedBlocks,
|
IndexedBlocks: indexedBlocks,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue