track last few worker states for debug purposes

This commit is contained in:
vyzo 2020-10-28 14:08:06 +02:00
parent 6266bae1d3
commit ba2512655e

View File

@ -20,6 +20,7 @@ var (
RecentSyncBufferSize = 10 RecentSyncBufferSize = 10
MaxSyncWorkers = 5 MaxSyncWorkers = 5
SyncWorkerHistory = 3
coalesceTipsets = false coalesceTipsets = false
) )
@ -69,6 +70,9 @@ type syncManager struct {
mx sync.Mutex mx sync.Mutex
state map[uint64]*workerState state map[uint64]*workerState
history []*workerState
historyI int
doSync func(context.Context, *types.TipSet) error doSync func(context.Context, *types.TipSet) error
} }
@ -103,6 +107,7 @@ func NewSyncManager(sync SyncFunc) SyncManager {
heads: make(map[peer.ID]*types.TipSet), heads: make(map[peer.ID]*types.TipSet),
state: make(map[uint64]*workerState), state: make(map[uint64]*workerState),
recent: newSyncBuffer(RecentSyncBufferSize), recent: newSyncBuffer(RecentSyncBufferSize),
history: make([]*workerState, SyncWorkerHistory),
doSync: sync, doSync: sync,
} }
@ -134,6 +139,11 @@ func (sm *syncManager) State() []SyncerStateSnapshot {
for _, ws := range sm.state { for _, ws := range sm.state {
workerStates = append(workerStates, ws) workerStates = append(workerStates, ws)
} }
for _, ws := range sm.history {
if ws != nil {
workerStates = append(workerStates, ws)
}
}
sm.mx.Unlock() sm.mx.Unlock()
sort.Slice(workerStates, func(i, j int) bool { sort.Slice(workerStates, func(i, j int) bool {
@ -216,6 +226,11 @@ func (sm *syncManager) handleWorkerStatus(status workerStatus) {
sm.mx.Lock() sm.mx.Lock()
ws := sm.state[status.id] ws := sm.state[status.id]
delete(sm.state, status.id) delete(sm.state, status.id)
// we track the last few workers for debug purposes
sm.history[sm.historyI] = ws
sm.historyI++
sm.historyI %= len(sm.history)
sm.mx.Unlock() sm.mx.Unlock()
if status.err != nil { if status.err != nil {