Skip to content

Commit

Permalink
storage/engine: centralize specification of pebble.Options
Browse files Browse the repository at this point in the history
Fixes cockroachdb#41860

Release note: None
  • Loading branch information
petermattis committed Oct 29, 2019
1 parent a576473 commit 7997e40
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 65 deletions.
18 changes: 4 additions & 14 deletions pkg/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,23 +498,13 @@ func (cfg *Config) CreateEngines(ctx context.Context) (Engines, error) {
// TODO(itsbilal): Tune these options, and allow them to be overridden
// in the spec (similar to the existing spec.RocksDBOptions and others).
pebbleConfig := engine.PebbleConfig{
Dir: spec.Path,
Opts: &pebble.Options{
Cache: pebbleCache,
MaxOpenFiles: int(openFileLimitPerStore),
MemTableSize: 64 << 20,
MemTableStopWritesThreshold: 4,
MinFlushRate: 4 << 20,
L0CompactionThreshold: 2,
L0StopWritesThreshold: 400,
LBaseMaxBytes: 64 << 20, // 64 MB
Levels: []pebble.LevelOptions{{
BlockSize: 32 << 10,
}},
},
Dir: spec.Path,
Opts: engine.DefaultPebbleOptions(),
Attrs: spec.Attributes,
Settings: cfg.Settings,
}
pebbleConfig.Opts.Cache = pebbleCache
pebbleConfig.Opts.MaxOpenFiles = int(openFileLimitPerStore)
eng, err = engine.NewPebble(pebbleConfig)
} else {
rocksDBConfig := engine.RocksDBConfig{
Expand Down
23 changes: 7 additions & 16 deletions pkg/storage/engine/bench_pebble_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,17 @@ import (
"github.com/cockroachdb/pebble/vfs"
)

func newPebbleOptions(fs vfs.FS) *pebble.Options {
return &pebble.Options{
Cache: pebble.NewCache(testCacheSize),
FS: fs,
MemTableSize: 64 << 20,
MemTableStopWritesThreshold: 4,
MinFlushRate: 4 << 20,
L0CompactionThreshold: 2,
L0StopWritesThreshold: 400,
LBaseMaxBytes: 64 << 20, // 64 MB
Levels: []pebble.LevelOptions{{
BlockSize: 32 << 10,
}},
}
func testPebbleOptions(fs vfs.FS) *pebble.Options {
opts := DefaultPebbleOptions()
opts.Cache = pebble.NewCache(testCacheSize)
opts.FS = fs
return opts
}

func setupMVCCPebble(b testing.TB, dir string) Engine {
peb, err := NewPebble(PebbleConfig{
Dir: dir,
Opts: newPebbleOptions(vfs.Default),
Opts: testPebbleOptions(vfs.Default),
})
if err != nil {
b.Fatalf("could not create new pebble instance at %s: %+v", dir, err)
Expand All @@ -48,7 +39,7 @@ func setupMVCCPebble(b testing.TB, dir string) Engine {

func setupMVCCInMemPebble(b testing.TB, loc string) Engine {
peb, err := NewPebble(PebbleConfig{
Opts: newPebbleOptions(vfs.NewMem()),
Opts: testPebbleOptions(vfs.NewMem()),
})
if err != nil {
b.Fatalf("could not create new in-mem pebble instance: %+v", err)
Expand Down
5 changes: 1 addition & 4 deletions pkg/storage/engine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/cockroach/pkg/util/protoutil"
"github.com/cockroachdb/pebble"
"github.com/cockroachdb/pebble/vfs"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -69,9 +68,7 @@ func runWithAllEngines(test func(e Engine, t *testing.T), t *testing.T) {

func() {
pebbleInMem, err := NewPebble(PebbleConfig{
Opts: &pebble.Options{
FS: vfs.NewMem(),
},
Opts: testPebbleOptions(vfs.NewMem()),
})
if err != nil {
t.Fatal(err)
Expand Down
5 changes: 1 addition & 4 deletions pkg/storage/engine/mvcc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/randutil"
"github.com/cockroachdb/cockroach/pkg/util/shuffle"
"github.com/cockroachdb/cockroach/pkg/util/uuid"
"github.com/cockroachdb/pebble"
"github.com/cockroachdb/pebble/vfs"
"github.com/gogo/protobuf/proto"
"github.com/kr/pretty"
Expand Down Expand Up @@ -89,9 +88,7 @@ func createTestRocksDBEngine() Engine {
// createTestPebbleEngine returns a new in-memory Pebble storage engine.
func createTestPebbleEngine() Engine {
peb, err := NewPebble(PebbleConfig{
Opts: &pebble.Options{
FS: vfs.NewMem(),
},
Opts: testPebbleOptions(vfs.NewMem()),
})
if err != nil {
return nil
Expand Down
22 changes: 18 additions & 4 deletions pkg/storage/engine/pebble.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,24 @@ var PebbleTablePropertyCollectors = []func() pebble.TablePropertyCollector{
func() pebble.TablePropertyCollector { return &pebbleDeleteRangeCollector{} },
}

// DefaultPebbleOptions returns the default pebble options.
func DefaultPebbleOptions() *pebble.Options {
return &pebble.Options{
Comparer: MVCCComparer,
L0CompactionThreshold: 2,
L0StopWritesThreshold: 1000,
LBaseMaxBytes: 64 << 20, // 64 MB
Levels: []pebble.LevelOptions{{
BlockSize: 32 << 10, // 32 KB
}},
MemTableSize: 64 << 20, // 64 MB
MemTableStopWritesThreshold: 4,
Merger: MVCCMerger,
MinFlushRate: 4 << 20, // 4 MB/sec
TablePropertyCollectors: PebbleTablePropertyCollectors,
}
}

// PebbleConfig holds all configuration parameters and knobs used in setting up
// a new Pebble instance.
type PebbleConfig struct {
Expand Down Expand Up @@ -216,10 +234,6 @@ var _ WithSSTables = &Pebble{}

// NewPebble creates a new Pebble instance, at the specified path.
func NewPebble(cfg PebbleConfig) (*Pebble, error) {
cfg.Opts.Comparer = MVCCComparer
cfg.Opts.Merger = MVCCMerger
cfg.Opts.TablePropertyCollectors = PebbleTablePropertyCollectors

// pebble.Open also calls EnsureDefaults, but only after doing a clone. Call
// EnsureDefaults beforehand so we have a matching cfg here for when we save
// cfg.FS and cfg.ReadOnly later on.
Expand Down
34 changes: 11 additions & 23 deletions pkg/storage/engine/temp_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,29 +120,17 @@ func NewPebbleTempEngine(
tempStorage base.TempStorageConfig, storeSpec base.StoreSpec,
) (diskmap.Factory, error) {
// Default options as copied over from pebble/cmd/pebble/db.go
opts := &pebble.Options{
// Pebble doesn't currently support 0-size caches, so use a 128MB cache for
// now.
Cache: pebble.NewCache(128 << 20),
// The Pebble temp engine does not use MVCC Encoding. Instead, the
// caller-provided key is used as-is (with the prefix prepended). See
// pebbleMap.makeKey and pebbleMap.makeKeyWithSequence on how this works.
// Use the default bytes.Compare-like comparer.
Comparer: pebble.DefaultComparer,
DisableWAL: true,
MemTableSize: 64 << 20,
MemTableStopWritesThreshold: 4,
MinFlushRate: 4 << 20,
L0CompactionThreshold: 2,
L0StopWritesThreshold: 400,
LBaseMaxBytes: 64 << 20, // 64 MB
Levels: []pebble.LevelOptions{{
BlockSize: 32 << 10,
}},
Merger: &pebble.Merger{
Name: "cockroach_merge_operator",
},
}
opts := DefaultPebbleOptions()
// Pebble doesn't currently support 0-size caches, so use a 128MB cache for
// now.
opts.Cache = pebble.NewCache(128 << 20)
// The Pebble temp engine does not use MVCC Encoding. Instead, the
// caller-provided key is used as-is (with the prefix prepended). See
// pebbleMap.makeKey and pebbleMap.makeKeyWithSequence on how this works.
// Use the default bytes.Compare-like comparer.
opts.Comparer = pebble.DefaultComparer
opts.DisableWAL = true
opts.TablePropertyCollectors = nil

path := tempStorage.Path
if tempStorage.InMemory {
Expand Down

0 comments on commit 7997e40

Please sign in to comment.