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(gc): make it possible to disable GC #74

Merged
merged 1 commit into from
Oct 22, 2019
Merged
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
17 changes: 15 additions & 2 deletions datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ type Options struct {
GcDiscardRatio float64

// Interval between GC cycles
//
// If zero, the datastore will perform no automatic garbage collection.
GcInterval time.Duration

// Sleep time between rounds of a single GC cycle.
//
// If zero, the datastore will only perform one round of GC per
// GcInterval.
GcSleep time.Duration

badger.Options
Expand Down Expand Up @@ -96,6 +101,12 @@ func NewDatastore(path string, options *Options) (*Datastore, error) {
gcInterval = options.GcInterval
}

if gcSleep <= 0 {
// If gcSleep is 0, we don't perform multiple rounds of GC per
// cycle.
gcSleep = gcInterval
}

opt.Dir = path
opt.ValueDir = path
opt.Logger = log
Expand All @@ -116,8 +127,10 @@ func NewDatastore(path string, options *Options) (*Datastore, error) {
gcInterval: gcInterval,
}

// schedule periodic GC till db is closed
go ds.periodicGC()
// Start the GC process if requested.
if ds.gcInterval > 0 {
go ds.periodicGC()
}

return ds, nil
}
Expand Down