Skip to content

Commit

Permalink
e3: Thread safe reopen folder (erigontech#6810)
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored Feb 9, 2023
1 parent ad1291a commit ec52990
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 55 deletions.
2 changes: 1 addition & 1 deletion cmd/erigon-el/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ func (s *Ethereum) setUpBlockReader(ctx context.Context, dirs datadir.Dirs, snCo
if err != nil {
return nil, nil, nil, err
}
if err = agg.ReopenFiles(); err != nil {
if err = agg.ReopenFolder(); err != nil {
return nil, nil, nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/integration/commands/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ func allSnapshots(ctx context.Context, db kv.RoDB) (*snapshotsync.RoSnapshots, *
if err != nil {
panic(err)
}
err = _aggSingleton.ReopenFiles()
err = _aggSingleton.ReopenFolder()
if err != nil {
panic(err)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/rpcdaemon/cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func RootCommand() (*cobra.Command, *httpcfg.HttpCfg) {
utils.CobraFlags(rootCmd, debug.Flags, utils.MetricFlags, logging.Flags)

cfg := &httpcfg.HttpCfg{Enabled: true, StateCache: kvcache.DefaultCoherentConfig}
rootCmd.PersistentFlags().StringVar(&cfg.PrivateApiAddr, "private.api.addr", "127.0.0.1:9090", "private api network address, for example: 127.0.0.1:9090")
rootCmd.PersistentFlags().StringVar(&cfg.PrivateApiAddr, "private.api.addr", "127.0.0.1:9090", "Erigon's components (txpool, rpcdaemon, sentry, downloader, ...) can be deployed as independent Processes on same/another server. Then components will connect to erigon by this internal grpc API. Example: 127.0.0.1:9090")
rootCmd.PersistentFlags().StringVar(&cfg.DataDir, "datadir", "", "path to Erigon working directory")
rootCmd.PersistentFlags().StringVar(&cfg.HttpListenAddress, "http.addr", nodecfg.DefaultHTTPHost, "HTTP-RPC server listening interface")
rootCmd.PersistentFlags().StringVar(&cfg.TLSCertfile, "tls.cert", "", "certificate for client side TLS handshake")
Expand Down Expand Up @@ -352,7 +352,7 @@ func RemoteServices(ctx context.Context, cfg httpcfg.HttpCfg, logger log.Logger,
if agg, err = libstate.NewAggregatorV3(ctx, cfg.Dirs.SnapHistory, cfg.Dirs.Tmp, ethconfig.HistoryV3AggregationStep, db); err != nil {
return nil, nil, nil, nil, nil, nil, nil, ff, nil, fmt.Errorf("create aggregator: %w", err)
}
_ = agg.ReopenFiles()
_ = agg.ReopenFolder()

db.View(context.Background(), func(tx kv.Tx) error {
agg.LogStats(tx, func(endTxNumMinimax uint64) uint64 {
Expand All @@ -374,7 +374,7 @@ func RemoteServices(ctx context.Context, cfg httpcfg.HttpCfg, logger log.Logger,
allSnapshots.LogStat()
}

if err = agg.ReopenFiles(); err != nil {
if err = agg.ReopenFolder(); err != nil {
log.Error("[Snapshots] reopen", "err", err)
} else {
db.View(context.Background(), func(tx kv.Tx) error {
Expand Down
4 changes: 4 additions & 0 deletions cmd/state/commands/erigon4.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ func Erigon4(genesis *core.Genesis, chainConfig *chain2.Config, logger log.Logge
if err3 != nil {
return fmt.Errorf("create aggregator: %w", err3)
}
if err := agg.ReopenFolder(); err != nil {
return err
}

defer agg.Close()

var mode libstate.CommitmentMode
Expand Down
4 changes: 4 additions & 0 deletions cmd/state/commands/history22.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ func History22(genesis *core.Genesis, logger log.Logger) error {
if err != nil {
return fmt.Errorf("create history: %w", err)
}
if err := h.ReopenFolder(); err != nil {
return err
}

defer h.Close()
readDbPath := path.Join(datadirCli, "readdb")
if block == 0 {
Expand Down
2 changes: 1 addition & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ func (s *Ethereum) setUpBlockReader(ctx context.Context, dirs datadir.Dirs, snCo
if err != nil {
return nil, nil, nil, err
}
if err = agg.ReopenFiles(); err != nil {
if err = agg.ReopenFolder(); err != nil {
return nil, nil, nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion eth/stagedsync/stage_execute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func newAgg(t *testing.T) *libstate.AggregatorV3 {
dir, ctx := t.TempDir(), context.Background()
agg, err := libstate.NewAggregatorV3(ctx, dir, dir, ethconfig.HistoryV3AggregationStep, nil)
require.NoError(t, err)
err = agg.ReopenFiles()
err = agg.ReopenFolder()
require.NoError(t, err)
return agg
}
Expand Down
2 changes: 1 addition & 1 deletion eth/stagedsync/stage_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ Finish:
if err := cfg.snapshots.ReopenFolder(); err != nil {
return err
}
if err := cfg.agg.ReopenFiles(); err != nil {
if err := cfg.agg.ReopenFolder(); err != nil {
return err
}

Expand Down
30 changes: 15 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/ledgerwatch/erigon
go 1.18

require (
github.com/ledgerwatch/erigon-lib v0.0.0-20230208030616-e96b599a98e4
github.com/ledgerwatch/erigon-lib v0.0.0-20230209041907-52c880a50ddc
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230120022649-cd9409a200da
github.com/ledgerwatch/log/v3 v3.7.0
github.com/ledgerwatch/secp256k1 v1.0.0
Expand Down Expand Up @@ -78,18 +78,18 @@ require (
github.com/tidwall/btree v1.5.0
github.com/ugorji/go/codec v1.1.13
github.com/ugorji/go/codec/codecgen v1.1.13
github.com/urfave/cli/v2 v2.23.7
github.com/valyala/fastjson v1.6.3
github.com/urfave/cli/v2 v2.24.3
github.com/valyala/fastjson v1.6.4
github.com/xsleonard/go-merkle v1.1.0
go.uber.org/atomic v1.10.0
go.uber.org/zap v1.23.0
golang.org/x/crypto v0.5.0
golang.org/x/exp v0.0.0-20230203172020-98cc5a0785f9
golang.org/x/net v0.5.0
golang.org/x/crypto v0.6.0
golang.org/x/exp v0.0.0-20230206171751-46f607a40771
golang.org/x/net v0.6.0
golang.org/x/sync v0.1.0
golang.org/x/sys v0.4.0
golang.org/x/sys v0.5.0
golang.org/x/time v0.3.0
google.golang.org/grpc v1.52.3
google.golang.org/grpc v1.53.0
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0
google.golang.org/protobuf v1.28.1
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
Expand Down Expand Up @@ -122,7 +122,7 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.2.2 // indirect
github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/containerd/cgroups v1.0.4 // indirect
github.com/coreos/go-systemd/v22 v22.4.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
Expand Down Expand Up @@ -224,7 +224,7 @@ require (
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/raulk/go-watchdog v1.3.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/rs/dnscache v0.0.0-20211102005908-e0241e321417 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
Expand All @@ -239,10 +239,10 @@ require (
go.opentelemetry.io/otel v1.8.0 // indirect
go.opentelemetry.io/otel/trace v1.8.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/mod v0.7.0 // indirect
golang.org/x/text v0.6.0 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/tools v0.5.0 // indirect
google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6 // indirect
google.golang.org/genproto v0.0.0-20230202175211-008b39050e57 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.3.0 // indirect
Expand All @@ -252,10 +252,10 @@ require (
modernc.org/ccgo/v3 v3.16.13 // indirect
modernc.org/libc v1.22.2 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/memory v1.4.0 // indirect
modernc.org/memory v1.5.0 // indirect
modernc.org/opt v0.1.3 // indirect
modernc.org/strutil v1.1.3 // indirect
modernc.org/token v1.0.1 // indirect
modernc.org/token v1.1.0 // indirect
)

replace github.com/tendermint/tendermint => github.com/bnb-chain/tendermint v0.31.12
Loading

0 comments on commit ec52990

Please sign in to comment.