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

Function showAllPostingsAt

dgraph/cmd/debug/run.go:252–314  ·  view source on GitHub ↗
(db *badger.DB, readTs uint64)

Source from the content-addressed store, hash-verified

250}
251
252func showAllPostingsAt(db *badger.DB, readTs uint64) {
253 txn := db.NewTransactionAt(readTs, false)
254 defer txn.Discard()
255
256 itr := txn.NewIterator(badger.DefaultIteratorOptions)
257 defer itr.Close()
258
259 type account struct {
260 Key int
261 Amt int
262 }
263 keys := make(map[uint64]*account)
264
265 var buf bytes.Buffer
266 fmt.Fprintf(&buf, "SHOWING all postings at %d\n", readTs)
267 for itr.Rewind(); itr.Valid(); itr.Next() {
268 item := itr.Item()
269 if item.Version() != readTs {
270 continue
271 }
272
273 pk, err := x.Parse(item.Key())
274 x.Check(err)
275 if !pk.IsData() {
276 continue
277 }
278
279 var acc *account
280 attr := x.ParseAttr(pk.Attr)
281 if strings.HasPrefix(attr, "key_") || strings.HasPrefix(attr, "amount_") {
282 var has bool
283 acc, has = keys[pk.Uid]
284 if !has {
285 acc = &account{}
286 keys[pk.Uid] = acc
287 }
288 }
289 fmt.Fprintf(&buf, " key: %+v hex: %x\n", pk, item.Key())
290 val, err := item.ValueCopy(nil)
291 x.Check(err)
292 var plist pb.PostingList
293 x.Check(proto.Unmarshal(val, &plist))
294
295 x.AssertTrue(len(plist.Postings) <= 1)
296 var num int
297 for _, p := range plist.Postings {
298 num = toInt(p)
299 appendPosting(&buf, p)
300 }
301 if num > 0 && acc != nil {
302 switch {
303 case strings.HasPrefix(attr, "key_"):
304 acc.Key = num
305 case strings.HasPrefix(attr, "amount_"):
306 acc.Amt = num
307 }
308 }
309 }

Callers 2

findFirstValidTxnFunction · 0.85
jepsenFunction · 0.85

Calls 14

ParseFunction · 0.92
CheckFunction · 0.92
ParseAttrFunction · 0.92
AssertTrueFunction · 0.92
toIntFunction · 0.85
appendPostingFunction · 0.85
NewIteratorMethod · 0.80
ValidMethod · 0.80
ItemMethod · 0.80
IsDataMethod · 0.80
CloseMethod · 0.65
NextMethod · 0.45

Tested by

no test coverage detected