| 443 | fmt.Fprintln(w, "") |
| 444 | } |
| 445 | func rollupKey(db *badger.DB) { |
| 446 | txn := db.NewTransactionAt(opt.readTs, false) |
| 447 | defer txn.Discard() |
| 448 | |
| 449 | key, err := hex.DecodeString(opt.rollupKey) |
| 450 | x.Check(err) |
| 451 | |
| 452 | iopts := badger.DefaultIteratorOptions |
| 453 | iopts.AllVersions = true |
| 454 | iopts.PrefetchValues = false |
| 455 | itr := txn.NewKeyIterator(key, iopts) |
| 456 | defer itr.Close() |
| 457 | |
| 458 | itr.Rewind() |
| 459 | if !itr.Valid() { |
| 460 | log.Fatalf("Unable to seek to key: %s", hex.Dump(key)) |
| 461 | } |
| 462 | |
| 463 | item := itr.Item() |
| 464 | // Don't need to do anything if the bitdelta is not set. |
| 465 | if item.UserMeta()&posting.BitDeltaPosting == 0 { |
| 466 | fmt.Printf("First item has UserMeta:[b%04b]. Nothing to do\n", item.UserMeta()) |
| 467 | return |
| 468 | } |
| 469 | pl, err := posting.ReadPostingList(item.KeyCopy(nil), itr) |
| 470 | x.Check(err) |
| 471 | |
| 472 | alloc := z.NewAllocator(32<<20, "Debug.RollupKey") |
| 473 | defer alloc.Release() |
| 474 | |
| 475 | // Setting kvs at their original value as we can't give a new timestamp in debug mode. |
| 476 | kvs, err := pl.Rollup(alloc, math.MaxUint64) |
| 477 | x.Check(err) |
| 478 | |
| 479 | wb := db.NewManagedWriteBatch() |
| 480 | x.Check(wb.WriteList(&bpb.KVList{Kv: kvs})) |
| 481 | x.Check(wb.Flush()) |
| 482 | } |
| 483 | |
| 484 | func lookup(db *badger.DB) { |
| 485 | txn := db.NewTransactionAt(opt.readTs, false) |