Skip to content

Commit

Permalink
table size value validation (#343)
Browse files Browse the repository at this point in the history
table-size inputs validation
  • Loading branch information
jingweicb authored Aug 16, 2022
1 parent 0c92a1e commit 5b745b9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 7 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ default values.`,
&startIndex,
"start-block",
-1,
`start-block is the block height to start syncing from. This will override the start_index from configuration file`,
`Start-block is the block height to start syncing from. This will override the start_index from configuration file`,
)

checkDataCmd.Flags().Int64Var(
Expand All @@ -269,15 +269,15 @@ default values.`,
checkDataCmd.Flags().Int64Var(
&tableSize,
"table-size",
0,
"Table-size configures the TableSize for badger DB. If table-size != 0, this will override the table_size from configuration file",
-1,
"Table-size configures the TableSize for badger DB. If table-size != -1, this will override the table_size from configuration file",
)

checkDataCmd.Flags().BoolVar(
&inMemoryMode,
"in-memory-mode",
false,
"in-memory-mode configures badger DB inMeomry option. Only when in-memory-mode=true, this will override the all_in_memory_enabled",
"In-memory-mode configures badger DB inMeomry option. Only when in-memory-mode=true, this will override the all_in_memory_enabled",
)

rootCmd.AddCommand(checkDataCmd)
Expand Down Expand Up @@ -394,8 +394,10 @@ func initConfig() {
Config.AllInMemoryEnabled = inMemoryMode
}

if tableSize != 0 {
if tableSize >= 2 && tableSize <= 100 {
Config.TableSize = &tableSize
} else if tableSize != -1 {
log.Fatalf("table-size %d is not in the range [2, 100], please check your input", tableSize)
}
}

Expand Down
8 changes: 8 additions & 0 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,14 @@ func assertConfiguration(ctx context.Context, config *Configuration) error {
return errors.New("serial_block_workers must be > 0")
}

if config.TableSize != nil && (*config.TableSize < 2 || *config.TableSize > 100) {
return fmt.Errorf("table_size %d is not in the range [2, 100], please check your input", *config.TableSize)
}

if config.ValueLogFileSize != nil && (*config.ValueLogFileSize < 128 || *config.ValueLogFileSize > 2048) {
return fmt.Errorf("value_log_file_size %d is not in the range [128, 2048], please check your input", *config.ValueLogFileSize)
}

if err := assertDataConfiguration(config.Data); err != nil {
return fmt.Errorf("%w: invalid data configuration", err)
}
Expand Down

0 comments on commit 5b745b9

Please sign in to comment.