MCPcopy
hub / github.com/dgraph-io/dgraph / VerifySnapshot

Function VerifySnapshot

x/debug.go:48–103  ·  view source on GitHub ↗

VerifySnapshot iterates over all the keys in badger. For all data keys it checks if key is a split key and it verifies if all part are present in badger as well.

(pstore *badger.DB, readTs uint64)

Source from the content-addressed store, hash-verified

46// VerifySnapshot iterates over all the keys in badger. For all data keys it checks
47// if key is a split key and it verifies if all part are present in badger as well.
48func VerifySnapshot(pstore *badger.DB, readTs uint64) {
49 stream := pstore.NewStreamAt(readTs)
50 stream.KeyToList = func(key []byte, itr *badger.Iterator) (*bpb.KVList, error) {
51 for ; itr.Valid(); itr.Next() {
52 item := itr.Item()
53 if item.IsDeletedOrExpired() {
54 break
55 }
56 if !bytes.Equal(key, item.Key()) {
57 // Break out on the first encounter with another key.
58 break
59 }
60
61 k := item.Key()
62 parsedKey, kErr := Parse(k)
63 Checkf(kErr, "Error parsing key: %v, version: %d", k, item.Version())
64 if !parsedKey.IsData() {
65 continue
66 }
67
68 err := item.Value(func(v []byte) error {
69 plist := &pb.PostingList{}
70 Check(proto.Unmarshal(v, plist))
71 VerifyPack(plist)
72 if len(plist.Splits) == 0 {
73 return nil
74 }
75 if plist.Splits[0] != uint64(1) {
76 log.Panic("First split UID is not 1 baseKey: ", k,
77 " version ", item.Version())
78 }
79 for _, uid := range plist.Splits {
80 sKey, kErr := SplitKey(k, uid)
81 Checkf(kErr,
82 "Error creating split key from base key: %v, version: %d", k,
83 item.Version())
84 newTxn := pstore.NewTransactionAt(readTs, false)
85 _, dbErr := newTxn.Get(sKey)
86 if dbErr != nil {
87 log.Panic("Snapshot verification failed: Unable to find splitKey: ",
88 sKey, "\nbaseKey: ", " version: ", item.Version(),
89 parsedKey, "\nSplits: ", plist.Splits,
90 )
91 }
92 }
93 return nil
94 })
95 Checkf(err, "Error getting value of key: %v version: %v", k, item.Version())
96
97 if item.DiscardEarlierVersions() {
98 break
99 }
100 }
101 return nil, nil
102 }
103}
104
105// VerifyPostingSplits checks if all the keys from parts are

Callers 1

populateSnapshotMethod · 0.92

Calls 13

CheckfFunction · 0.85
SplitKeyFunction · 0.85
ValidMethod · 0.80
ItemMethod · 0.80
IsDataMethod · 0.80
PanicMethod · 0.80
ParseFunction · 0.70
CheckFunction · 0.70
VerifyPackFunction · 0.70
GetMethod · 0.65
NextMethod · 0.45
KeyMethod · 0.45

Tested by

no test coverage detected