Skip to content

Commit 4cfebae

Browse files
authored
Merge pull request #2338 from CortexFoundation/dev
clone cached slices, fix tempRange
2 parents 85965bd + 665480f commit 4cfebae

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

core/filtermaps/filtermaps.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ type FilterMaps struct {
128128

129129
// test hooks
130130
testDisableSnapshots, testSnapshotUsed bool
131+
testProcessEventsHook func()
131132
}
132133

133134
// filterMap is a full or partial in-memory representation of a filter map where
@@ -573,7 +574,7 @@ func (f *FilterMaps) getFilterMapRow(mapIndex, rowIndex uint32, baseLayerOnly bo
573574
}
574575
f.baseRowsCache.Add(baseMapRowIndex, baseRows)
575576
}
576-
baseRow := baseRows[mapIndex&(f.baseRowGroupLength-1)]
577+
baseRow := slices.Clone(baseRows[mapIndex&(f.baseRowGroupLength-1)])
577578
if baseLayerOnly {
578579
return baseRow, nil
579580
}
@@ -610,7 +611,9 @@ func (f *FilterMaps) storeFilterMapRowsOfGroup(batch ctxcdb.Batch, mapIndices []
610611
if uint32(len(mapIndices)) != f.baseRowGroupLength { // skip base rows read if all rows are replaced
611612
var ok bool
612613
baseRows, ok = f.baseRowsCache.Get(baseMapRowIndex)
613-
if !ok {
614+
if ok {
615+
baseRows = slices.Clone(baseRows)
616+
} else {
614617
var err error
615618
baseRows, err = rawdb.ReadFilterMapBaseRows(f.db, baseMapRowIndex, f.baseRowGroupLength, f.logMapWidth)
616619
if err != nil {
@@ -656,7 +659,7 @@ func (f *FilterMaps) mapRowIndex(mapIndex, rowIndex uint32) uint64 {
656659
// called from outside the indexerLoop goroutine.
657660
func (f *FilterMaps) getBlockLvPointer(blockNumber uint64) (uint64, error) {
658661
if blockNumber >= f.indexedRange.blocks.AfterLast() && f.indexedRange.headIndexed {
659-
return f.indexedRange.headDelimiter, nil
662+
return f.indexedRange.headDelimiter + 1, nil
660663
}
661664
if lvPointer, ok := f.lvPointerCache.Get(blockNumber); ok {
662665
return lvPointer, nil

core/filtermaps/indexer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ func (f *FilterMaps) waitForNewHead() {
165165
// processEvents processes all events, blocking only if a block processing is
166166
// happening and indexing should be suspended.
167167
func (f *FilterMaps) processEvents() {
168+
if f.testProcessEventsHook != nil {
169+
f.testProcessEventsHook()
170+
}
168171
for f.processSingleEvent(f.blockProcessing) {
169172
}
170173
}

core/filtermaps/map_renderer.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"errors"
2121
"fmt"
2222
"math"
23+
"slices"
2324
"sort"
2425
"time"
2526

@@ -107,7 +108,7 @@ func (f *FilterMaps) renderMapsFromSnapshot(cp *renderedMap) (*mapRenderer, erro
107108
filterMap: cp.filterMap.fullCopy(),
108109
mapIndex: cp.mapIndex,
109110
lastBlock: cp.lastBlock,
110-
blockLvPtrs: cp.blockLvPtrs,
111+
blockLvPtrs: slices.Clone(cp.blockLvPtrs),
111112
},
112113
finishedMaps: make(map[uint32]*renderedMap),
113114
finished: common.NewRange(cp.mapIndex, 0),
@@ -244,7 +245,7 @@ func (f *FilterMaps) loadHeadSnapshot() error {
244245
}
245246
}
246247
f.renderSnapshots.Add(f.indexedRange.blocks.Last(), &renderedMap{
247-
filterMap: fm,
248+
filterMap: fm.fullCopy(),
248249
mapIndex: f.indexedRange.maps.Last(),
249250
lastBlock: f.indexedRange.blocks.Last(),
250251
lastBlockId: f.indexedView.BlockId(f.indexedRange.blocks.Last()),
@@ -536,6 +537,7 @@ func (r *mapRenderer) getTempRange() (filterMapsRange, error) {
536537
} else {
537538
tempRange.blocks.SetAfterLast(0)
538539
}
540+
tempRange.headIndexed = false
539541
tempRange.headDelimiter = 0
540542
}
541543
return tempRange, nil

0 commit comments

Comments
 (0)