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

Method runGC

value.go:1834–1866  ·  view source on GitHub ↗
(discardRatio float64, head valuePointer)

Source from the content-addressed store, hash-verified

1832}
1833
1834func (vlog *valueLog) runGC(discardRatio float64, head valuePointer) error {
1835 select {
1836 case vlog.garbageCh <- struct{}{}:
1837 // Pick a log file for GC.
1838 tr := trace.New("Badger.ValueLog", "GC")
1839 tr.SetMaxEvents(100)
1840 defer func() {
1841 tr.Finish()
1842 <-vlog.garbageCh
1843 }()
1844
1845 var err error
1846 files := vlog.pickLog(head, tr)
1847 if len(files) == 0 {
1848 tr.LazyPrintf("PickLog returned zero results.")
1849 return ErrNoRewrite
1850 }
1851 tried := make(map[uint32]bool)
1852 for _, lf := range files {
1853 if _, done := tried[lf.fid]; done {
1854 continue
1855 }
1856 tried[lf.fid] = true
1857 err = vlog.doRunGC(lf, discardRatio, tr)
1858 if err == nil {
1859 return vlog.deleteMoveKeysFor(lf.fid, tr)
1860 }
1861 }
1862 return err
1863 default:
1864 return ErrRejected
1865 }
1866}
1867
1868func (vlog *valueLog) updateDiscardStats(stats map[uint32]int64) {
1869 if vlog.opt.InMemory {

Callers 1

RunValueLogGCMethod · 0.80

Calls 4

pickLogMethod · 0.95
doRunGCMethod · 0.95
deleteMoveKeysForMethod · 0.95
FinishMethod · 0.45

Tested by

no test coverage detected