(key []byte, itr *badger.Iterator)
| 743 | } |
| 744 | |
| 745 | func (tl *threadLocal) toBackupList(key []byte, itr *badger.Iterator) ( |
| 746 | *bpb.KVList, *pb.DropOperation, error) { |
| 747 | list := &bpb.KVList{} |
| 748 | var dropOp *pb.DropOperation |
| 749 | |
| 750 | item := itr.Item() |
| 751 | if item.Version() < tl.Request.SinceTs { |
| 752 | return list, nil, |
| 753 | errors.Errorf("toBackupList: Item.Version(): %d should be less than sinceTs: %d", |
| 754 | item.Version(), tl.Request.SinceTs) |
| 755 | } |
| 756 | if item.IsDeletedOrExpired() { |
| 757 | return list, nil, nil |
| 758 | } |
| 759 | |
| 760 | switch item.UserMeta() { |
| 761 | case posting.BitEmptyPosting, posting.BitCompletePosting, posting.BitDeltaPosting: |
| 762 | l, err := posting.ReadPostingList(key, itr) |
| 763 | if err != nil { |
| 764 | return nil, nil, errors.Wrapf(err, "while reading posting list") |
| 765 | } |
| 766 | |
| 767 | // Don't allocate kv on tl.alloc, because we don't need it by the end of this func. |
| 768 | kv, err := l.ToBackupPostingList(&tl.bpl, tl.alloc, tl.buf) |
| 769 | if err != nil { |
| 770 | return nil, nil, errors.Wrapf(err, "while rolling up list") |
| 771 | } |
| 772 | |
| 773 | backupKey, err := tl.toBackupKey(kv.Key) |
| 774 | if err != nil { |
| 775 | return nil, nil, err |
| 776 | } |
| 777 | |
| 778 | // check if this key was storing a DROP operation record. If yes, get the drop operation. |
| 779 | dropOp, err = checkAndGetDropOp(key, l, tl.Request.ReadTs) |
| 780 | if err != nil { |
| 781 | return nil, nil, err |
| 782 | } |
| 783 | |
| 784 | kv.Key = backupKey |
| 785 | list.Kv = append(list.Kv, kv) |
| 786 | default: |
| 787 | return nil, nil, errors.Errorf( |
| 788 | "Unexpected meta: %d for key: %s", item.UserMeta(), hex.Dump(key)) |
| 789 | } |
| 790 | return list, dropOp, nil |
| 791 | } |
| 792 | |
| 793 | func (tl *threadLocal) toBackupKey(key []byte) ([]byte, error) { |
| 794 | parsedKey, err := x.Parse(key) |
no test coverage detected