All checks were successful
DCO action / DCO (pull_request) Successful in 1m40s
Tests and linters / Run gofumpt (pull_request) Successful in 1m42s
Pre-commit hooks / Pre-commit (pull_request) Successful in 3m6s
Vulncheck / Vulncheck (pull_request) Successful in 3m47s
Build / Build Components (1.22) (pull_request) Successful in 3m47s
Build / Build Components (1.23) (pull_request) Successful in 3m46s
Tests and linters / Tests (1.22) (pull_request) Successful in 4m27s
Tests and linters / Tests (1.23) (pull_request) Successful in 4m39s
Tests and linters / Staticcheck (pull_request) Successful in 4m47s
Tests and linters / Tests with -race (pull_request) Successful in 4m59s
Tests and linters / Lint (pull_request) Successful in 5m20s
Tests and linters / gopls check (pull_request) Successful in 5m17s
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
67 lines
2.6 KiB
Go
67 lines
2.6 KiB
Go
package writecache
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/cockroachdb/pebble"
|
|
"github.com/cockroachdb/pebble/bloom"
|
|
)
|
|
|
|
const (
|
|
defaultPebbleCacheSize = 1 << 30
|
|
defaultPebbleMemTableSize = 64 << 20
|
|
defaultMemTableStopWritesThreshold = 20
|
|
defaultPebbleBytesPerSync = 1 << 20
|
|
defaultPebbleMaxConcurrentCompactions = 5
|
|
defaultPebbleMaxOpenFiles = 1000
|
|
defaultPebbleL0CompactionThreshold = 4
|
|
defaultPebbleL0CompactionFileThreshold = 500
|
|
defaultPebbleL0StopWritesThreshold = 12
|
|
defaultPebbleLBaseMaxBytes = 128 << 20
|
|
defaultPebbleLevels = 7
|
|
defaultPebbleL0TargetFileSize = 4 << 20
|
|
defaultPebbleBlockSize = 4 << 10
|
|
defaultPebbleFilterPolicy bloom.FilterPolicy = 10
|
|
)
|
|
|
|
// OpenDB opens BoltDB instance for write-cache. Opens in read-only mode if ro is true.
|
|
func OpenDB(p string, ro bool) (*pebble.DB, error) {
|
|
opts := &pebble.Options{
|
|
ReadOnly: ro,
|
|
FormatMajorVersion: pebble.FormatNewest,
|
|
}
|
|
opts.Logger = &noopPebbleLogger{}
|
|
opts.Cache = pebble.NewCache(defaultPebbleCacheSize)
|
|
opts.MemTableSize = defaultPebbleMemTableSize
|
|
opts.MemTableStopWritesThreshold = defaultMemTableStopWritesThreshold
|
|
opts.BytesPerSync = defaultPebbleBytesPerSync
|
|
opts.MaxConcurrentCompactions = func() int { return defaultPebbleMaxConcurrentCompactions }
|
|
opts.MaxOpenFiles = defaultPebbleMaxOpenFiles
|
|
opts.L0CompactionThreshold = defaultPebbleL0CompactionThreshold
|
|
opts.L0CompactionFileThreshold = defaultPebbleL0CompactionFileThreshold
|
|
opts.L0StopWritesThreshold = defaultPebbleL0StopWritesThreshold
|
|
opts.LBaseMaxBytes = defaultPebbleLBaseMaxBytes
|
|
opts.Levels = make([]pebble.LevelOptions, defaultPebbleLevels)
|
|
opts.Levels[0].TargetFileSize = defaultPebbleL0TargetFileSize
|
|
for i := 0; i < defaultPebbleLevels; i++ {
|
|
l := &opts.Levels[i]
|
|
l.BlockSize = defaultPebbleBlockSize
|
|
l.FilterPolicy = defaultPebbleFilterPolicy
|
|
l.FilterType = pebble.TableFilter
|
|
if i > 0 {
|
|
l.TargetFileSize = opts.Levels[i-1].TargetFileSize * 2
|
|
}
|
|
l.EnsureDefaults()
|
|
}
|
|
return pebble.Open(p, opts)
|
|
}
|
|
|
|
var _ pebble.Logger = (*noopPebbleLogger)(nil)
|
|
|
|
type noopPebbleLogger struct{}
|
|
|
|
func (n *noopPebbleLogger) Fatalf(format string, args ...interface{}) {
|
|
log.Fatalf(format, args...)
|
|
}
|
|
|
|
func (n *noopPebbleLogger) Infof(string, ...interface{}) {}
|