MCPcopy
hub / github.com/dgraph-io/badger / deleteMoveKeysFor

Method deleteMoveKeysFor

value.go:694–749  ·  view source on GitHub ↗
(fid uint32, tr trace.Trace)

Source from the content-addressed store, hash-verified

692}
693
694func (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
751func (vlog *valueLog) incrIteratorCount() {

Callers 1

runGCMethod · 0.95

Calls 12

CloseMethod · 0.95
SeekMethod · 0.95
ValidForPrefixMethod · 0.95
NextMethod · 0.95
ItemMethod · 0.95
DecodeMethod · 0.95
KeyWithTsFunction · 0.92
ViewMethod · 0.80
VersionMethod · 0.80
batchSetMethod · 0.80
KeyMethod · 0.65
NewIteratorMethod · 0.45

Tested by

no test coverage detected