40 lines
817 B
Go
40 lines
817 B
Go
package writecachebadger
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
|
)
|
|
|
|
func (c *cache) runGCLoop(ctx context.Context) {
|
|
c.wg.Add(1)
|
|
|
|
go func() {
|
|
defer c.wg.Done()
|
|
|
|
t := time.NewTicker(c.gcInterval)
|
|
defer t.Stop()
|
|
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
return
|
|
case <-t.C:
|
|
// This serves to synchronize the c.db field when changing mode as well.
|
|
c.modeMtx.RLock()
|
|
ro := c.readOnly()
|
|
c.modeMtx.RUnlock()
|
|
if ro {
|
|
continue
|
|
}
|
|
|
|
// 0.5 is the recommended value so that write amplification of the value log is 2.
|
|
// See https://pkg.go.dev/github.com/dgraph-io/badger/v4#DB.RunValueLogGC for more info.
|
|
for c.db.RunValueLogGC(0.5) == nil {
|
|
c.log.Debug(logs.WritecacheDBValueLogGCRunCompleted)
|
|
}
|
|
}
|
|
}
|
|
}()
|
|
}
|