Merge pull request #18 from filecoin-project/feat/no-ffi-workerinfo
Move WorkerInfo to not require importing ffi
This commit is contained in:
commit
9404c859cb
@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/filecoin-project/sector-storage/ffiwrapper"
|
"github.com/filecoin-project/sector-storage/ffiwrapper"
|
||||||
"github.com/filecoin-project/sector-storage/sealtasks"
|
"github.com/filecoin-project/sector-storage/sealtasks"
|
||||||
"github.com/filecoin-project/sector-storage/stores"
|
"github.com/filecoin-project/sector-storage/stores"
|
||||||
|
"github.com/filecoin-project/sector-storage/storiface"
|
||||||
)
|
)
|
||||||
|
|
||||||
var pathTypes = []stores.SectorFileType{stores.FTUnsealed, stores.FTSealed, stores.FTCache}
|
var pathTypes = []stores.SectorFileType{stores.FTUnsealed, stores.FTSealed, stores.FTCache}
|
||||||
@ -167,7 +168,7 @@ func (l *LocalWorker) Paths(ctx context.Context) ([]stores.StoragePath, error) {
|
|||||||
return l.localStore.Local(ctx)
|
return l.localStore.Local(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LocalWorker) Info(context.Context) (WorkerInfo, error) {
|
func (l *LocalWorker) Info(context.Context) (storiface.WorkerInfo, error) {
|
||||||
hostname, err := os.Hostname() // TODO: allow overriding from config
|
hostname, err := os.Hostname() // TODO: allow overriding from config
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -180,17 +181,17 @@ func (l *LocalWorker) Info(context.Context) (WorkerInfo, error) {
|
|||||||
|
|
||||||
h, err := sysinfo.Host()
|
h, err := sysinfo.Host()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return WorkerInfo{}, xerrors.Errorf("getting host info: %w", err)
|
return storiface.WorkerInfo{}, xerrors.Errorf("getting host info: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
mem, err := h.Memory()
|
mem, err := h.Memory()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return WorkerInfo{}, xerrors.Errorf("getting memory info: %w", err)
|
return storiface.WorkerInfo{}, xerrors.Errorf("getting memory info: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return WorkerInfo{
|
return storiface.WorkerInfo{
|
||||||
Hostname: hostname,
|
Hostname: hostname,
|
||||||
Resources: WorkerResources{
|
Resources: storiface.WorkerResources{
|
||||||
MemPhysical: mem.Total,
|
MemPhysical: mem.Total,
|
||||||
MemSwap: mem.VirtualTotal,
|
MemSwap: mem.VirtualTotal,
|
||||||
MemReserved: mem.VirtualUsed + mem.Total - mem.Available, // TODO: sub this process
|
MemReserved: mem.VirtualUsed + mem.Total - mem.Available, // TODO: sub this process
|
||||||
|
18
manager.go
18
manager.go
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/filecoin-project/sector-storage/ffiwrapper"
|
"github.com/filecoin-project/sector-storage/ffiwrapper"
|
||||||
"github.com/filecoin-project/sector-storage/sealtasks"
|
"github.com/filecoin-project/sector-storage/sealtasks"
|
||||||
"github.com/filecoin-project/sector-storage/stores"
|
"github.com/filecoin-project/sector-storage/stores"
|
||||||
|
"github.com/filecoin-project/sector-storage/storiface"
|
||||||
)
|
)
|
||||||
|
|
||||||
var log = logging.Logger("advmgr")
|
var log = logging.Logger("advmgr")
|
||||||
@ -35,26 +36,11 @@ type Worker interface {
|
|||||||
// Returns paths accessible to the worker
|
// Returns paths accessible to the worker
|
||||||
Paths(context.Context) ([]stores.StoragePath, error)
|
Paths(context.Context) ([]stores.StoragePath, error)
|
||||||
|
|
||||||
Info(context.Context) (WorkerInfo, error)
|
Info(context.Context) (storiface.WorkerInfo, error)
|
||||||
|
|
||||||
Close() error
|
Close() error
|
||||||
}
|
}
|
||||||
|
|
||||||
type WorkerInfo struct {
|
|
||||||
Hostname string
|
|
||||||
|
|
||||||
Resources WorkerResources
|
|
||||||
}
|
|
||||||
|
|
||||||
type WorkerResources struct {
|
|
||||||
MemPhysical uint64
|
|
||||||
MemSwap uint64
|
|
||||||
|
|
||||||
MemReserved uint64 // Used by system / other processes
|
|
||||||
|
|
||||||
GPUs []string
|
|
||||||
}
|
|
||||||
|
|
||||||
type SectorManager interface {
|
type SectorManager interface {
|
||||||
SectorSize() abi.SectorSize
|
SectorSize() abi.SectorSize
|
||||||
|
|
||||||
|
3
sched.go
3
sched.go
@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||||
|
|
||||||
"github.com/filecoin-project/sector-storage/sealtasks"
|
"github.com/filecoin-project/sector-storage/sealtasks"
|
||||||
|
"github.com/filecoin-project/sector-storage/storiface"
|
||||||
)
|
)
|
||||||
|
|
||||||
const mib = 1 << 20
|
const mib = 1 << 20
|
||||||
@ -39,7 +40,7 @@ func (r *workerRequest) respond(resp workerResponse) {
|
|||||||
type workerHandle struct {
|
type workerHandle struct {
|
||||||
w Worker
|
w Worker
|
||||||
|
|
||||||
info WorkerInfo
|
info storiface.WorkerInfo
|
||||||
|
|
||||||
memUsedMin uint64
|
memUsedMin uint64
|
||||||
memUsedMax uint64
|
memUsedMax uint64
|
||||||
|
15
stats.go
15
stats.go
@ -1,22 +1,15 @@
|
|||||||
package sectorstorage
|
package sectorstorage
|
||||||
|
|
||||||
type WorkerStats struct {
|
import "github.com/filecoin-project/sector-storage/storiface"
|
||||||
Info WorkerInfo
|
|
||||||
|
|
||||||
MemUsedMin uint64
|
func (m *Manager) WorkerStats() map[uint64]storiface.WorkerStats {
|
||||||
MemUsedMax uint64
|
|
||||||
GpuUsed bool
|
|
||||||
CpuUse int
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Manager) WorkerStats() map[uint64]WorkerStats {
|
|
||||||
m.workersLk.Lock()
|
m.workersLk.Lock()
|
||||||
defer m.workersLk.Unlock()
|
defer m.workersLk.Unlock()
|
||||||
|
|
||||||
out := map[uint64]WorkerStats{}
|
out := map[uint64]storiface.WorkerStats{}
|
||||||
|
|
||||||
for id, handle := range m.workers {
|
for id, handle := range m.workers {
|
||||||
out[uint64(id)] = WorkerStats{
|
out[uint64(id)] = storiface.WorkerStats{
|
||||||
Info: handle.info,
|
Info: handle.info,
|
||||||
MemUsedMin: handle.memUsedMin,
|
MemUsedMin: handle.memUsedMin,
|
||||||
MemUsedMax: handle.memUsedMax,
|
MemUsedMax: handle.memUsedMax,
|
||||||
|
25
storiface/worker.go
Normal file
25
storiface/worker.go
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package storiface
|
||||||
|
|
||||||
|
type WorkerInfo struct {
|
||||||
|
Hostname string
|
||||||
|
|
||||||
|
Resources WorkerResources
|
||||||
|
}
|
||||||
|
|
||||||
|
type WorkerResources struct {
|
||||||
|
MemPhysical uint64
|
||||||
|
MemSwap uint64
|
||||||
|
|
||||||
|
MemReserved uint64 // Used by system / other processes
|
||||||
|
|
||||||
|
GPUs []string
|
||||||
|
}
|
||||||
|
|
||||||
|
type WorkerStats struct {
|
||||||
|
Info WorkerInfo
|
||||||
|
|
||||||
|
MemUsedMin uint64
|
||||||
|
MemUsedMax uint64
|
||||||
|
GpuUsed bool
|
||||||
|
CpuUse int
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user