From f235a1751ac2002bf293b789dc46d8d1582ef6d4 Mon Sep 17 00:00:00 2001 From: Ashwin Phatak Date: Thu, 26 May 2022 15:50:42 +0530 Subject: [PATCH] Log progress info --- .gitignore | 2 ++ Makefile | 5 ++++- README.md | 5 +++++ cmd/stateSnapshot.go | 2 +- pkg/snapshot/service.go | 21 ++++++++++++++++++++- 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 5d7a86c..385c906 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .idea/ +.vscode/ ipld-eth-state-snapshot +mocks/ diff --git a/Makefile b/Makefile index eebd422..b612d53 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ MOCKS_DIR = $(CURDIR)/mocks mockgen_cmd=mockgen -.PHONY: mocks +.PHONY: mocks test mocks: mocks/snapshot/publisher.go @@ -14,3 +14,6 @@ clean: build: go fmt ./... go build + +test: mocks + go clean -testcache && go test -v ./... diff --git a/README.md b/README.md index 1c0bed2..738aeb2 100644 --- a/README.md +++ b/README.md @@ -44,3 +44,8 @@ Config format: httpPort = 9101 # prometheus http port (default: 8086) dbStats = true # enable prometheus db stats (default: false) ``` + +## Tests + +* Install [mockgen](https://github.com/golang/mock#installation) +* `make test` diff --git a/cmd/stateSnapshot.go b/cmd/stateSnapshot.go index c44d84e..cc4e88a 100644 --- a/cmd/stateSnapshot.go +++ b/cmd/stateSnapshot.go @@ -44,7 +44,7 @@ func stateSnapshot() { mode := snapshot.SnapshotMode(modeStr) config, err := snapshot.NewConfig(mode) if err != nil { - logWithCommand.Fatal("unable to initialize config: %v", err) + logWithCommand.Fatalf("unable to initialize config: %v", err) } logWithCommand.Infof("opening levelDB and ancient data at %s and %s", config.Eth.LevelDBPath, config.Eth.AncientDBPath) diff --git a/pkg/snapshot/service.go b/pkg/snapshot/service.go index 3e269a9..be7d903 100644 --- a/pkg/snapshot/service.go +++ b/pkg/snapshot/service.go @@ -81,6 +81,8 @@ type SnapshotParams struct { } func (s *Service) CreateSnapshot(params SnapshotParams) error { + log.Infof("createSnapshot BEGIN %v", params) + // extract header from lvldb and publish to PG-IPFS // hold onto the headerID so that we can link the state nodes to this header log.Infof("Creating snapshot at height %d", params.Height) @@ -92,12 +94,16 @@ func (s *Service) CreateSnapshot(params SnapshotParams) error { log.Infof("head hash: %s head height: %d", hash.Hex(), params.Height) + log.Infof("publish header") err := s.ipfsPublisher.PublishHeader(header) if err != nil { return err } + log.Infof("opening trie...") tree, err := s.stateDB.OpenTrie(header.Root) + log.Infof("opened trie") + if err != nil { return err } @@ -106,13 +112,19 @@ func (s *Service) CreateSnapshot(params SnapshotParams) error { go s.tracker.run() go s.tracker.captureSignal() + log.Infof("after goroutines start") + var iters []trie.NodeIterator // attempt to restore from recovery file if it exists + log.Infof("restoring iterators from recovery file...") iters, err = s.tracker.restore(tree) + if err != nil { + log.Errorf("restore error: %s", err.Error()) return err } if iters != nil { + log.Infof("restored iterators; count: %d", len(iters)) if params.Workers < uint(len(iters)) { return fmt.Errorf( "number of recovered workers (%d) is greater than number configured (%d)", @@ -120,12 +132,17 @@ func (s *Service) CreateSnapshot(params SnapshotParams) error { ) } } else { // nothing to restore + log.Infof("no iterators to restore") if params.Workers > 1 { + log.Infof("creating %d subtrie iterators...", params.Workers) iters = iter.SubtrieIterators(tree, params.Workers) + log.Infof("created %d subtrie iterators", params.Workers) } else { + log.Infof("creating node iterators") iters = []trie.NodeIterator{tree.NodeIterator(nil)} } for i, it := range iters { + log.Infof("tracked iterator %d", i) iters[i] = s.tracker.tracked(it) } } @@ -133,10 +150,12 @@ func (s *Service) CreateSnapshot(params SnapshotParams) error { defer func() { err := s.tracker.haltAndDump() if err != nil { - log.Error("failed to write recovery file: ", err) + log.Errorf("failed to write recovery file: %v", err) } }() + log.Infof("num iters %d", len(iters)) + if len(iters) > 0 { return s.createSnapshotAsync(iters, headerID) } else {