2020-08-17 13:26:18 +00:00
|
|
|
package sectorstorage
|
2020-03-23 14:56:22 +00:00
|
|
|
|
2020-08-27 21:14:33 +00:00
|
|
|
import (
|
2022-03-18 20:31:15 +00:00
|
|
|
"context"
|
2020-09-23 17:26:26 +00:00
|
|
|
"time"
|
2020-09-30 17:32:19 +00:00
|
|
|
|
2020-10-18 10:35:44 +00:00
|
|
|
"github.com/google/uuid"
|
|
|
|
|
2022-03-18 20:31:15 +00:00
|
|
|
"github.com/filecoin-project/lotus/extern/sector-storage/sealtasks"
|
2020-09-30 17:32:19 +00:00
|
|
|
"github.com/filecoin-project/lotus/extern/sector-storage/storiface"
|
2020-08-27 21:14:33 +00:00
|
|
|
)
|
2020-03-23 14:56:22 +00:00
|
|
|
|
2022-03-18 20:31:15 +00:00
|
|
|
func (m *Manager) WorkerStats(ctx context.Context) map[uuid.UUID]storiface.WorkerStats {
|
2020-08-13 09:31:18 +00:00
|
|
|
m.sched.workersLk.RLock()
|
2020-03-23 14:56:22 +00:00
|
|
|
|
2020-10-18 10:35:44 +00:00
|
|
|
out := map[uuid.UUID]storiface.WorkerStats{}
|
2020-03-23 14:56:22 +00:00
|
|
|
|
2022-05-18 13:47:08 +00:00
|
|
|
cb := func(ctx context.Context, id storiface.WorkerID, handle *WorkerHandle) {
|
2021-09-15 13:34:50 +00:00
|
|
|
handle.lk.Lock()
|
2022-03-18 20:31:15 +00:00
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(ctx, 3*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
tt, err := handle.workerRpc.TaskTypes(ctx)
|
|
|
|
var taskList []sealtasks.TaskType
|
|
|
|
if err != nil {
|
|
|
|
log.Warnw("getting worker task types in WorkerStats", "error", err)
|
|
|
|
} else {
|
|
|
|
for taskType := range tt {
|
|
|
|
taskList = append(taskList, taskType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-18 10:35:44 +00:00
|
|
|
out[uuid.UUID(id)] = storiface.WorkerStats{
|
2022-05-18 13:47:08 +00:00
|
|
|
Info: handle.Info,
|
2022-03-18 20:31:15 +00:00
|
|
|
Tasks: taskList,
|
2022-05-18 13:47:08 +00:00
|
|
|
Enabled: handle.Enabled,
|
2020-04-27 20:43:42 +00:00
|
|
|
MemUsedMin: handle.active.memUsedMin,
|
|
|
|
MemUsedMax: handle.active.memUsedMax,
|
|
|
|
GpuUsed: handle.active.gpuUsed,
|
|
|
|
CpuUse: handle.active.cpuUse,
|
2020-03-23 14:56:22 +00:00
|
|
|
}
|
2021-09-15 13:34:50 +00:00
|
|
|
handle.lk.Unlock()
|
2020-03-23 14:56:22 +00:00
|
|
|
}
|
|
|
|
|
2022-05-18 13:47:08 +00:00
|
|
|
for id, handle := range m.sched.Workers {
|
2022-03-18 20:31:15 +00:00
|
|
|
cb(ctx, id, handle)
|
2021-07-27 03:15:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m.sched.workersLk.RUnlock()
|
|
|
|
|
|
|
|
//list post workers
|
2022-03-18 20:31:15 +00:00
|
|
|
m.winningPoStSched.WorkerStats(ctx, cb)
|
|
|
|
m.windowPoStSched.WorkerStats(ctx, cb)
|
2020-03-23 14:56:22 +00:00
|
|
|
return out
|
|
|
|
}
|
2020-07-21 18:01:25 +00:00
|
|
|
|
2020-10-18 10:35:44 +00:00
|
|
|
func (m *Manager) WorkerJobs() map[uuid.UUID][]storiface.WorkerJob {
|
|
|
|
out := map[uuid.UUID][]storiface.WorkerJob{}
|
2020-09-23 17:26:26 +00:00
|
|
|
calls := map[storiface.CallID]struct{}{}
|
2020-07-21 18:01:25 +00:00
|
|
|
|
2021-10-15 19:26:35 +00:00
|
|
|
running, preparing := m.sched.workTracker.Running()
|
|
|
|
|
|
|
|
for _, t := range running {
|
|
|
|
out[uuid.UUID(t.worker)] = append(out[uuid.UUID(t.worker)], t.job)
|
|
|
|
calls[t.job.ID] = struct{}{}
|
|
|
|
}
|
|
|
|
for _, t := range preparing {
|
2020-10-18 10:35:44 +00:00
|
|
|
out[uuid.UUID(t.worker)] = append(out[uuid.UUID(t.worker)], t.job)
|
2020-09-23 17:26:26 +00:00
|
|
|
calls[t.job.ID] = struct{}{}
|
2020-09-23 12:56:37 +00:00
|
|
|
}
|
2020-08-27 21:14:33 +00:00
|
|
|
|
2020-09-23 17:26:26 +00:00
|
|
|
m.sched.workersLk.RLock()
|
|
|
|
|
2022-05-18 13:47:08 +00:00
|
|
|
for id, handle := range m.sched.Workers {
|
2020-08-27 21:14:33 +00:00
|
|
|
handle.wndLk.Lock()
|
2020-08-28 16:26:17 +00:00
|
|
|
for wi, window := range handle.activeWindows {
|
2022-05-18 13:47:08 +00:00
|
|
|
for _, request := range window.Todo {
|
2020-10-18 10:35:44 +00:00
|
|
|
out[uuid.UUID(id)] = append(out[uuid.UUID(id)], storiface.WorkerJob{
|
2020-09-07 14:12:46 +00:00
|
|
|
ID: storiface.UndefCall,
|
2022-05-18 13:47:08 +00:00
|
|
|
Sector: request.Sector.ID,
|
|
|
|
Task: request.TaskType,
|
2021-10-15 19:04:03 +00:00
|
|
|
RunWait: wi + 2,
|
2020-08-27 21:14:33 +00:00
|
|
|
Start: request.start,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
handle.wndLk.Unlock()
|
2020-07-21 18:01:25 +00:00
|
|
|
}
|
|
|
|
|
2020-09-23 17:26:26 +00:00
|
|
|
m.sched.workersLk.RUnlock()
|
|
|
|
|
|
|
|
m.workLk.Lock()
|
|
|
|
defer m.workLk.Unlock()
|
|
|
|
|
2020-09-24 09:55:11 +00:00
|
|
|
for id, work := range m.callToWork {
|
2020-09-23 17:26:26 +00:00
|
|
|
_, found := calls[id]
|
|
|
|
if found {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-11-09 22:09:04 +00:00
|
|
|
var ws WorkState
|
|
|
|
if err := m.work.Get(work).Get(&ws); err != nil {
|
|
|
|
log.Errorf("WorkerJobs: get work %s: %+v", work, err)
|
|
|
|
}
|
|
|
|
|
2020-11-09 22:38:20 +00:00
|
|
|
wait := storiface.RWRetWait
|
2020-11-09 22:13:29 +00:00
|
|
|
if _, ok := m.results[work]; ok {
|
2020-11-09 22:38:20 +00:00
|
|
|
wait = storiface.RWReturned
|
|
|
|
}
|
|
|
|
if ws.Status == wsDone {
|
|
|
|
wait = storiface.RWRetDone
|
2020-11-09 22:13:29 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 10:35:44 +00:00
|
|
|
out[uuid.UUID{}] = append(out[uuid.UUID{}], storiface.WorkerJob{
|
2020-11-09 22:09:04 +00:00
|
|
|
ID: id,
|
|
|
|
Sector: id.Sector,
|
|
|
|
Task: work.Method,
|
2020-11-09 22:13:29 +00:00
|
|
|
RunWait: wait,
|
2020-11-09 22:09:04 +00:00
|
|
|
Start: time.Unix(ws.StartTime, 0),
|
|
|
|
Hostname: ws.WorkerHostname,
|
2020-09-23 17:26:26 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-07-21 18:01:25 +00:00
|
|
|
return out
|
|
|
|
}
|