[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make badger store GCReclaimInterval and GcDiscardRatio options #139

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions store/badger/badger.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ type badgerStore struct {
db *badger.DB
chWg sync.WaitGroup
chQuit chan struct{}

gcInterval time.Duration
gcDiscardRatio float64
}

func (store *badgerStore) Begin(update bool) (store.Tx, error) {
Expand Down Expand Up @@ -110,25 +113,25 @@ func OpenWithOptions(opts badger.Options) (store.Store, error) {
}

dataStore := &badgerStore{
db: db,
chQuit: make(chan struct{}, 1),
db: db,
chQuit: make(chan struct{}, 1),
gcInterval: time.Minute * 5,
gcDiscardRatio: 0.5,
}
dataStore.startGC()
return dataStore, nil
}

const (
GCReclaimInterval = time.Minute * 5
GCDiscardRatio = 0.5
)
func (store *badgerStore) SetGCReclaimInterval(duration time.Duration) { store.gcInterval = duration }
func (store *badgerStore) SetGCDiscardRatio(ratio float64) { store.gcDiscardRatio = ratio }

func (store *badgerStore) startGC() {
store.chWg.Add(1)

go func() {
defer store.chWg.Done()

ticker := time.NewTicker(GCReclaimInterval)
ticker := time.NewTicker(store.gcInterval)
defer ticker.Stop()

for {
Expand All @@ -137,7 +140,7 @@ func (store *badgerStore) startGC() {
return

case <-ticker.C:
err := store.db.RunValueLogGC(GCDiscardRatio)
err := store.db.RunValueLogGC(store.gcDiscardRatio)
if err != nil && errors.Is(err, badger.ErrNoRewrite) {
log.Fatalf("RunValueLogGC(): %s\n", err.Error())
}
Expand Down
Loading