Skip to content

Commit

Permalink
Merge pull request #74 from ipfs/feat/disable-gc
Browse files Browse the repository at this point in the history
feat(gc): make it possible to disable GC
  • Loading branch information
Stebalien authored Oct 22, 2019
2 parents 7d3125d + fe6e0b5 commit 537179a
Showing 1 changed file with 15 additions and 2 deletions.
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

0 comments on commit 537179a

Please sign in to comment.