From 98b51356d97cbe6a5331873fa4ba9c1d2380dd38 Mon Sep 17 00:00:00 2001 From: Naman Jain Date: Tue, 28 Sep 2021 22:57:25 +0530 Subject: [PATCH] fix(compact): close vlog after the compaction at L0 has completed (#1752) Vlog needs to stay open while the compaction is being run. With the CompactL0OnClose option, it becomes necessary to close the vlog after all the compactions have been completed. --- db_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/db_test.go b/db_test.go index 4a8fcfaf2..f3e13092f 100644 --- a/db_test.go +++ b/db_test.go @@ -2635,3 +2635,32 @@ func TestCompactL0OnClose(t *testing.T) { } }) } + +func TestCompactL0OnClose(t *testing.T) { + opt := getTestOptions("") + opt.CompactL0OnClose = true + opt.ValueThreshold = 1 // Every value goes to value log + opt.NumVersionsToKeep = 1 + runBadgerTest(t, &opt, func(t *testing.T, db *DB) { + var keys [][]byte + val := make([]byte, 1<<12) + for i := 0; i < 10; i++ { + key := make([]byte, 40) + _, err := rand.Read(key) + require.NoError(t, err) + keys = append(keys, key) + + err = db.Update(func(txn *Txn) error { + return txn.SetEntry(NewEntry(key, val)) + }) + require.NoError(t, err) + } + + for _, key := range keys { + err := db.Update(func(txn *Txn) error { + return txn.SetEntry(NewEntry(key, val)) + }) + require.NoError(t, err) + } + }) +}