Skip to content

Commit

Permalink
apply feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
fredcarle committed Aug 16, 2022
1 parent f9b1a47 commit d6bc357
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
8 changes: 4 additions & 4 deletions cli/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,12 @@ func init() {
}

startCmd.Flags().Var(
&cfg.Datastore.Badger.VLogMaxSize, "vlogmaxsize",
"Specify the datastore maximum value log file size (in bytes)",
&cfg.Datastore.Badger.ValueLogFileSize, "valuelogfilesize",
"Specify the datastore value log file size (in bytes). In memory size will be 2*valuelogfilesize",
)
err = viper.BindPFlag("datastore.badger.vlogmaxsize", startCmd.Flags().Lookup("vlogmaxsize"))
err = viper.BindPFlag("datastore.badger.valuelogfilesize", startCmd.Flags().Lookup("valuelogfilesize"))
if err != nil {
log.FeedbackFatalE(context.Background(), "Could not bind datastore..badger.vlogmaxsize", err)
log.FeedbackFatalE(context.Background(), "Could not bind datastore.badger.valuelogfilesize", err)
}

startCmd.Flags().String(
Expand Down
20 changes: 11 additions & 9 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,13 @@ func (cfg *Config) Load(rootDirPath string) error {
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AutomaticEnv()

if err := viper.Unmarshal(cfg, viper.DecodeHook(mapstructure.TextUnmarshallerHookFunc())); err != nil {
err := viper.Unmarshal(cfg, viper.DecodeHook(mapstructure.TextUnmarshallerHookFunc()))
if err != nil {
return err
}
cfg.setBadgerVLogMaxSize()
cfg.handleParams(rootDirPath)
err := cfg.validate()
err = cfg.validate()
if err != nil {
return err
}
Expand All @@ -128,7 +129,8 @@ func (cfg *Config) LoadWithoutRootDir() error {
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AutomaticEnv()

if err := viper.Unmarshal(cfg, viper.DecodeHook(mapstructure.TextUnmarshallerHookFunc())); err != nil {
err = viper.Unmarshal(cfg, viper.DecodeHook(mapstructure.TextUnmarshallerHookFunc()))
if err != nil {
return err
}
rootDir, err := DefaultRootDir()
Expand Down Expand Up @@ -178,7 +180,7 @@ func (cfg *Config) handleParams(rootDir string) {
}

func (cfg *Config) setBadgerVLogMaxSize() {
cfg.Datastore.Badger.ValueLogFileSize = int64(cfg.Datastore.Badger.VLogMaxSize)
cfg.Datastore.Badger.Options.ValueLogFileSize = int64(cfg.Datastore.Badger.ValueLogFileSize)
}

// DatastoreConfig configures datastores.
Expand All @@ -190,8 +192,8 @@ type DatastoreConfig struct {

// BadgerConfig configures Badger's on-disk / filesystem mode.
type BadgerConfig struct {
Path string
VLogMaxSize ByteSize
Path string
ValueLogFileSize ByteSize
*badgerds.Options
}

Expand Down Expand Up @@ -278,9 +280,9 @@ func defaultDatastoreConfig() *DatastoreConfig {
return &DatastoreConfig{
Store: "badger",
Badger: BadgerConfig{
Path: "data",
VLogMaxSize: 1 * GB,
Options: &opts,
Path: "data",
ValueLogFileSize: 1 * GB,
Options: &opts,
},
}
}
Expand Down
4 changes: 2 additions & 2 deletions config/configfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ datastore:
store: {{ .Datastore.Store }}
badger:
path: {{ .Datastore.Badger.Path }}
# Maximum file size of the value log file. The actual file size will be 2*vlogmaxsize.
# Maximum file size of the value log files. The in memory file size will be 2*valuelogfilesize.
# Human friendly units can be used (ex: 500MB).
vlogmaxsize: {{ .Datastore.Badger.VLogMaxSize }}
valuelogfilesize: {{ .Datastore.Badger.ValueLogFileSize }}
# memory:
# size: {{ .Datastore.Memory.Size }}
Expand Down
4 changes: 2 additions & 2 deletions config/configfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestReadConfigFileForDatastore(t *testing.T) {
cfg := DefaultConfig()
cfg.Datastore.Store = "badger"
cfg.Datastore.Badger.Path = "dataPath"
cfg.Datastore.Badger.VLogMaxSize = 512 * MB
cfg.Datastore.Badger.ValueLogFileSize = 512 * MB

err := cfg.WriteConfigFileToRootDir(dir)
if err != nil {
Expand All @@ -131,5 +131,5 @@ func TestReadConfigFileForDatastore(t *testing.T) {
}
assert.Equal(t, cfg.Datastore.Store, cfgFromFile.Datastore.Store)
assert.Equal(t, dir+"/"+cfg.Datastore.Badger.Path, cfgFromFile.Datastore.Badger.Path)
assert.NotEqual(t, cfg.Datastore.Badger.VLogMaxSize, cfgFromFile.Datastore.Badger.VLogMaxSize)
assert.NotEqual(t, cfg.Datastore.Badger.ValueLogFileSize, cfgFromFile.Datastore.Badger.ValueLogFileSize)
}

0 comments on commit d6bc357

Please sign in to comment.