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

cleanup sstable file after tests #1912

Merged
merged 1 commit into from
Mar 22, 2023
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
7 changes: 7 additions & 0 deletions badger/cmd/pick_table_bench.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ func pickTableBench(cmd *cobra.Command, args []string) error {

boundaries := getBoundaries(db)
tables := genTables(boundaries)
defer func() {
for _, tbl := range tables {
if err := tbl.DecrRef(); err != nil {
panic(err)
}
}
}()
handler.init(tables)
keys, err = getSampleKeys(db, pickOpts.sampleSize)
y.Check(err)
Expand Down
1 change: 1 addition & 0 deletions iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func TestPickSortTables(t *testing.T) {
opts := table.Options{ChkMode: options.OnTableAndBlockRead}
tbl := buildTable(t, [][]string{{mk.small, "some value"},
{mk.large, "some value"}}, opts)
defer func() { require.NoError(t, tbl.DecrRef()) }()
out = append(out, tbl)
}
return out
Expand Down
2 changes: 2 additions & 0 deletions table/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func TestInvalidCompression(t *testing.T) {
keyPrefix := "key"
opts := Options{BlockSize: 4 << 10, Compression: options.ZSTD}
tbl := buildTestTable(t, keyPrefix, 1000, opts)
defer func() { require.NoError(t, tbl.DecrRef()) }()
mf := tbl.MmapFile
t.Run("with correct decompression algo", func(t *testing.T) {
_, err := OpenTable(mf, opts)
Expand Down Expand Up @@ -237,6 +238,7 @@ func TestBloomfilter(t *testing.T) {
opts.BloomFalsePositive = 0.01
}
tab := buildTestTable(t, keyPrefix, keyCount, opts)
defer func() { require.NoError(t, tab.DecrRef()) }()
require.Equal(t, withBlooms, tab.hasBloomFilter)
// Forward iteration
it := tab.NewIterator(0)
Expand Down
27 changes: 16 additions & 11 deletions table/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ func TestConcatIteratorOneTable(t *testing.T) {
{"k1", "a1"},
{"k2", "a2"},
}, opts)

defer func() { require.NoError(t, tbl.DecrRef()) }()

it := NewConcatIterator([]*Table{tbl}, 0)
Expand All @@ -385,10 +384,10 @@ func TestConcatIteratorOneTable(t *testing.T) {
func TestConcatIterator(t *testing.T) {
opts := getTestTableOptions()
tbl := buildTestTable(t, "keya", 10000, opts)
tbl2 := buildTestTable(t, "keyb", 10000, opts)
tbl3 := buildTestTable(t, "keyc", 10000, opts)
defer func() { require.NoError(t, tbl.DecrRef()) }()
tbl2 := buildTestTable(t, "keyb", 10000, opts)
defer func() { require.NoError(t, tbl2.DecrRef()) }()
tbl3 := buildTestTable(t, "keyc", 10000, opts)
defer func() { require.NoError(t, tbl3.DecrRef()) }()

{
Expand Down Expand Up @@ -464,11 +463,14 @@ func TestMergingIterator(t *testing.T) {
{"k4", "a4"},
{"k5", "a5"},
}, opts)
defer func() { require.NoError(t, tbl1.DecrRef()) }()

tbl2 := buildTable(t, [][]string{
{"k2", "b2"},
{"k3", "b3"},
{"k4", "b4"},
}, opts)
defer func() { require.NoError(t, tbl2.DecrRef()) }()

expected := []struct {
key string
Expand All @@ -480,8 +482,7 @@ func TestMergingIterator(t *testing.T) {
{"k4", "a4"},
{"k5", "a5"},
}
defer func() { require.NoError(t, tbl1.DecrRef()) }()
defer func() { require.NoError(t, tbl2.DecrRef()) }()

it1 := tbl1.NewIterator(0)
it2 := NewConcatIterator([]*Table{tbl2}, 0)
it := NewMergeIterator([]y.Iterator{it1, it2}, false)
Expand All @@ -508,12 +509,15 @@ func TestMergingIteratorReversed(t *testing.T) {
{"k4", "a4"},
{"k5", "a5"},
}, opts)
defer func() { require.NoError(t, tbl1.DecrRef()) }()

tbl2 := buildTable(t, [][]string{
{"k1", "b2"},
{"k3", "b3"},
{"k4", "b4"},
{"k5", "b5"},
}, opts)
defer func() { require.NoError(t, tbl2.DecrRef()) }()

expected := []struct {
key string
Expand All @@ -525,8 +529,7 @@ func TestMergingIteratorReversed(t *testing.T) {
{"k2", "a2"},
{"k1", "a1"},
}
defer func() { require.NoError(t, tbl1.DecrRef()) }()
defer func() { require.NoError(t, tbl2.DecrRef()) }()

it1 := tbl1.NewIterator(REVERSED)
it2 := NewConcatIterator([]*Table{tbl2}, REVERSED)
it := NewMergeIterator([]y.Iterator{it1, it2}, true)
Expand All @@ -553,9 +556,8 @@ func TestMergingIteratorTakeOne(t *testing.T) {
{"k1", "a1"},
{"k2", "a2"},
}, opts)
t2 := buildTable(t, [][]string{{"l1", "b1"}}, opts)

defer func() { require.NoError(t, t1.DecrRef()) }()
t2 := buildTable(t, [][]string{{"l1", "b1"}}, opts)
defer func() { require.NoError(t, t2.DecrRef()) }()

it1 := NewConcatIterator([]*Table{t1}, 0)
Expand Down Expand Up @@ -594,12 +596,12 @@ func TestMergingIteratorTakeOne(t *testing.T) {
func TestMergingIteratorTakeTwo(t *testing.T) {
opts := getTestTableOptions()
t1 := buildTable(t, [][]string{{"l1", "b1"}}, opts)
defer func() { require.NoError(t, t1.DecrRef()) }()

t2 := buildTable(t, [][]string{
{"k1", "a1"},
{"k2", "a2"},
}, opts)

defer func() { require.NoError(t, t1.DecrRef()) }()
defer func() { require.NoError(t, t2.DecrRef()) }()

it1 := NewConcatIterator([]*Table{t1}, 0)
Expand Down Expand Up @@ -681,6 +683,7 @@ func TestTableChecksum(t *testing.T) {
opts := getTestTableOptions()
opts.ChkMode = options.OnTableAndBlockRead
tbl := buildTestTable(t, "k", 10000, opts)
defer func() { require.NoError(t, tbl.DecrRef()) }()
// Write random bytes at random location.
start := rand.Intn(len(tbl.Data) - len(rb))
n := copy(tbl.Data[start:], rb)
Expand All @@ -691,6 +694,8 @@ func TestTableChecksum(t *testing.T) {
_, err := OpenTable(tbl.MmapFile, opts)
if strings.Contains(err.Error(), "checksum") {
panic("checksum mismatch")
} else {
require.NoError(t, err)
}
})
}
Expand Down