add duration tracking to sync status

This commit is contained in:
whyrusleeping 2019-12-03 20:59:41 -08:00
parent 034f0cc479
commit c302051bc2
4 changed files with 32 additions and 8 deletions

View File

@ -2,6 +2,7 @@ package api
import ( import (
"context" "context"
"time"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"github.com/ipfs/go-filestore" "github.com/ipfs/go-filestore"
@ -263,6 +264,10 @@ type ActiveSync struct {
Stage SyncStateStage Stage SyncStateStage
Height uint64 Height uint64
Start time.Time
End time.Time
Message string
} }
type SyncState struct { type SyncState struct {

View File

@ -144,7 +144,11 @@ func (syncer *Syncer) InformNewHead(from peer.ID, fts *store.FullTipSet) {
bestPweight := syncer.store.GetHeaviestTipSet().Blocks()[0].ParentWeight bestPweight := syncer.store.GetHeaviestTipSet().Blocks()[0].ParentWeight
targetWeight := fts.TipSet().Blocks()[0].ParentWeight targetWeight := fts.TipSet().Blocks()[0].ParentWeight
if targetWeight.LessThan(bestPweight) { if targetWeight.LessThan(bestPweight) {
log.Warn("incoming tipset does not appear to be better than our best chain, ignoring for now") var miners []string
for _, blk := range fts.TipSet().Blocks() {
miners = append(miners, blk.Miner.String())
}
log.Warnf("incoming tipset from %s does not appear to be better than our best chain, ignoring for now", miners)
return return
} }

View File

@ -26,14 +26,14 @@ var syncStatusCmd = &cli.Command{
Name: "status", Name: "status",
Usage: "check sync status", Usage: "check sync status",
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
api, closer, err := GetFullNodeAPI(cctx) apic, closer, err := GetFullNodeAPI(cctx)
if err != nil { if err != nil {
return err return err
} }
defer closer() defer closer()
ctx := ReqContext(cctx) ctx := ReqContext(cctx)
state, err := api.SyncState(ctx) state, err := apic.SyncState(ctx)
if err != nil { if err != nil {
return err return err
} }
@ -43,6 +43,7 @@ var syncStatusCmd = &cli.Command{
fmt.Printf("worker %d:\n", i) fmt.Printf("worker %d:\n", i)
var base, target []cid.Cid var base, target []cid.Cid
var heightDiff int64 var heightDiff int64
var theight uint64
if ss.Base != nil { if ss.Base != nil {
base = ss.Base.Cids() base = ss.Base.Cids()
heightDiff = int64(ss.Base.Height()) heightDiff = int64(ss.Base.Height())
@ -50,14 +51,25 @@ var syncStatusCmd = &cli.Command{
if ss.Target != nil { if ss.Target != nil {
target = ss.Target.Cids() target = ss.Target.Cids()
heightDiff = int64(ss.Target.Height()) - heightDiff heightDiff = int64(ss.Target.Height()) - heightDiff
theight = ss.Target.Height()
} else { } else {
heightDiff = 0 heightDiff = 0
} }
fmt.Printf("\tBase:\t%s\n", base) fmt.Printf("\tBase:\t%s\n", base)
fmt.Printf("\tTarget:\t%s\n", target) fmt.Printf("\tTarget:\t%s (%d)\n", target, theight)
fmt.Printf("\tHeight diff:\t%d\n", heightDiff) fmt.Printf("\tHeight diff:\t%d\n", heightDiff)
fmt.Printf("\tStage: %s\n", chain.SyncStageString(ss.Stage)) fmt.Printf("\tStage: %s\n", chain.SyncStageString(ss.Stage))
fmt.Printf("\tHeight: %d\n", ss.Height) fmt.Printf("\tHeight: %d\n", ss.Height)
if ss.End.IsZero() {
if !ss.Start.IsZero() {
fmt.Printf("\tElapsed: %s\n", time.Since(ss.Start))
}
} else {
fmt.Printf("\tElapsed: %s\n", ss.End.Sub(ss.Start))
}
if ss.Stage == api.StageSyncErrored {
fmt.Printf("\tError: %s\n", ss.Message)
}
} }
return nil return nil
}, },

View File

@ -26,10 +26,13 @@ func (a *SyncAPI) SyncState(ctx context.Context) (*api.SyncState, error) {
for _, ss := range states { for _, ss := range states {
out.ActiveSyncs = append(out.ActiveSyncs, api.ActiveSync{ out.ActiveSyncs = append(out.ActiveSyncs, api.ActiveSync{
Base: ss.Base, Base: ss.Base,
Target: ss.Target, Target: ss.Target,
Stage: ss.Stage, Stage: ss.Stage,
Height: ss.Height, Height: ss.Height,
Start: ss.Start,
End: ss.End,
Message: ss.Message,
}) })
} }
return out, nil return out, nil