56 lines
1.0 KiB
Go
56 lines
1.0 KiB
Go
package sectorstorage
|
|
|
|
import (
|
|
"github.com/filecoin-project/go-statestore"
|
|
|
|
"github.com/filecoin-project/lotus/extern/sector-storage/storiface"
|
|
)
|
|
|
|
type workerCallTracker struct {
|
|
st *statestore.StateStore // by CallID
|
|
}
|
|
|
|
type CallState uint64
|
|
|
|
const (
|
|
CallStarted CallState = iota
|
|
CallDone
|
|
// returned -> remove
|
|
)
|
|
|
|
type Call struct {
|
|
ID storiface.CallID
|
|
RetType ReturnType
|
|
|
|
State CallState
|
|
|
|
Result []byte // json bytes
|
|
}
|
|
|
|
func (wt *workerCallTracker) onStart(ci storiface.CallID, rt ReturnType) error {
|
|
return wt.st.Begin(ci, &Call{
|
|
ID: ci,
|
|
RetType: rt,
|
|
State: CallStarted,
|
|
})
|
|
}
|
|
|
|
func (wt *workerCallTracker) onDone(ci storiface.CallID, ret []byte) error {
|
|
st := wt.st.Get(ci)
|
|
return st.Mutate(func(cs *Call) error {
|
|
cs.State = CallDone
|
|
cs.Result = ret
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func (wt *workerCallTracker) onReturned(ci storiface.CallID) error {
|
|
st := wt.st.Get(ci)
|
|
return st.End()
|
|
}
|
|
|
|
func (wt *workerCallTracker) unfinished() ([]Call, error) {
|
|
var out []Call
|
|
return out, wt.st.List(&out)
|
|
}
|