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

Method RunValueLogGC

db.go:1198–1229  ·  view source on GitHub ↗

RunValueLogGC triggers a value log garbage collection. It picks value log files to perform GC based on statistics that are collected during compactions. If no such statistics are available, then log files are picked in random order. The process stops as soon as the first log file is encountered wh

(discardRatio float64)

Source from the content-addressed store, hash-verified

1196// Note: Every time GC is run, it would produce a spike of activity on the LSM
1197// tree.
1198func (db *DB) RunValueLogGC(discardRatio float64) error {
1199 if db.opt.InMemory {
1200 return ErrGCInMemoryMode
1201 }
1202 if discardRatio >= 1.0 || discardRatio <= 0.0 {
1203 return ErrInvalidRequest
1204 }
1205
1206 // startLevel is the level from which we should search for the head key. When badger is running
1207 // with KeepL0InMemory flag, all tables on L0 are kept in memory. This means we should pick head
1208 // key from Level 1 onwards because if we pick the headkey from Level 0 we might end up losing
1209 // data. See test TestL0GCBug.
1210 startLevel := 0
1211 if db.opt.KeepL0InMemory {
1212 startLevel = 1
1213 }
1214 // Find head on disk
1215 headKey := y.KeyWithTs(head, math.MaxUint64)
1216 // Need to pass with timestamp, lsm get removes the last 8 bytes and compares key
1217 val, err := db.lc.get(headKey, nil, startLevel)
1218 if err != nil {
1219 return errors.Wrap(err, "Retrieving head from on-disk LSM")
1220 }
1221
1222 var head valuePointer
1223 if len(val.Value) > 0 {
1224 head.Decode(val.Value)
1225 }
1226
1227 // Pick a log file and run GC
1228 return db.vlog.runGC(discardRatio, head)
1229}
1230
1231// Size returns the size of lsm and value log files in bytes. It can be used to decide how often to
1232// call RunValueLogGC.

Callers 8

BenchmarkDbGrowthFunction · 0.80
TestLSMOnlyFunction · 0.80
TestBigKeyValuePairsFunction · 0.80
TestL0GCBugFunction · 0.80
TestValueGCManagedFunction · 0.80
TestValueLogTriggerFunction · 0.80
TestBug578Function · 0.80
mainFunction · 0.80

Calls 4

DecodeMethod · 0.95
KeyWithTsFunction · 0.92
runGCMethod · 0.80
getMethod · 0.45

Tested by 7

BenchmarkDbGrowthFunction · 0.64
TestLSMOnlyFunction · 0.64
TestBigKeyValuePairsFunction · 0.64
TestL0GCBugFunction · 0.64
TestValueGCManagedFunction · 0.64
TestValueLogTriggerFunction · 0.64
TestBug578Function · 0.64