Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rocksdb Option Parameter Misspelling info #3045

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ func NewAccNonceHandler(ak auth.AccountKeeper) sdk.AccNonceHandler {

func PreRun(ctx *server.Context, cmd *cobra.Command) error {
// check start flag conflicts
err := sanity.CheckStart()
err := sanity.CheckStart(ctx)
if err != nil {
return err
}
Expand Down
52 changes: 51 additions & 1 deletion app/utils/sanity/start.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package sanity

import (
"fmt"
"strings"

"github.com/spf13/viper"

"github.com/okex/exchain/app/config"
Expand All @@ -11,6 +14,7 @@ import (
"github.com/okex/exchain/libs/tendermint/consensus"
"github.com/okex/exchain/libs/tendermint/state"
"github.com/okex/exchain/libs/tendermint/types"
db "github.com/okex/exchain/libs/tm-db"
"github.com/okex/exchain/x/evm/watcher"
"github.com/okex/exchain/x/infura"
)
Expand Down Expand Up @@ -108,7 +112,7 @@ var (
)

// CheckStart check start command.If it has conflict pair above. then return the conflict error
func CheckStart() error {
func CheckStart(ctx *server.Context) error {
if viper.GetBool(FlagDisableSanity) {
return nil
}
Expand All @@ -129,5 +133,51 @@ func CheckStart() error {
}
}

rocksDBMisspelling(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can find a more common way to do the check, just like sanity check.

return nil
}

func rocksDBMisspelling(ctx *server.Context) {
//A copy of all the constant variables indicating rocksDB option parameters
//in exchain/libs/tm-db/rocksdb.go
rocksDBConst := []string{
"block_size",
"block_cache",
"statistics",
"max_open_files",
"allow_mmap_reads",
"allow_mmap_writes",
"unordered_write",
"pipelined_write",
}
params := parseOptParams(viper.GetString(db.FlagRocksdbOpts))
if params == nil {
return
}
for _, str := range rocksDBConst {
delete(params, str)
}
if len(params) != 0 {
for inputOpt, _ := range params {
ctx.Logger.Info(fmt.Sprintf("%s %s failed to set rocksDB parameters, please double-check the spelling", db.FlagRocksdbOpts, inputOpt))
}
}

return
}

func parseOptParams(params string) map[string]struct{} {
if len(params) == 0 {
return nil
}

opts := make(map[string]struct{})
for _, s := range strings.Split(params, ",") {
opt := strings.Split(s, "=")
if len(opt) != 2 {
panic("Invalid options parameter, like this 'block_size=4kb,statistics=true")
}
opts[strings.TrimSpace(opt[0])] = struct{}{}
}
return opts
}
10 changes: 6 additions & 4 deletions app/utils/sanity/start_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package sanity

import (
"testing"

"github.com/spf13/cobra"

apptype "github.com/okex/exchain/app/types"
"github.com/okex/exchain/libs/cosmos-sdk/server"
"github.com/okex/exchain/libs/cosmos-sdk/store/types"
Expand All @@ -9,8 +13,6 @@ import (
sm "github.com/okex/exchain/libs/tendermint/state"
ttypes "github.com/okex/exchain/libs/tendermint/types"
"github.com/okex/exchain/x/evm/watcher"
"github.com/spf13/cobra"
"testing"
)

func getCommandNodeModeRpcPruningNothing() *cobra.Command {
Expand Down Expand Up @@ -93,7 +95,7 @@ func TestCheckStart(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
var err error
tt.cmdFunc()
if err = CheckStart(); (err != nil) != tt.wantErr {
if err = CheckStart(nil); (err != nil) != tt.wantErr {
t.Errorf("CheckStart() error = %v, wantErr %v", err, tt.wantErr)
}
t.Log(err)
Expand Down Expand Up @@ -132,7 +134,7 @@ func TestCheckStartArchive(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var err error
if err = CheckStart(); (err != nil) != tt.wantErr {
if err = CheckStart(nil); (err != nil) != tt.wantErr {
t.Errorf("CheckStart() error = %v, wantErr %v", err, tt.wantErr)
}
t.Log(err)
Expand Down
7 changes: 4 additions & 3 deletions cmd/exchaind/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import (
"github.com/okex/exchain/x/evm/watcher"

"github.com/gogo/protobuf/jsonpb"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/okex/exchain/app/config"
okexchain "github.com/okex/exchain/app/types"
"github.com/okex/exchain/app/utils/appstatus"
Expand All @@ -36,8 +39,6 @@ import (
"github.com/okex/exchain/libs/tendermint/store"
"github.com/okex/exchain/libs/tendermint/types"
dbm "github.com/okex/exchain/libs/tm-db"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

const (
Expand Down Expand Up @@ -66,7 +67,7 @@ func replayCmd(ctx *server.Context, registerAppFlagFn func(cmd *cobra.Command),
PreRunE: func(cmd *cobra.Command, args []string) error {
// set external package flags
log.Println("--------- replay preRun ---------")
err := sanity.CheckStart()
err := sanity.CheckStart(ctx)
if err != nil {
fmt.Println(err)
return err
Expand Down
2 changes: 1 addition & 1 deletion libs/ibc-go/testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ func PreRun(ctx *server.Context) error {
appconfig.RegisterDynamicConfig(ctx.Logger.With("module", "config"))

// check start flag conflicts
err := sanity.CheckStart()
err := sanity.CheckStart(nil)
if err != nil {
return err
}
Expand Down