2020-04-23 22:16:21 +00:00
|
|
|
package storiface
|
|
|
|
|
2020-07-21 18:01:25 +00:00
|
|
|
import (
|
2020-09-06 16:47:16 +00:00
|
|
|
"context"
|
2020-09-14 07:44:55 +00:00
|
|
|
"fmt"
|
2020-09-06 16:47:16 +00:00
|
|
|
"io"
|
2020-07-21 18:01:25 +00:00
|
|
|
"time"
|
|
|
|
|
2020-09-06 16:47:16 +00:00
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/ipfs/go-cid"
|
|
|
|
|
2020-09-07 03:49:10 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2020-09-06 16:47:16 +00:00
|
|
|
"github.com/filecoin-project/specs-storage/storage"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/extern/sector-storage/sealtasks"
|
2020-07-21 18:01:25 +00:00
|
|
|
)
|
|
|
|
|
2020-04-23 22:16:21 +00:00
|
|
|
type WorkerInfo struct {
|
|
|
|
Hostname string
|
|
|
|
|
|
|
|
Resources WorkerResources
|
|
|
|
}
|
|
|
|
|
|
|
|
type WorkerResources struct {
|
|
|
|
MemPhysical uint64
|
|
|
|
MemSwap uint64
|
|
|
|
|
|
|
|
MemReserved uint64 // Used by system / other processes
|
|
|
|
|
2020-04-27 12:38:24 +00:00
|
|
|
CPUs uint64 // Logical cores
|
2020-04-23 22:16:21 +00:00
|
|
|
GPUs []string
|
|
|
|
}
|
|
|
|
|
|
|
|
type WorkerStats struct {
|
2020-10-18 10:35:44 +00:00
|
|
|
Info WorkerInfo
|
|
|
|
Enabled bool
|
2020-04-23 22:16:21 +00:00
|
|
|
|
|
|
|
MemUsedMin uint64
|
|
|
|
MemUsedMax uint64
|
2020-08-16 10:40:35 +00:00
|
|
|
GpuUsed bool // nolint
|
|
|
|
CpuUse uint64 // nolint
|
2020-04-23 22:16:21 +00:00
|
|
|
}
|
2020-07-21 18:01:25 +00:00
|
|
|
|
2020-11-09 22:38:20 +00:00
|
|
|
const (
|
|
|
|
RWRetWait = -1
|
|
|
|
RWReturned = -2
|
|
|
|
RWRetDone = -3
|
|
|
|
)
|
|
|
|
|
2020-07-21 18:01:25 +00:00
|
|
|
type WorkerJob struct {
|
2020-09-07 14:12:46 +00:00
|
|
|
ID CallID
|
2020-07-21 18:01:25 +00:00
|
|
|
Sector abi.SectorID
|
|
|
|
Task sealtasks.TaskType
|
|
|
|
|
2020-11-09 22:38:20 +00:00
|
|
|
// 1+ - assigned
|
|
|
|
// 0 - running
|
|
|
|
// -1 - ret-wait
|
|
|
|
// -2 - returned
|
|
|
|
// -3 - ret-done
|
|
|
|
RunWait int
|
2020-08-27 21:14:33 +00:00
|
|
|
Start time.Time
|
2020-11-09 22:09:04 +00:00
|
|
|
|
|
|
|
Hostname string `json:",omitempty"` // optional, set for ret-wait jobs
|
2020-07-21 18:01:25 +00:00
|
|
|
}
|
2020-09-06 16:47:16 +00:00
|
|
|
|
|
|
|
type CallID struct {
|
|
|
|
Sector abi.SectorID
|
|
|
|
ID uuid.UUID
|
|
|
|
}
|
|
|
|
|
2020-09-14 07:44:55 +00:00
|
|
|
func (c CallID) String() string {
|
|
|
|
return fmt.Sprintf("%d-%d-%s", c.Sector.Miner, c.Sector.Number, c.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ fmt.Stringer = &CallID{}
|
|
|
|
|
2020-09-06 16:47:16 +00:00
|
|
|
var UndefCall CallID
|
|
|
|
|
|
|
|
type WorkerCalls interface {
|
2020-11-04 20:29:08 +00:00
|
|
|
AddPiece(ctx context.Context, sector storage.SectorRef, pieceSizes []abi.UnpaddedPieceSize, newPieceSize abi.UnpaddedPieceSize, pieceData storage.Data) (CallID, error)
|
|
|
|
SealPreCommit1(ctx context.Context, sector storage.SectorRef, ticket abi.SealRandomness, pieces []abi.PieceInfo) (CallID, error)
|
|
|
|
SealPreCommit2(ctx context.Context, sector storage.SectorRef, pc1o storage.PreCommit1Out) (CallID, error)
|
|
|
|
SealCommit1(ctx context.Context, sector storage.SectorRef, ticket abi.SealRandomness, seed abi.InteractiveSealRandomness, pieces []abi.PieceInfo, cids storage.SectorCids) (CallID, error)
|
|
|
|
SealCommit2(ctx context.Context, sector storage.SectorRef, c1o storage.Commit1Out) (CallID, error)
|
|
|
|
FinalizeSector(ctx context.Context, sector storage.SectorRef, keepUnsealed []storage.Range) (CallID, error)
|
|
|
|
ReleaseUnsealed(ctx context.Context, sector storage.SectorRef, safeToFree []storage.Range) (CallID, error)
|
|
|
|
MoveStorage(ctx context.Context, sector storage.SectorRef, types SectorFileType) (CallID, error)
|
|
|
|
UnsealPiece(context.Context, storage.SectorRef, UnpaddedByteIndex, abi.UnpaddedPieceSize, abi.SealRandomness, cid.Cid) (CallID, error)
|
|
|
|
ReadPiece(context.Context, io.Writer, storage.SectorRef, UnpaddedByteIndex, abi.UnpaddedPieceSize) (CallID, error)
|
|
|
|
Fetch(context.Context, storage.SectorRef, SectorFileType, PathType, AcquireMode) (CallID, error)
|
2020-09-06 16:47:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type WorkerReturn interface {
|
|
|
|
ReturnAddPiece(ctx context.Context, callID CallID, pi abi.PieceInfo, err string) error
|
|
|
|
ReturnSealPreCommit1(ctx context.Context, callID CallID, p1o storage.PreCommit1Out, err string) error
|
|
|
|
ReturnSealPreCommit2(ctx context.Context, callID CallID, sealed storage.SectorCids, err string) error
|
|
|
|
ReturnSealCommit1(ctx context.Context, callID CallID, out storage.Commit1Out, err string) error
|
|
|
|
ReturnSealCommit2(ctx context.Context, callID CallID, proof storage.Proof, err string) error
|
|
|
|
ReturnFinalizeSector(ctx context.Context, callID CallID, err string) error
|
|
|
|
ReturnReleaseUnsealed(ctx context.Context, callID CallID, err string) error
|
|
|
|
ReturnMoveStorage(ctx context.Context, callID CallID, err string) error
|
|
|
|
ReturnUnsealPiece(ctx context.Context, callID CallID, err string) error
|
|
|
|
ReturnReadPiece(ctx context.Context, callID CallID, ok bool, err string) error
|
|
|
|
ReturnFetch(ctx context.Context, callID CallID, err string) error
|
|
|
|
}
|