-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify Pebble Datastore creation with single set of options (#39)
Use a single set of options when creating the Pebble Datastore. One of the options allows passing a struct containing all Pebble options.This means that no argumants other than path are to create a pebble datastore with the default settings. Make it easier to handle creation/teardown of a custom-sized Pebble shared block cache. Only the cache size need to be specified as a creation option if using other the default size.
- Loading branch information
Showing
3 changed files
with
89 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package pebbleds | ||
|
||
import ( | ||
"github.com/cockroachdb/pebble" | ||
) | ||
|
||
type config struct { | ||
cacheSize int64 | ||
db *pebble.DB | ||
pebbleOpts *pebble.Options | ||
} | ||
|
||
type Option func(*config) | ||
|
||
func getOpts(options []Option) config { | ||
var cfg config | ||
for _, opt := range options { | ||
if opt == nil { | ||
continue | ||
} | ||
opt(&cfg) | ||
} | ||
return cfg | ||
} | ||
|
||
// WithCacheSize configures the size of pebble's shared block cache. A value of | ||
// 0 (the default) uses the default cache size. | ||
func WithCacheSize(size int64) Option { | ||
return func(c *config) { | ||
c.cacheSize = size | ||
} | ||
} | ||
|
||
// WithPebbleDB is used to configure the Datastore with a custom DB. | ||
func WithPebbleDB(db *pebble.DB) Option { | ||
return func(c *config) { | ||
c.db = db | ||
} | ||
} | ||
|
||
// WithPebbleOpts sets any/all configurable values for pebble. If not set, the | ||
// default configuration values are used. Any unspecified value in opts is | ||
// replaced by the default value. | ||
func WithPebbleOpts(opts *pebble.Options) Option { | ||
return func(c *config) { | ||
c.pebbleOpts = opts | ||
} | ||
} |