bitcask-mirror/options.go

63 lines
1.6 KiB
Go
Raw Normal View History

2019-03-14 11:14:55 +00:00
package bitcask
import "github.com/prologic/bitcask/internal/config"
2019-03-14 11:14:55 +00:00
const (
2019-03-21 07:20:53 +00:00
// DefaultMaxDatafileSize is the default maximum datafile size in bytes
2019-03-14 11:14:55 +00:00
DefaultMaxDatafileSize = 1 << 20 // 1MB
2019-03-21 07:20:53 +00:00
// DefaultMaxKeySize is the default maximum key size in bytes
DefaultMaxKeySize = uint32(64) // 64 bytes
2019-03-21 07:20:53 +00:00
// DefaultMaxValueSize is the default value size in bytes
DefaultMaxValueSize = uint64(1 << 16) // 65KB
// DefaultSync is the default file synchronization action
DefaultSync = false
2019-03-21 07:20:53 +00:00
)
2019-03-21 07:20:53 +00:00
// Option is a function that takes a config struct and modifies it
type Option func(*config.Config) error
2019-03-14 11:14:55 +00:00
2019-03-21 07:20:53 +00:00
// WithMaxDatafileSize sets the maximum datafile size option
func WithMaxDatafileSize(size int) Option {
return func(cfg *config.Config) error {
cfg.MaxDatafileSize = size
2019-03-14 11:14:55 +00:00
return nil
}
}
2019-03-21 07:20:53 +00:00
// WithMaxKeySize sets the maximum key size option
func WithMaxKeySize(size uint32) Option {
return func(cfg *config.Config) error {
cfg.MaxKeySize = size
2019-03-14 11:14:55 +00:00
return nil
}
}
2019-03-21 07:20:53 +00:00
// WithMaxValueSize sets the maximum value size option
func WithMaxValueSize(size uint64) Option {
return func(cfg *config.Config) error {
cfg.MaxValueSize = size
2019-03-14 11:14:55 +00:00
return nil
}
}
// WithSync causes Sync() to be called on every key/value written increasing
2019-08-14 10:53:08 +00:00
// durability and safety at the expense of performance
func WithSync(sync bool) Option {
return func(cfg *config.Config) error {
cfg.Sync = sync
return nil
}
}
func newDefaultConfig() *config.Config {
return &config.Config{
MaxDatafileSize: DefaultMaxDatafileSize,
MaxKeySize: DefaultMaxKeySize,
MaxValueSize: DefaultMaxValueSize,
Sync: DefaultSync,
}
}