Skip to content

Commit

Permalink
Remove startJ chain of return params
Browse files Browse the repository at this point in the history
  • Loading branch information
wmitsuda committed May 31, 2024
1 parent 0c852ee commit 00d9451
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 25 deletions.
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
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

0 comments on commit 00d9451

Please sign in to comment.