(fid uint32, tr trace.Trace)
| 692 | } |
| 693 | |
| 694 | func (vlog *valueLog) deleteMoveKeysFor(fid uint32, tr trace.Trace) error { |
| 695 | db := vlog.db |
| 696 | var result []*Entry |
| 697 | var count, pointers uint64 |
| 698 | tr.LazyPrintf("Iterating over move keys to find invalids for fid: %d", fid) |
| 699 | err := db.View(func(txn *Txn) error { |
| 700 | opt := DefaultIteratorOptions |
| 701 | opt.InternalAccess = true |
| 702 | opt.PrefetchValues = false |
| 703 | itr := txn.NewIterator(opt) |
| 704 | defer itr.Close() |
| 705 | |
| 706 | for itr.Seek(badgerMove); itr.ValidForPrefix(badgerMove); itr.Next() { |
| 707 | count++ |
| 708 | item := itr.Item() |
| 709 | if item.meta&bitValuePointer == 0 { |
| 710 | continue |
| 711 | } |
| 712 | pointers++ |
| 713 | var vp valuePointer |
| 714 | vp.Decode(item.vptr) |
| 715 | if vp.Fid == fid { |
| 716 | e := &Entry{Key: y.KeyWithTs(item.Key(), item.Version()), meta: bitDelete} |
| 717 | result = append(result, e) |
| 718 | } |
| 719 | } |
| 720 | return nil |
| 721 | }) |
| 722 | if err != nil { |
| 723 | tr.LazyPrintf("Got error while iterating move keys: %v", err) |
| 724 | tr.SetError() |
| 725 | return err |
| 726 | } |
| 727 | tr.LazyPrintf("Num total move keys: %d. Num pointers: %d", count, pointers) |
| 728 | tr.LazyPrintf("Number of invalid move keys found: %d", len(result)) |
| 729 | batchSize := 10240 |
| 730 | for i := 0; i < len(result); { |
| 731 | end := i + batchSize |
| 732 | if end > len(result) { |
| 733 | end = len(result) |
| 734 | } |
| 735 | if err := db.batchSet(result[i:end]); err != nil { |
| 736 | if err == ErrTxnTooBig { |
| 737 | batchSize /= 2 |
| 738 | tr.LazyPrintf("Dropped batch size to %d", batchSize) |
| 739 | continue |
| 740 | } |
| 741 | tr.LazyPrintf("Error while doing batchSet: %v", err) |
| 742 | tr.SetError() |
| 743 | return err |
| 744 | } |
| 745 | i += batchSize |
| 746 | } |
| 747 | tr.LazyPrintf("Move keys deletion done.") |
| 748 | return nil |
| 749 | } |
| 750 | |
| 751 | func (vlog *valueLog) incrIteratorCount() { |
no test coverage detected