Skip to content

Commit 5ff6b6f

Browse files
committed
Introduce new LSMOnlyOptions, to make Badger act like a typical LSM tree.
1 parent e1ead00 commit 5ff6b6f

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

db_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,6 +1607,36 @@ func TestReadOnly(t *testing.T) {
16071607
require.NoError(t, err)
16081608
}
16091609

1610+
func TestLSMOnly(t *testing.T) {
1611+
dir, err := ioutil.TempDir("", "badger")
1612+
require.NoError(t, err)
1613+
defer os.RemoveAll(dir)
1614+
1615+
opts := LSMOnlyOptions
1616+
opts.Dir = dir
1617+
opts.ValueDir = dir
1618+
1619+
dopts := DefaultOptions
1620+
require.NotEqual(t, dopts.ValueThreshold, opts.ValueThreshold)
1621+
require.NotEqual(t, dopts.ValueLogLoadingMode, opts.ValueLogLoadingMode)
1622+
require.NotEqual(t, dopts.ValueLogFileSize, opts.ValueLogFileSize)
1623+
1624+
db, err := Open(opts)
1625+
if err != nil {
1626+
t.Fatal(err)
1627+
}
1628+
defer db.Close()
1629+
1630+
for i := 0; i < 5000; i++ {
1631+
value := make([]byte, 64000)
1632+
_, err = rand.Read(value)
1633+
require.NoError(t, err)
1634+
1635+
txnSet(t, db, []byte(fmt.Sprintf("key%d", i)), value, 0x00)
1636+
}
1637+
require.NoError(t, db.RunValueLogGC(0.2))
1638+
}
1639+
16101640
func ExampleOpen() {
16111641
dir, err := ioutil.TempDir("", "badger")
16121642
if err != nil {

options.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,18 @@ var DefaultOptions = Options{
120120
ValueThreshold: 20,
121121
Truncate: false,
122122
}
123+
124+
// LSMOnlyOptions follows from DefaultOptions, but sets a higher ValueThreshold so values would
125+
// be colocated with the LSM tree, with value log largely acting as a write-ahead log only. These
126+
// options would reduce the disk usage of value log, and make Badger act like a typical LSM tree.
127+
var LSMOnlyOptions = Options{}
128+
129+
func init() {
130+
LSMOnlyOptions = DefaultOptions
131+
132+
// TODO: Once we switch Skiplist code to store uint32 value sizes, we can increase this.
133+
// But for now, ensure that the value length fits in uint16.
134+
LSMOnlyOptions.ValueThreshold = 65001
135+
LSMOnlyOptions.ValueLogFileSize = 64 << 20 // Allow easy space reclamation.
136+
LSMOnlyOptions.ValueLogLoadingMode = options.FileIO
137+
}

0 commit comments

Comments
 (0)