-
Notifications
You must be signed in to change notification settings - Fork 644
Create Live Snapshot without shutting down node #2816
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
b8e1bfd
3a2957d
989df29
37bb881
a1a558c
5614d67
af4be8d
a76fa30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ import ( | |
"path/filepath" | ||
"reflect" | ||
"strings" | ||
"sync" | ||
"syscall" | ||
"time" | ||
|
||
|
@@ -36,6 +37,7 @@ import ( | |
_ "github.com/ethereum/go-ethereum/eth/tracers/js" | ||
_ "github.com/ethereum/go-ethereum/eth/tracers/native" | ||
"github.com/ethereum/go-ethereum/ethclient" | ||
"github.com/ethereum/go-ethereum/ethdb" | ||
"github.com/ethereum/go-ethereum/graphql" | ||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/ethereum/go-ethereum/metrics" | ||
|
@@ -641,6 +643,11 @@ func mainImpl() int { | |
deferFuncs = []func(){func() { currentNode.StopAndWait() }} | ||
} | ||
|
||
// Live db snapshot creation is only supported on archive nodes | ||
if nodeConfig.Execution.Caching.Archive { | ||
go liveDBSnapshotter(ctx, chainDb, arbDb, execNode.ExecEngine.CreateBlocksMutex(), func() string { return liveNodeConfig.Get().SnapshotDir }) | ||
} | ||
|
||
sigint := make(chan os.Signal, 1) | ||
signal.Notify(sigint, os.Interrupt, syscall.SIGTERM) | ||
|
||
|
@@ -674,6 +681,43 @@ func mainImpl() int { | |
return 0 | ||
} | ||
|
||
func liveDBSnapshotter(ctx context.Context, chainDb, arbDb ethdb.Database, createBlocksMutex *sync.Mutex, snapshotDirGetter func() string) { | ||
sigusr2 := make(chan os.Signal, 1) | ||
signal.Notify(sigusr2, syscall.SIGUSR2) | ||
|
||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return | ||
case <-sigusr2: | ||
log.Info("Live databases snapshot creation triggered by SIGUSR2") | ||
} | ||
|
||
snapshotDir := snapshotDirGetter() | ||
if snapshotDir == "" { | ||
log.Error("Aborting live databases snapshot creation as destination directory is empty, try updating --snapshot-dir in the config file") | ||
continue | ||
} | ||
|
||
createBlocksMutex.Lock() | ||
|
||
log.Info("Beginning snapshot creation for l2chaindata, ancient and wasm databases") | ||
err := chainDb.CreateDBSnapshot(snapshotDir) | ||
createBlocksMutex.Unlock() | ||
if err != nil { | ||
log.Error("Snapshot creation for l2chaindata, ancient and wasm databases failed", "err", err) | ||
continue | ||
} | ||
log.Info("Live snapshot of l2chaindata, ancient and wasm databases were successfully created") | ||
|
||
log.Info("Beginning snapshot creation for arbitrumdata database") | ||
if err := arbDb.CreateDBSnapshot(snapshotDir); err != nil { | ||
log.Error("Snapshot creation for arbitrumdata database failed", "err", err) | ||
} else { | ||
log.Info("Live snapshot of arbitrumdata database was successfully created") | ||
} | ||
} | ||
} | ||
|
||
type NodeConfig struct { | ||
Conf genericconf.ConfConfig `koanf:"conf" reload:"hot"` | ||
Node arbnode.Config `koanf:"node" reload:"hot"` | ||
|
@@ -697,6 +741,7 @@ type NodeConfig struct { | |
Init conf.InitConfig `koanf:"init"` | ||
Rpc genericconf.RpcConfig `koanf:"rpc"` | ||
BlocksReExecutor blocksreexecutor.Config `koanf:"blocks-reexecutor"` | ||
SnapshotDir string `koanf:"snapshot-dir" reload:"hot"` | ||
} | ||
|
||
var NodeConfigDefault = NodeConfig{ | ||
|
@@ -722,6 +767,7 @@ var NodeConfigDefault = NodeConfig{ | |
PProf: false, | ||
PprofCfg: genericconf.PProfDefault, | ||
BlocksReExecutor: blocksreexecutor.DefaultConfig, | ||
SnapshotDir: "", | ||
} | ||
|
||
func NodeConfigAddOptions(f *flag.FlagSet) { | ||
|
@@ -748,6 +794,8 @@ func NodeConfigAddOptions(f *flag.FlagSet) { | |
conf.InitConfigAddOptions("init", f) | ||
genericconf.RpcConfigAddOptions("rpc", f) | ||
blocksreexecutor.ConfigAddOptions("blocks-reexecutor", f) | ||
|
||
f.String("snapshot-dir", NodeConfigDefault.SnapshotDir, "directory in which snapshot of databases would be stored") | ||
} | ||
|
||
func (c *NodeConfig) ResolveDirectoryNames() error { | ||
|
+4 −0 | arbitrum/recordingdb.go | |
+20 −0 | core/rawdb/database.go | |
+64 −0 | core/rawdb/freezer.go | |
+4 −0 | core/rawdb/freezer_memory.go | |
+5 −0 | core/rawdb/freezer_resettable.go | |
+6 −0 | core/rawdb/table.go | |
+1 −0 | ethdb/database.go | |
+4 −0 | ethdb/leveldb/fake_leveldb.go | |
+4 −0 | ethdb/leveldb/leveldb.go | |
+4 −0 | ethdb/memorydb/memorydb.go | |
+6 −0 | ethdb/pebble/pebble.go | |
+6 −0 | ethdb/remotedb/remotedb.go | |
+3 −0 | ethdb/snapshot.go | |
+3 −0 | trie/trie_test.go |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that:
liveDBSnapshotter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Want a config option to enable the snapshotter, off by default.