mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-10 04:51:20 +00:00
83 lines
2.4 KiB
Go
83 lines
2.4 KiB
Go
package state
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestGCReadAfterRemoveFile(t *testing.T) {
|
|
require := require.New(t)
|
|
_, db, h, txs := filledHistory(t)
|
|
collateAndMergeHistory(t, db, h, txs)
|
|
ctx := context.Background()
|
|
|
|
t.Run("read after: remove when have reader", func(t *testing.T) {
|
|
tx, err := db.BeginRo(ctx)
|
|
require.NoError(err)
|
|
defer tx.Rollback()
|
|
|
|
// - create immutable view
|
|
// - del cold file
|
|
// - read from canDelete file
|
|
// - close view
|
|
// - open new view
|
|
// - make sure there is no canDelete file
|
|
hc := h.MakeContext()
|
|
_ = hc
|
|
lastOnFs, _ := h.files.Max()
|
|
require.False(lastOnFs.frozen) // prepared dataset must have some non-frozen files. or it's bad dataset.
|
|
h.integrateMergedFiles(nil, []*filesItem{lastOnFs}, nil, nil)
|
|
require.NotNil(lastOnFs.decompressor)
|
|
|
|
lastInView := hc.historyFiles[len(hc.historyFiles)-1]
|
|
g := lastInView.src.decompressor.MakeGetter()
|
|
require.Equal(lastInView.startTxNum, lastOnFs.startTxNum)
|
|
require.Equal(lastInView.endTxNum, lastOnFs.endTxNum)
|
|
if g.HasNext() {
|
|
k, _ := g.Next(nil)
|
|
require.Equal(8, len(k))
|
|
v, _ := g.Next(nil)
|
|
require.Equal(8, len(v))
|
|
}
|
|
|
|
require.NotNil(lastOnFs.decompressor)
|
|
loc := hc.loc // replace of locality index must not affect current HistoryContext, but expect to be closed after last reader
|
|
h.localityIndex.integrateFiles(LocalityIndexFiles{}, 0, 0)
|
|
require.NotNil(loc.file)
|
|
hc.Close()
|
|
require.Nil(lastOnFs.decompressor)
|
|
require.NotNil(loc.file)
|
|
|
|
nonDeletedOnFs, _ := h.files.Max()
|
|
require.False(nonDeletedOnFs.frozen)
|
|
require.NotNil(nonDeletedOnFs.decompressor) // non-canDelete files are not closed
|
|
|
|
hc = h.MakeContext()
|
|
newLastInView := hc.historyFiles[len(hc.historyFiles)-1]
|
|
require.False(lastOnFs.frozen)
|
|
require.False(lastInView.startTxNum == newLastInView.startTxNum && lastInView.endTxNum == newLastInView.endTxNum)
|
|
|
|
hc.Close()
|
|
})
|
|
|
|
t.Run("read after: remove when no readers", func(t *testing.T) {
|
|
tx, err := db.BeginRo(ctx)
|
|
require.NoError(err)
|
|
defer tx.Rollback()
|
|
|
|
// - del cold file
|
|
// - new reader must not see canDelete file
|
|
hc := h.MakeContext()
|
|
lastOnFs, _ := h.files.Max()
|
|
require.False(lastOnFs.frozen) // prepared dataset must have some non-frozen files. or it's bad dataset.
|
|
h.integrateMergedFiles(nil, []*filesItem{lastOnFs}, nil, nil)
|
|
|
|
require.NotNil(lastOnFs.decompressor)
|
|
hc.Close()
|
|
require.Nil(lastOnFs.decompressor)
|
|
})
|
|
|
|
}
|