Skip to content

Commit

Permalink
env: support underscore separated numbers (#12818)
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored Nov 22, 2024
1 parent f4e5d1e commit 67229d8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
20 changes: 12 additions & 8 deletions erigon-lib/common/dbg/dbg_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package dbg

import (
"fmt"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -70,20 +71,14 @@ func EnvInt(envVarName string, defaultVal int) int {
v, _ := os.LookupEnv(envVarName)
if v != "" {
WarnOnErigonPrefix(envVarName)
i, err := strconv.Atoi(v)
if err != nil {
panic(err)
}
i := MustParseInt(v)
log.Info("[env]", envVarName, i)
return i
}

v, _ = os.LookupEnv("ERIGON_" + envVarName)
if v != "" {
i, err := strconv.Atoi(v)
if err != nil {
panic(err)
}
i := MustParseInt(v)
log.Info("[env]", envVarName, i)
return i
}
Expand Down Expand Up @@ -141,3 +136,12 @@ func WarnOnErigonPrefix(envVarName string) {
log.Warn("[env] please use ERIGON_ prefix for env variables of erigon", "var", envVarName)
}
}

func MustParseInt(strNum string) int {
cleanNum := strings.ReplaceAll(strNum, "_", "")
parsed, err := strconv.ParseInt(cleanNum, 10, 64)
if err != nil {
panic(fmt.Errorf("%w, str: %s", err, strNum))
}
return int(parsed)
}
6 changes: 1 addition & 5 deletions erigon-lib/common/dbg/experiments.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"path/filepath"
"runtime"
"runtime/pprof"
"strconv"
"sync"
"time"

Expand Down Expand Up @@ -96,10 +95,7 @@ func DirtySpace() uint64 {
dirtySaceOnce.Do(func() {
v, _ := os.LookupEnv("MDBX_DIRTY_SPACE_MB")
if v != "" {
i, err := strconv.Atoi(v)
if err != nil {
panic(err)
}
i := MustParseInt(v)
log.Info("[Experiment]", "MDBX_DIRTY_SPACE_MB", i)
dirtySace = uint64(i * 1024 * 1024)
}
Expand Down

0 comments on commit 67229d8

Please sign in to comment.