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

Function TestDiscardFirstVersion

levels_test.go:598–647  ·  view source on GitHub ↗

This is a test to ensure that the first entry with DiscardEarlierversion bit < DiscardTs is kept around (when numversionstokeep is infinite).

(t *testing.T)

Source from the content-addressed store, hash-verified

596// This is a test to ensure that the first entry with DiscardEarlierversion bit < DiscardTs
597// is kept around (when numversionstokeep is infinite).
598func TestDiscardFirstVersion(t *testing.T) {
599 opt := DefaultOptions("")
600 opt.NumCompactors = 0
601 opt.NumVersionsToKeep = math.MaxInt32
602 opt.managedTxns = true
603
604 runBadgerTest(t, &opt, func(t *testing.T, db *DB) {
605 l0 := []keyValVersion{{"foo", "bar", 1, 0}}
606 l01 := []keyValVersion{{"foo", "bar", 2, bitDiscardEarlierVersions}}
607 l02 := []keyValVersion{{"foo", "bar", 3, 0}}
608 l03 := []keyValVersion{{"foo", "bar", 4, 0}}
609 l04 := []keyValVersion{{"foo", "bar", 9, 0}}
610 l05 := []keyValVersion{{"foo", "bar", 10, bitDiscardEarlierVersions}}
611
612 // Level 0 has all the tables.
613 createAndOpen(db, l0, 0)
614 createAndOpen(db, l01, 0)
615 createAndOpen(db, l02, 0)
616 createAndOpen(db, l03, 0)
617 createAndOpen(db, l04, 0)
618 createAndOpen(db, l05, 0)
619
620 // Discard Time stamp is set to 7.
621 db.SetDiscardTs(7)
622
623 // Compact L0 to L1
624 cdef := compactDef{
625 thisLevel: db.lc.levels[0],
626 nextLevel: db.lc.levels[1],
627 top: db.lc.levels[0].tables,
628 bot: db.lc.levels[1].tables,
629 }
630 require.NoError(t, db.lc.runCompactDef(0, cdef))
631
632 // - Version 10, 9 lie above version 7 so they should be there.
633 // - Version 4, 3, 2 lie below the discardTs but they don't have the
634 // "bitDiscardEarlierVersions" versions set so they should not be removed because number
635 // of versions to keep is set to infinite.
636 // - Version 1 is below DiscardTS and below the first "bitDiscardEarlierVersions"
637 // marker so IT WILL BE REMOVED.
638 ExpectedKeys := []keyValVersion{
639 {"foo", "bar", 10, bitDiscardEarlierVersions},
640 {"foo", "bar", 9, 0},
641 {"foo", "bar", 4, 0},
642 {"foo", "bar", 3, 0},
643 {"foo", "bar", 2, bitDiscardEarlierVersions}}
644
645 getAllAndCheck(t, db, ExpectedKeys)
646 })
647}
648
649// This test ensures we don't stall when L1's size is greater than opt.LevelOneSize.
650// We should stall only when L0 tables more than the opt.NumLevelZeroTableStall.

Callers

nothing calls this directly

Calls 6

DefaultOptionsFunction · 0.85
runBadgerTestFunction · 0.85
createAndOpenFunction · 0.85
getAllAndCheckFunction · 0.85
SetDiscardTsMethod · 0.80
runCompactDefMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…