|
|
@ -295,10 +295,10 @@ func (f *FilterMaps) tryUpdateTail(head *types.Header, stopFn func() bool) bool |
|
|
|
return false |
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if tailNum < tailTarget { |
|
|
|
if tailNum+f.unindexLimit <= tailTarget { |
|
|
|
f.pruneTailPtr(tailTarget) |
|
|
|
f.unindexTailPtr(tailTarget) |
|
|
|
} |
|
|
|
} |
|
|
|
return f.tryPruneTailMaps(tailTarget, stopFn) |
|
|
|
return f.tryUnindexTailMaps(tailTarget, stopFn) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// tryExtendTail attempts to extend the log index backwards until it indexes the
|
|
|
|
// tryExtendTail attempts to extend the log index backwards until it indexes the
|
|
|
@ -335,12 +335,12 @@ func (f *FilterMaps) tryExtendTail(tailTarget uint64, stopFn func() bool) bool { |
|
|
|
return number <= tailTarget |
|
|
|
return number <= tailTarget |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// pruneTailPtr updates the tail block number and hash and the corresponding
|
|
|
|
// unindexTailPtr updates the tail block number and hash and the corresponding
|
|
|
|
// tailBlockLvPointer according to the given tail target block number.
|
|
|
|
// tailBlockLvPointer according to the given tail target block number.
|
|
|
|
// Note that this function does not remove old index data, only marks it unused
|
|
|
|
// Note that this function does not remove old index data, only marks it unused
|
|
|
|
// by updating the tail pointers, except for targetLvPointer which is unchanged
|
|
|
|
// by updating the tail pointers, except for targetLvPointer which is unchanged
|
|
|
|
// as it marks the tail of the log index data stored in the database.
|
|
|
|
// as it marks the tail of the log index data stored in the database.
|
|
|
|
func (f *FilterMaps) pruneTailPtr(tailTarget uint64) { |
|
|
|
func (f *FilterMaps) unindexTailPtr(tailTarget uint64) { |
|
|
|
f.lock.Lock() |
|
|
|
f.lock.Lock() |
|
|
|
defer f.lock.Unlock() |
|
|
|
defer f.lock.Unlock() |
|
|
|
|
|
|
|
|
|
|
@ -372,9 +372,9 @@ func (f *FilterMaps) pruneTailPtr(tailTarget uint64) { |
|
|
|
f.setRange(f.db, fmr) |
|
|
|
f.setRange(f.db, fmr) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// tryPruneTailMaps removes unused filter maps and corresponding log index
|
|
|
|
// tryUnindexTailMaps removes unused filter maps and corresponding log index
|
|
|
|
// pointers from the database. This function also updates targetLvPointer.
|
|
|
|
// pointers from the database. This function also updates targetLvPointer.
|
|
|
|
func (f *FilterMaps) tryPruneTailMaps(tailTarget uint64, stopFn func() bool) bool { |
|
|
|
func (f *FilterMaps) tryUnindexTailMaps(tailTarget uint64, stopFn func() bool) bool { |
|
|
|
fmr := f.getRange() |
|
|
|
fmr := f.getRange() |
|
|
|
tailMap := uint32(fmr.tailLvPointer >> f.logValuesPerMap) |
|
|
|
tailMap := uint32(fmr.tailLvPointer >> f.logValuesPerMap) |
|
|
|
targetMap := uint32(fmr.tailBlockLvPointer >> f.logValuesPerMap) |
|
|
|
targetMap := uint32(fmr.tailBlockLvPointer >> f.logValuesPerMap) |
|
|
@ -394,11 +394,11 @@ func (f *FilterMaps) tryPruneTailMaps(tailTarget uint64, stopFn func() bool) boo |
|
|
|
for tailMap < targetMap && !stopFn() { |
|
|
|
for tailMap < targetMap && !stopFn() { |
|
|
|
tailEpoch := tailMap >> f.logMapsPerEpoch |
|
|
|
tailEpoch := tailMap >> f.logMapsPerEpoch |
|
|
|
if tailEpoch == lastEpoch { |
|
|
|
if tailEpoch == lastEpoch { |
|
|
|
f.pruneMaps(tailMap, targetMap, &removeLvPtr) |
|
|
|
f.unindexMaps(tailMap, targetMap, &removeLvPtr) |
|
|
|
break |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
nextTailMap := (tailEpoch + 1) << f.logMapsPerEpoch |
|
|
|
nextTailMap := (tailEpoch + 1) << f.logMapsPerEpoch |
|
|
|
f.pruneMaps(tailMap, nextTailMap, &removeLvPtr) |
|
|
|
f.unindexMaps(tailMap, nextTailMap, &removeLvPtr) |
|
|
|
tailMap = nextTailMap |
|
|
|
tailMap = nextTailMap |
|
|
|
if !logged || time.Since(lastLogged) >= time.Second*10 { |
|
|
|
if !logged || time.Since(lastLogged) >= time.Second*10 { |
|
|
|
log.Info("Pruning log index tail...", "filter maps left", targetMap-tailMap) |
|
|
|
log.Info("Pruning log index tail...", "filter maps left", targetMap-tailMap) |
|
|
@ -411,9 +411,9 @@ func (f *FilterMaps) tryPruneTailMaps(tailTarget uint64, stopFn func() bool) boo |
|
|
|
return tailMap >= targetMap |
|
|
|
return tailMap >= targetMap |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// pruneMaps removes filter maps and corresponding log index pointers in the
|
|
|
|
// unindexMaps removes filter maps and corresponding log index pointers in the
|
|
|
|
// specified range in a single batch.
|
|
|
|
// specified range in a single batch.
|
|
|
|
func (f *FilterMaps) pruneMaps(first, afterLast uint32, removeLvPtr *uint64) { |
|
|
|
func (f *FilterMaps) unindexMaps(first, afterLast uint32, removeLvPtr *uint64) { |
|
|
|
nextBlockNumber, err := f.getMapBlockPtr(afterLast) |
|
|
|
nextBlockNumber, err := f.getMapBlockPtr(afterLast) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Error("Error fetching next map block pointer", "map index", afterLast, "error", err) |
|
|
|
log.Error("Error fetching next map block pointer", "map index", afterLast, "error", err) |
|
|
@ -438,7 +438,7 @@ func (f *FilterMaps) pruneMaps(first, afterLast uint32, removeLvPtr *uint64) { |
|
|
|
fmr := f.getRange() |
|
|
|
fmr := f.getRange() |
|
|
|
fmr.tailLvPointer = uint64(afterLast) << f.logValuesPerMap |
|
|
|
fmr.tailLvPointer = uint64(afterLast) << f.logValuesPerMap |
|
|
|
if fmr.tailLvPointer > fmr.tailBlockLvPointer { |
|
|
|
if fmr.tailLvPointer > fmr.tailBlockLvPointer { |
|
|
|
log.Error("Cannot prune filter maps beyond tail block log value pointer", "tailLvPointer", fmr.tailLvPointer, "tailBlockLvPointer", fmr.tailBlockLvPointer) |
|
|
|
log.Error("Cannot unindex filter maps beyond tail block log value pointer", "tailLvPointer", fmr.tailLvPointer, "tailBlockLvPointer", fmr.tailBlockLvPointer) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
f.setRange(batch, fmr) |
|
|
|
f.setRange(batch, fmr) |
|
|
|