Unverified Commit 537179a3 authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #74 from ipfs/feat/disable-gc

feat(gc): make it possible to disable GC
parents 7d3125da fe6e0b52
...@@ -48,9 +48,14 @@ type Options struct { ...@@ -48,9 +48,14 @@ type Options struct {
GcDiscardRatio float64 GcDiscardRatio float64
// Interval between GC cycles // Interval between GC cycles
//
// If zero, the datastore will perform no automatic garbage collection.
GcInterval time.Duration GcInterval time.Duration
// Sleep time between rounds of a single GC cycle. // 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 GcSleep time.Duration
badger.Options badger.Options
...@@ -96,6 +101,12 @@ func NewDatastore(path string, options *Options) (*Datastore, error) { ...@@ -96,6 +101,12 @@ func NewDatastore(path string, options *Options) (*Datastore, error) {
gcInterval = options.GcInterval 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.Dir = path
opt.ValueDir = path opt.ValueDir = path
opt.Logger = log opt.Logger = log
...@@ -116,8 +127,10 @@ func NewDatastore(path string, options *Options) (*Datastore, error) { ...@@ -116,8 +127,10 @@ func NewDatastore(path string, options *Options) (*Datastore, error) {
gcInterval: gcInterval, gcInterval: gcInterval,
} }
// schedule periodic GC till db is closed // Start the GC process if requested.
go ds.periodicGC() if ds.gcInterval > 0 {
go ds.periodicGC()
}
return ds, nil return ds, nil
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment