From 8371344756f26e4d7b6e48025287b32c22ff49aa Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Wed, 8 Jun 2022 20:08:17 +0800 Subject: [PATCH] clean up logging --- cmd/stateSnapshot.go | 2 +- pkg/snapshot/service.go | 22 ++++------------------ pkg/snapshot/tracker.go | 3 ++- 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/cmd/stateSnapshot.go b/cmd/stateSnapshot.go index cc4e88a..72a51fe 100644 --- a/cmd/stateSnapshot.go +++ b/cmd/stateSnapshot.go @@ -56,7 +56,7 @@ func stateSnapshot() { recoveryFile := viper.GetString(snapshot.SNAPSHOT_RECOVERY_FILE_TOML) if recoveryFile == "" { recoveryFile = fmt.Sprintf("./%d_snapshot_recovery", height) - logWithCommand.Infof("no recovery file set, creating default: %s", recoveryFile) + logWithCommand.Infof("no recovery file set, using default: %s", recoveryFile) } pub, err := snapshot.NewPublisher(mode, config) diff --git a/pkg/snapshot/service.go b/pkg/snapshot/service.go index bba80e8..ac759b7 100644 --- a/pkg/snapshot/service.go +++ b/pkg/snapshot/service.go @@ -81,8 +81,6 @@ 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) @@ -94,36 +92,30 @@ 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 } + headerID := header.Hash().String() s.tracker = newTracker(s.recoveryFile, int(params.Workers)) 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)) + log.Debugf("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)", @@ -131,17 +123,13 @@ func (s *Service) CreateSnapshot(params SnapshotParams) error { ) } } else { // nothing to restore - log.Infof("no iterators to restore") + log.Debugf("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) } } @@ -153,8 +141,6 @@ func (s *Service) CreateSnapshot(params SnapshotParams) error { } }() - log.Infof("num iters %d", len(iters)) - if len(iters) > 0 { return s.createSnapshotAsync(iters, headerID) } else { diff --git a/pkg/snapshot/tracker.go b/pkg/snapshot/tracker.go index e66b8d0..7192eec 100644 --- a/pkg/snapshot/tracker.go +++ b/pkg/snapshot/tracker.go @@ -72,7 +72,7 @@ func (tr *iteratorTracker) tracked(it trie.NodeIterator) (ret *trackedIter) { // dumps iterator path and bounds to a text file so it can be restored later func (tr *iteratorTracker) dump() error { - log.Info("Dumping recovery state to: ", tr.recoveryFile) + log.Debug("Dumping recovery state to: ", tr.recoveryFile) var rows [][]string for it, _ := range tr.started { var endPath []byte @@ -103,6 +103,7 @@ func (tr *iteratorTracker) restore(tree state.Trie) ([]trie.NodeIterator, error) } return nil, err } + log.Debug("Restoring recovery state from: ", tr.recoveryFile) defer file.Close() in := csv.NewReader(file) in.FieldsPerRecord = 2