MCPcopy
hub / github.com/dgraph-io/badger / BenchmarkDbGrowth

Function BenchmarkDbGrowth

db_test.go:408–480  ·  view source on GitHub ↗

BenchmarkDbGrowth ensures DB does not grow with repeated adds and deletes. New keys are created with each for-loop iteration. During each iteration, the previous for-loop iteration's keys are deleted. To reproduce continous growth problem due to `badgerMove` keys, update `value.go` `discardEntry`

(b *testing.B)

Source from the content-addressed store, hash-verified

406// Also with PR #1303, the delete keys are properly cleaned which
407// further reduces disk size.
408func BenchmarkDbGrowth(b *testing.B) {
409 dir, err := ioutil.TempDir("", "badger-test")
410 require.NoError(b, err)
411 defer removeDir(dir)
412
413 start := 0
414 lastStart := 0
415 numKeys := 2000
416 valueSize := 1024
417 value := make([]byte, valueSize)
418
419 discardRatio := 0.001
420 maxWrites := 200
421 opts := getTestOptions(dir)
422 opts.ValueLogFileSize = 64 << 15
423 opts.MaxTableSize = 4 << 15
424 opts.LevelOneSize = 16 << 15
425 opts.NumVersionsToKeep = 1
426 opts.NumLevelZeroTables = 1
427 opts.NumLevelZeroTablesStall = 2
428 opts.KeepL0InMemory = false // enable L0 compaction
429 db, err := Open(opts)
430 require.NoError(b, err)
431 for numWrites := 0; numWrites < maxWrites; numWrites++ {
432 txn := db.NewTransaction(true)
433 if start > 0 {
434 for i := lastStart; i < start; i++ {
435 key := make([]byte, 8)
436 binary.BigEndian.PutUint64(key[:], uint64(i))
437 err := txn.Delete(key)
438 if err == ErrTxnTooBig {
439 require.NoError(b, txn.Commit())
440 txn = db.NewTransaction(true)
441 } else {
442 require.NoError(b, err)
443 }
444 }
445 }
446
447 for i := start; i < numKeys+start; i++ {
448 key := make([]byte, 8)
449 binary.BigEndian.PutUint64(key[:], uint64(i))
450 err := txn.SetEntry(NewEntry(key, value))
451 if err == ErrTxnTooBig {
452 require.NoError(b, txn.Commit())
453 txn = db.NewTransaction(true)
454 } else {
455 require.NoError(b, err)
456 }
457 }
458 require.NoError(b, txn.Commit())
459 require.NoError(b, db.Flatten(1))
460 for {
461 err = db.RunValueLogGC(discardRatio)
462 if err == ErrNoRewrite {
463 break
464 } else {
465 require.NoError(b, err)

Callers

nothing calls this directly

Calls 13

removeDirFunction · 0.85
getTestOptionsFunction · 0.85
OpenFunction · 0.85
NewEntryFunction · 0.85
dirSizeFunction · 0.85
NewTransactionMethod · 0.80
CommitMethod · 0.80
FlattenMethod · 0.80
RunValueLogGCMethod · 0.80
PrintfMethod · 0.80
CloseMethod · 0.65
DeleteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…