clean up logging

This commit is contained in:
Roy Crihfield 2022-06-08 20:08:17 +08:00
parent ef391d8d31
commit 8371344756
3 changed files with 7 additions and 20 deletions

View File

@ -56,7 +56,7 @@ func stateSnapshot() {
recoveryFile := viper.GetString(snapshot.SNAPSHOT_RECOVERY_FILE_TOML) recoveryFile := viper.GetString(snapshot.SNAPSHOT_RECOVERY_FILE_TOML)
if recoveryFile == "" { if recoveryFile == "" {
recoveryFile = fmt.Sprintf("./%d_snapshot_recovery", height) 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) pub, err := snapshot.NewPublisher(mode, config)

View File

@ -81,8 +81,6 @@ type SnapshotParams struct {
} }
func (s *Service) CreateSnapshot(params SnapshotParams) error { func (s *Service) CreateSnapshot(params SnapshotParams) error {
log.Infof("createSnapshot BEGIN %v", params)
// extract header from lvldb and publish to PG-IPFS // extract header from lvldb and publish to PG-IPFS
// hold onto the headerID so that we can link the state nodes to this header // hold onto the headerID so that we can link the state nodes to this header
log.Infof("Creating snapshot at height %d", params.Height) 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("head hash: %s head height: %d", hash.Hex(), params.Height)
log.Infof("publish header")
err := s.ipfsPublisher.PublishHeader(header) err := s.ipfsPublisher.PublishHeader(header)
if err != nil { if err != nil {
return err return err
} }
log.Infof("opening trie...")
tree, err := s.stateDB.OpenTrie(header.Root) tree, err := s.stateDB.OpenTrie(header.Root)
log.Infof("opened trie")
if err != nil { if err != nil {
return err return err
} }
headerID := header.Hash().String() headerID := header.Hash().String()
s.tracker = newTracker(s.recoveryFile, int(params.Workers)) s.tracker = newTracker(s.recoveryFile, int(params.Workers))
s.tracker.captureSignal() s.tracker.captureSignal()
log.Infof("after goroutines start")
var iters []trie.NodeIterator var iters []trie.NodeIterator
// attempt to restore from recovery file if it exists // attempt to restore from recovery file if it exists
log.Infof("restoring iterators from recovery file...")
iters, err = s.tracker.restore(tree) iters, err = s.tracker.restore(tree)
if err != nil { if err != nil {
log.Errorf("restore error: %s", err.Error()) log.Errorf("restore error: %s", err.Error())
return err return err
} }
if iters != nil { 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)) { if params.Workers < uint(len(iters)) {
return fmt.Errorf( return fmt.Errorf(
"number of recovered workers (%d) is greater than number configured (%d)", "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 } else { // nothing to restore
log.Infof("no iterators to restore") log.Debugf("no iterators to restore")
if params.Workers > 1 { if params.Workers > 1 {
log.Infof("creating %d subtrie iterators...", params.Workers)
iters = iter.SubtrieIterators(tree, params.Workers) iters = iter.SubtrieIterators(tree, params.Workers)
log.Infof("created %d subtrie iterators", params.Workers)
} else { } else {
log.Infof("creating node iterators")
iters = []trie.NodeIterator{tree.NodeIterator(nil)} iters = []trie.NodeIterator{tree.NodeIterator(nil)}
} }
for i, it := range iters { for i, it := range iters {
log.Infof("tracked iterator %d", i)
iters[i] = s.tracker.tracked(it) 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 { if len(iters) > 0 {
return s.createSnapshotAsync(iters, headerID) return s.createSnapshotAsync(iters, headerID)
} else { } else {

View File

@ -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 // dumps iterator path and bounds to a text file so it can be restored later
func (tr *iteratorTracker) dump() error { func (tr *iteratorTracker) dump() error {
log.Info("Dumping recovery state to: ", tr.recoveryFile) log.Debug("Dumping recovery state to: ", tr.recoveryFile)
var rows [][]string var rows [][]string
for it, _ := range tr.started { for it, _ := range tr.started {
var endPath []byte var endPath []byte
@ -103,6 +103,7 @@ func (tr *iteratorTracker) restore(tree state.Trie) ([]trie.NodeIterator, error)
} }
return nil, err return nil, err
} }
log.Debug("Restoring recovery state from: ", tr.recoveryFile)
defer file.Close() defer file.Close()
in := csv.NewReader(file) in := csv.NewReader(file)
in.FieldsPerRecord = 2 in.FieldsPerRecord = 2