Expose WorkerID

Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
Jakub Sztandera 2020-10-28 20:22:07 +01:00
parent e575b5fe8a
commit ad905fc310
No known key found for this signature in database
GPG Key ID: 9A9AF56F8B3879BA
5 changed files with 23 additions and 19 deletions

View File

@ -781,8 +781,9 @@ type IpldObject struct {
} }
type ActiveSync struct { type ActiveSync struct {
Base *types.TipSet WorkerID uint64
Target *types.TipSet Base *types.TipSet
Target *types.TipSet
Stage SyncStateStage Stage SyncStateStage
Height abi.ChainEpoch Height abi.ChainEpoch

View File

@ -135,7 +135,7 @@ func (sm *syncManager) SetPeerHead(ctx context.Context, p peer.ID, ts *types.Tip
func (sm *syncManager) State() []SyncerStateSnapshot { func (sm *syncManager) State() []SyncerStateSnapshot {
sm.mx.Lock() sm.mx.Lock()
workerStates := make([]*workerState, 0, len(sm.state)) workerStates := make([]*workerState, 0, len(sm.state)+len(sm.history))
for _, ws := range sm.state { for _, ws := range sm.state {
workerStates = append(workerStates, ws) workerStates = append(workerStates, ws)
} }
@ -285,6 +285,7 @@ func (sm *syncManager) spawnWorker(target *types.TipSet) {
ts: target, ts: target,
ss: new(SyncerState), ss: new(SyncerState),
} }
ws.ss.data.WorkerID = id
sm.mx.Lock() sm.mx.Lock()
sm.state[id] = ws sm.state[id] = ws

View File

@ -12,13 +12,14 @@ import (
) )
type SyncerStateSnapshot struct { type SyncerStateSnapshot struct {
Target *types.TipSet WorkerID uint64
Base *types.TipSet Target *types.TipSet
Stage api.SyncStateStage Base *types.TipSet
Height abi.ChainEpoch Stage api.SyncStateStage
Message string Height abi.ChainEpoch
Start time.Time Message string
End time.Time Start time.Time
End time.Time
} }
type SyncerState struct { type SyncerState struct {

View File

@ -45,8 +45,8 @@ var syncStatusCmd = &cli.Command{
} }
fmt.Println("sync status:") fmt.Println("sync status:")
for i, ss := range state.ActiveSyncs { for _, ss := range state.ActiveSyncs {
fmt.Printf("worker %d:\n", i) fmt.Printf("worker %d:\n", ss.WorkerID)
var base, target []cid.Cid var base, target []cid.Cid
var heightDiff int64 var heightDiff int64
var theight abi.ChainEpoch var theight abi.ChainEpoch

View File

@ -37,13 +37,14 @@ func (a *SyncAPI) SyncState(ctx context.Context) (*api.SyncState, error) {
for i := range states { for i := range states {
ss := &states[i] ss := &states[i]
out.ActiveSyncs = append(out.ActiveSyncs, api.ActiveSync{ out.ActiveSyncs = append(out.ActiveSyncs, api.ActiveSync{
Base: ss.Base, WorkerID: ss.WorkerID,
Target: ss.Target, Base: ss.Base,
Stage: ss.Stage, Target: ss.Target,
Height: ss.Height, Stage: ss.Stage,
Start: ss.Start, Height: ss.Height,
End: ss.End, Start: ss.Start,
Message: ss.Message, End: ss.End,
Message: ss.Message,
}) })
} }
return out, nil return out, nil