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

Function TestDropPrefixMoveBug

levels_test.go:783–820  ·  view source on GitHub ↗

Regression test for https://github.com/dgraph-io/dgraph/issues/5573

(t *testing.T)

Source from the content-addressed store, hash-verified

781
782// Regression test for https://github.com/dgraph-io/dgraph/issues/5573
783func TestDropPrefixMoveBug(t *testing.T) {
784 runBadgerTest(t, nil, func(t *testing.T, db *DB) {
785 // l1 is used to verify that drop prefix actually drops move keys from all the levels.
786 l1 := []keyValVersion{{string(append(badgerMove, "F"...)), "", 0, 0}}
787 createAndOpen(db, l1, 1)
788
789 // Mutiple levels can have the exact same move key with version.
790 l2 := []keyValVersion{{string(append(badgerMove, "F"...)), "", 0, 0}, {"A", "", 0, 0}}
791 l21 := []keyValVersion{{"B", "", 0, 0}, {"C", "", 0, 0}}
792 l22 := []keyValVersion{{"F", "", 0, 0}, {"G", "", 0, 0}}
793
794 // Level 2 has all the tables.
795 createAndOpen(db, l2, 2)
796 createAndOpen(db, l21, 2)
797 createAndOpen(db, l22, 2)
798
799 require.NoError(t, db.lc.validate())
800 require.NoError(t, db.DropPrefix([]byte("F")))
801
802 db.View(func(txn *Txn) error {
803 iopt := DefaultIteratorOptions
804 iopt.AllVersions = true
805
806 it := txn.NewIterator(iopt)
807 defer it.Close()
808
809 specialKey := []byte("F")
810 droppedPrefixes := [][]byte{specialKey, append(badgerMove, specialKey...)}
811 for it.Rewind(); it.Valid(); it.Next() {
812 key := it.Item().Key()
813 // Ensure we don't have any "F" or "!badger!move!F" left
814 require.False(t, hasAnyPrefixes(key, droppedPrefixes))
815 }
816 return nil
817 })
818 require.NoError(t, db.lc.validate())
819 })
820}

Callers

nothing calls this directly

Calls 13

CloseMethod · 0.95
RewindMethod · 0.95
ValidMethod · 0.95
NextMethod · 0.95
ItemMethod · 0.95
runBadgerTestFunction · 0.85
createAndOpenFunction · 0.85
hasAnyPrefixesFunction · 0.85
DropPrefixMethod · 0.80
ViewMethod · 0.80
KeyMethod · 0.65
validateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…