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

Function lookup

dgraph/cmd/debug/run.go:484–546  ·  view source on GitHub ↗
(db *badger.DB)

Source from the content-addressed store, hash-verified

482}
483
484func lookup(db *badger.DB) {
485 txn := db.NewTransactionAt(opt.readTs, false)
486 defer txn.Discard()
487
488 iopts := badger.DefaultIteratorOptions
489 iopts.AllVersions = true
490 iopts.PrefetchValues = false
491 itr := txn.NewIterator(iopts)
492 defer itr.Close()
493
494 key, err := hex.DecodeString(opt.keyLookup)
495 if err != nil {
496 log.Fatal(err)
497 }
498 itr.Seek(key)
499 if !itr.Valid() {
500 log.Fatalf("Unable to seek to key: %s", hex.Dump(key))
501 }
502
503 if opt.keyHistory {
504 history(key, itr)
505 return
506 }
507
508 var buf bytes.Buffer
509 item := itr.Item()
510 if item.UserMeta()&posting.BitSchemaPosting > 0 {
511 // Schema is stored as pb.SchemaUpdate, we should not try to read it as a posting list
512 fmt.Fprintf(&buf, "Key: %x\n", item.Key())
513 schemaBytes, err := item.ValueCopy(nil)
514 x.Check(err)
515
516 var s pb.SchemaUpdate
517 x.Check(proto.Unmarshal(schemaBytes, &s))
518 fmt.Fprintf(&buf, "Value: %+v\n", s)
519 } else {
520 fmt.Fprintf(&buf, "Key: %x", item.Key())
521 pl, err := posting.ReadPostingList(item.KeyCopy(nil), itr)
522 if err != nil {
523 log.Fatal(err)
524 }
525 pl.RLock()
526 c := pl.GetLength(math.MaxUint64)
527 pl.RUnlock()
528 fmt.Fprintf(&buf, " Length: %d", c)
529
530 splits := pl.PartSplits()
531 isMultiPart := len(splits) > 0
532 fmt.Fprintf(&buf, " Is multi-part list? %v", isMultiPart)
533 if isMultiPart {
534 fmt.Fprintf(&buf, " Start UID of parts: %v\n", splits)
535 }
536
537 err = pl.Iterate(math.MaxUint64, 0, func(o *pb.Posting) error {
538 appendPosting(&buf, o)
539 return nil
540 })
541 if err != nil {

Callers 1

runFunction · 0.85

Calls 15

CheckFunction · 0.92
ReadPostingListFunction · 0.92
historyFunction · 0.85
appendPostingFunction · 0.85
NewIteratorMethod · 0.80
FatalMethod · 0.80
SeekMethod · 0.80
ValidMethod · 0.80
FatalfMethod · 0.80
ItemMethod · 0.80
RLockMethod · 0.80
GetLengthMethod · 0.80

Tested by

no test coverage detected