(db *badger.DB)
| 482 | } |
| 483 | |
| 484 | func 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 { |
no test coverage detected