lotus/extern/sector-storage/worker_calltracker.go

46 lines
825 B
Go
Raw Normal View History

2020-09-14 07:44:55 +00:00
package sectorstorage
import (
"github.com/filecoin-project/go-statestore"
"github.com/filecoin-project/lotus/extern/sector-storage/storiface"
)
type workerCallTracker struct {
2020-09-14 07:44:55 +00:00
st *statestore.StateStore // by CallID
}
type CallState uint64
const (
CallStarted CallState = iota
CallDone
// returned -> remove
)
type Call struct {
State CallState
Result []byte // json bytes
2020-09-14 07:44:55 +00:00
}
func (wt *workerCallTracker) onStart(ci storiface.CallID) error {
2020-09-14 07:44:55 +00:00
return wt.st.Begin(ci, &Call{
State: CallStarted,
})
}
func (wt *workerCallTracker) onDone(ci storiface.CallID, ret []byte) error {
2020-09-14 07:44:55 +00:00
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 {
2020-09-14 07:44:55 +00:00
st := wt.st.Get(ci)
return st.End()
}