Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove startJ chain of return params #10569

Merged
merged 1 commit into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions erigon-lib/state/aggregator_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ type SelectedStaticFilesV3 struct {
d [kv.DomainLen][]*filesItem
dHist [kv.DomainLen][]*filesItem
dIdx [kv.DomainLen][]*filesItem
dI [kv.DomainLen]int
ii [kv.StandaloneIdxLen][]*filesItem
}

Expand Down Expand Up @@ -59,12 +58,12 @@ func (sf SelectedStaticFilesV3) Close() {
func (ac *AggregatorRoTx) staticFilesInRange(r RangesV3) (sf SelectedStaticFilesV3, err error) {
for id := range ac.d {
if r.d[id].any() {
sf.d[id], sf.dIdx[id], sf.dHist[id], sf.dI[id] = ac.d[id].staticFilesInRange(r.d[id])
sf.d[id], sf.dIdx[id], sf.dHist[id] = ac.d[id].staticFilesInRange(r.d[id])
}
}
for id, rng := range r.ranges {
if rng != nil && rng.needMerge {
fi, _ := ac.iis[id].staticFilesInRange(rng.from, rng.to)
fi := ac.iis[id].staticFilesInRange(rng.from, rng.to)
sf.ii[id] = fi
}
}
Expand Down
6 changes: 3 additions & 3 deletions erigon-lib/state/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ func collateAndMerge(t *testing.T, db kv.RwDB, tx kv.RwTx, d *Domain, txs uint64
if !r.any() {
return true
}
valuesOuts, indexOuts, historyOuts, _ := dc.staticFilesInRange(r)
valuesOuts, indexOuts, historyOuts := dc.staticFilesInRange(r)
valuesIn, indexIn, historyIn, err := dc.mergeFiles(ctx, valuesOuts, indexOuts, historyOuts, r, nil, background.NewProgressSet())
require.NoError(t, err)
if valuesIn != nil && valuesIn.decompressor != nil {
Expand Down Expand Up @@ -709,7 +709,7 @@ func collateAndMergeOnce(t *testing.T, d *Domain, tx kv.RwTx, step uint64, prune
dc.Close()
break
}
valuesOuts, indexOuts, historyOuts, _ := dc.staticFilesInRange(r)
valuesOuts, indexOuts, historyOuts := dc.staticFilesInRange(r)
valuesIn, indexIn, historyIn, err := dc.mergeFiles(ctx, valuesOuts, indexOuts, historyOuts, r, nil, background.NewProgressSet())
require.NoError(t, err)

Expand Down Expand Up @@ -1406,7 +1406,7 @@ func TestDomainContext_getFromFiles(t *testing.T) {
require.NoError(t, err)

ranges := dc.findMergeRange(txFrom, txTo)
vl, il, hl, _ := dc.staticFilesInRange(ranges)
vl, il, hl := dc.staticFilesInRange(ranges)

dv, di, dh, err := dc.mergeFiles(ctx, vl, il, hl, ranges, nil, ps)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion erigon-lib/state/history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ func collateAndMergeHistory(tb testing.TB, db kv.RwDB, h *History, txs uint64, d
if !r.any() {
return true
}
indexOuts, historyOuts, _, err := hc.staticFilesInRange(r)
indexOuts, historyOuts, err := hc.staticFilesInRange(r)
require.NoError(err)
indexIn, historyIn, err := hc.mergeFiles(ctx, indexOuts, historyOuts, r, background.NewProgressSet())
require.NoError(err)
Expand Down
2 changes: 1 addition & 1 deletion erigon-lib/state/inverted_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ func mergeInverted(tb testing.TB, db kv.RwDB, ii *InvertedIndex, txs uint64) {
if !found {
return true
}
outs, _ := ic.staticFilesInRange(startTxNum, endTxNum)
outs := ic.staticFilesInRange(startTxNum, endTxNum)
in, err := ic.mergeFiles(ctx, outs, startTxNum, endTxNum, background.NewProgressSet())
require.NoError(tb, err)
ii.integrateMergedDirtyFiles(outs, in)
Expand Down
21 changes: 8 additions & 13 deletions erigon-lib/state/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,10 @@ func (iit *InvertedIndexRoTx) maxTxNumInFiles(onlyFrozen bool) uint64 {

// staticFilesInRange returns list of static files with txNum in specified range [startTxNum; endTxNum)
// files are in the descending order of endTxNum
func (dt *DomainRoTx) staticFilesInRange(r DomainRanges) (valuesFiles, indexFiles, historyFiles []*filesItem, startJ int) {
func (dt *DomainRoTx) staticFilesInRange(r DomainRanges) (valuesFiles, indexFiles, historyFiles []*filesItem) {
if r.index || r.history {
var err error
indexFiles, historyFiles, startJ, err = dt.ht.staticFilesInRange(HistoryRanges{
indexFiles, historyFiles, err = dt.ht.staticFilesInRange(HistoryRanges{
historyStartTxNum: r.historyStartTxNum,
historyEndTxNum: r.historyEndTxNum,
history: r.history,
Expand All @@ -367,7 +367,6 @@ func (dt *DomainRoTx) staticFilesInRange(r DomainRanges) (valuesFiles, indexFile
if r.values {
for _, item := range dt.files {
if item.startTxNum < r.valuesStartTxNum {
startJ++
continue
}
if item.endTxNum > r.valuesEndTxNum {
Expand All @@ -384,13 +383,11 @@ func (dt *DomainRoTx) staticFilesInRange(r DomainRanges) (valuesFiles, indexFile
return
}

func (iit *InvertedIndexRoTx) staticFilesInRange(startTxNum, endTxNum uint64) ([]*filesItem, int) {
func (iit *InvertedIndexRoTx) staticFilesInRange(startTxNum, endTxNum uint64) []*filesItem {
files := make([]*filesItem, 0, len(iit.files))
var startJ int

for _, item := range iit.files {
if item.startTxNum < startTxNum {
startJ++
continue
}
if item.endTxNum > endTxNum {
Expand All @@ -404,27 +401,25 @@ func (iit *InvertedIndexRoTx) staticFilesInRange(startTxNum, endTxNum uint64) ([
}
}

return files, startJ
return files
}

// nolint
func (ii *InvertedIndex) staticFilesInRange(startTxNum, endTxNum uint64, ic *InvertedIndexRoTx) ([]*filesItem, int) {
panic("deprecated: use InvertedIndexRoTx.staticFilesInRange")
}

func (ht *HistoryRoTx) staticFilesInRange(r HistoryRanges) (indexFiles, historyFiles []*filesItem, startJ int, err error) {
func (ht *HistoryRoTx) staticFilesInRange(r HistoryRanges) (indexFiles, historyFiles []*filesItem, err error) {
if !r.history && r.index {
indexFiles, startJ = ht.iit.staticFilesInRange(r.indexStartTxNum, r.indexEndTxNum)
return indexFiles, historyFiles, startJ, nil
indexFiles = ht.iit.staticFilesInRange(r.indexStartTxNum, r.indexEndTxNum)
return indexFiles, historyFiles, nil
}

if r.history {
// Get history files from HistoryRoTx (no "garbage/overalps"), but index files not from InvertedIndexRoTx
// because index files may already be merged (before `kill -9`) and it means not visible in InvertedIndexRoTx
startJ = 0
for _, item := range ht.files {
if item.startTxNum < r.historyStartTxNum {
startJ++
continue
}
if item.endTxNum > r.historyEndTxNum {
Expand All @@ -437,7 +432,7 @@ func (ht *HistoryRoTx) staticFilesInRange(r HistoryRanges) (indexFiles, historyF
indexFiles = append(indexFiles, idxFile)
} else {
walkErr := fmt.Errorf("History.staticFilesInRange: required file not found: v1-%s.%d-%d.efi", ht.h.filenameBase, item.startTxNum/ht.h.aggregationStep, item.endTxNum/ht.h.aggregationStep)
return nil, nil, 0, walkErr
return nil, nil, walkErr
}
}

Expand Down
14 changes: 7 additions & 7 deletions erigon-lib/state/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestFindMergeRangeCornerCases(t *testing.T) {
assert.Equal(t, 0, int(mr.from))
assert.Equal(t, 4, int(mr.to))

idxF, _ := ic.staticFilesInRange(mr.from, mr.to)
idxF := ic.staticFilesInRange(mr.from, mr.to)
assert.Equal(t, 3, len(idxF))

ii = emptyTestInvertedIndex(1)
Expand Down Expand Up @@ -199,7 +199,7 @@ func TestFindMergeRangeCornerCases(t *testing.T) {
assert.False(t, r.index)
assert.True(t, r.history)
assert.Equal(t, 2, int(r.historyEndTxNum))
idxFiles, histFiles, _, err := hc.staticFilesInRange(r)
idxFiles, histFiles, err := hc.staticFilesInRange(r)
require.NoError(t, err)
require.Equal(t, 2, len(idxFiles))
require.Equal(t, 2, len(histFiles))
Expand Down Expand Up @@ -237,7 +237,7 @@ func TestFindMergeRangeCornerCases(t *testing.T) {
assert.False(t, r.index)
assert.True(t, r.history)
assert.Equal(t, 2, int(r.historyEndTxNum))
_, _, _, err := hc.staticFilesInRange(r)
_, _, err := hc.staticFilesInRange(r)
require.Error(t, err)
})

Expand Down Expand Up @@ -275,7 +275,7 @@ func TestFindMergeRangeCornerCases(t *testing.T) {
assert.True(t, r.index)
assert.False(t, r.history)
assert.Equal(t, uint64(2), r.indexEndTxNum)
idxFiles, histFiles, _, err := hc.staticFilesInRange(r)
idxFiles, histFiles, err := hc.staticFilesInRange(r)
require.NoError(t, err)
require.Equal(t, 2, len(idxFiles))
require.Equal(t, 0, len(histFiles))
Expand Down Expand Up @@ -318,7 +318,7 @@ func TestFindMergeRangeCornerCases(t *testing.T) {
assert.True(t, r.index)
assert.True(t, r.history)
assert.Equal(t, 4, int(r.indexEndTxNum))
idxFiles, histFiles, _, err := hc.staticFilesInRange(r)
idxFiles, histFiles, err := hc.staticFilesInRange(r)
require.NoError(t, err)
require.Equal(t, 3, len(idxFiles))
require.Equal(t, 3, len(histFiles))
Expand Down Expand Up @@ -358,7 +358,7 @@ func TestFindMergeRangeCornerCases(t *testing.T) {
assert.False(t, r.index)
assert.True(t, r.history)
assert.Equal(t, 2, int(r.historyEndTxNum))
idxFiles, histFiles, _, err := hc.staticFilesInRange(r)
idxFiles, histFiles, err := hc.staticFilesInRange(r)
require.NoError(t, err)
require.Equal(t, 2, len(idxFiles))
require.Equal(t, 2, len(histFiles))
Expand Down Expand Up @@ -418,7 +418,7 @@ func TestFindMergeRangeCornerCases(t *testing.T) {
assert.True(t, mr.needMerge)
require.Equal(t, 0, int(mr.from))
require.Equal(t, 4, int(mr.to))
idxFiles, _ := ic.staticFilesInRange(mr.from, mr.to)
idxFiles := ic.staticFilesInRange(mr.from, mr.to)
require.Equal(t, 3, len(idxFiles))
})
}
Expand Down
Loading