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

Increase default valueThreshold from 32B to 1KB #1346

Merged
merged 15 commits into from
Jun 24, 2020
6 changes: 5 additions & 1 deletion batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ func TestWriteBatch(t *testing.T) {
require.NoError(t, err)
}
t.Run("disk mode", func(t *testing.T) {
runBadgerTest(t, nil, func(t *testing.T, db *DB) {
opt := getTestOptions("")
// Set value threshold to 32 bytes otherwise write batch will generate
// too many files and we will crash with too many files open error.
opt.ValueThreshold = 32
runBadgerTest(t, &opt, func(t *testing.T, db *DB) {
test(t, db)
})
})
Expand Down
7 changes: 1 addition & 6 deletions db2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ func TestTruncateVlogNoClose(t *testing.T) {
t.Skip("Skipping test meant to be run manually.")
return
}
fmt.Println("running")
dir := "p"
opts := getTestOptions(dir)
opts.SyncWrites = true
Expand Down Expand Up @@ -707,8 +706,8 @@ func TestWindowsDataLoss(t *testing.T) {
defer removeDir(dir)

opt := DefaultOptions(dir).WithSyncWrites(true)
opt.ValueThreshold = 32

fmt.Println("First DB Open")
db, err := Open(opt)
require.NoError(t, err)
keyCount := 20
Expand All @@ -730,8 +729,6 @@ func TestWindowsDataLoss(t *testing.T) {
}
require.NoError(t, db.Close())

fmt.Println()
fmt.Println("Second DB Open")
opt.Truncate = true
db, err = Open(opt)
require.NoError(t, err)
Expand All @@ -753,8 +750,6 @@ func TestWindowsDataLoss(t *testing.T) {
require.NoError(t, db.manifest.close())
require.NoError(t, db.lc.close())

fmt.Println()
fmt.Println("Third DB Open")
opt.Truncate = true
db, err = Open(opt)
require.NoError(t, err)
Expand Down
1 change: 1 addition & 0 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1987,6 +1987,7 @@ func TestNoCrash(t *testing.T) {

ops := getTestOptions(dir)
ops.ValueLogMaxEntries = 1
ops.ValueThreshold = 32
db, err := Open(ops)
require.NoError(t, err, "unable to open db")

Expand Down
2 changes: 1 addition & 1 deletion managed_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ func TestWriteBatchManagedMode(t *testing.T) {
}
opt := DefaultOptions("")
opt.managedTxns = true
opt.MaxTableSize = 1 << 15 // This would create multiple transactions in write batch.
opt.MaxTableSize = 1 << 20 // This would create multiple transactions in write batch.
runBadgerTest(t, &opt, func(t *testing.T, db *DB) {
wb := db.NewWriteBatchAt(1)
defer wb.Cancel()
Expand Down
4 changes: 2 additions & 2 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func DefaultOptions(path string) Options {
ValueLogFileSize: 1<<30 - 1,

ValueLogMaxEntries: 1000000,
ValueThreshold: 32,
ValueThreshold: 1 << 10, // 1 KB.
Truncate: false,
Logger: defaultLogger(INFO),
LogRotatesToFlush: 2,
Expand Down Expand Up @@ -357,7 +357,7 @@ func (opt Options) WithMaxLevels(val int) Options {
// ValueThreshold sets the threshold used to decide whether a value is stored directly in the LSM
// tree or separately in the log value files.
//
// The default value of ValueThreshold is 32, but LSMOnlyOptions sets it to maxValueThreshold.
// The default value of ValueThreshold is 1 KB, but LSMOnlyOptions sets it to maxValueThreshold.
func (opt Options) WithValueThreshold(val int) Options {
opt.ValueThreshold = val
return opt
Expand Down
3 changes: 3 additions & 0 deletions table/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ func (b *Builder) addHelper(key []byte, v y.ValueStruct, vpLen uint64) {
diffKey = b.keyDiff(key)
}

y.AssertTrue(len(key)-len(diffKey) <= math.MaxUint16)
y.AssertTrue(len(diffKey) <= math.MaxUint16)

h := header{
overlap: uint16(len(key) - len(diffKey)),
diff: uint16(len(diffKey)),
Expand Down
8 changes: 6 additions & 2 deletions value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestValueBasic(t *testing.T) {
y.Check(err)
defer removeDir(dir)

kv, _ := Open(getTestOptions(dir))
kv, _ := Open(getTestOptions(dir).WithValueThreshold(32))
defer kv.Close()
log := &kv.vlog

Expand Down Expand Up @@ -472,7 +472,7 @@ func TestPersistLFDiscardStats(t *testing.T) {
require.NoError(t, err)
}

time.Sleep(1 * time.Second) // wait for compaction to complete
time.Sleep(2 * time.Second) // wait for compaction to complete

persistedMap := make(map[uint32]int64)
db.vlog.lfDiscardStats.Lock()
Expand Down Expand Up @@ -509,6 +509,7 @@ func TestChecksums(t *testing.T) {
opts := getTestOptions(dir)
opts.Truncate = true
opts.ValueLogFileSize = 100 * 1024 * 1024 // 100Mb
opts.ValueThreshold = 32
kv, err := Open(opts)
require.NoError(t, err)
require.NoError(t, kv.Close())
Expand Down Expand Up @@ -592,6 +593,7 @@ func TestPartialAppendToValueLog(t *testing.T) {
opts := getTestOptions(dir)
opts.Truncate = true
opts.ValueLogFileSize = 100 * 1024 * 1024 // 100Mb
opts.ValueThreshold = 32
kv, err := Open(opts)
require.NoError(t, err)
require.NoError(t, kv.Close())
Expand Down Expand Up @@ -1167,6 +1169,7 @@ func TestValueEntryChecksum(t *testing.T) {

opt := getTestOptions(dir)
opt.VerifyValueChecksum = true
opt.ValueThreshold = 32
db, err := Open(opt)
require.NoError(t, err)

Expand Down Expand Up @@ -1195,6 +1198,7 @@ func TestValueEntryChecksum(t *testing.T) {

opt := getTestOptions(dir)
opt.VerifyValueChecksum = true
opt.ValueThreshold = 32
db, err := Open(opt)
require.NoError(t, err)

Expand Down