Documentation ¶
Overview ¶
Package optracker implements functionality to track the status of pin and operations as needed by implementations of the pintracker component. It particularly allows to obtain status information for a given Cid, to skip re-tracking already ongoing operations, or to cancel ongoing operations when opposing ones arrive.
Index ¶
- func TrackerStatusToOperationPhase(status api.TrackerStatus) (OperationType, Phase)
- type Operation
- func (op *Operation) Cancel()
- func (op *Operation) Cancelled() bool
- func (op *Operation) Cid() cid.Cid
- func (op *Operation) Context() context.Context
- func (op *Operation) Error() string
- func (op *Operation) Phase() Phase
- func (op *Operation) Pin() api.Pin
- func (op *Operation) SetError(err error)
- func (op *Operation) SetPhase(ph Phase)
- func (op *Operation) Timestamp() time.Time
- func (op *Operation) ToTrackerStatus() api.TrackerStatus
- func (op *Operation) Type() OperationType
- type OperationTracker
- func (opt *OperationTracker) Clean(op *Operation)
- func (opt *OperationTracker) CleanAllDone()
- func (opt *OperationTracker) CleanError(c cid.Cid)
- func (opt *OperationTracker) Filter(filters ...interface{}) []api.PinInfo
- func (opt *OperationTracker) Get(c cid.Cid) api.PinInfo
- func (opt *OperationTracker) GetAll() []api.PinInfo
- func (opt *OperationTracker) GetExists(c cid.Cid) (api.PinInfo, bool)
- func (opt *OperationTracker) OpContext(c cid.Cid) context.Context
- func (opt *OperationTracker) SetError(c cid.Cid, err error)
- func (opt *OperationTracker) Status(c cid.Cid) (api.TrackerStatus, bool)
- func (opt *OperationTracker) TrackNewOperation(pin api.Pin, typ OperationType, ph Phase) *Operation
- type OperationType
- type Phase
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TrackerStatusToOperationPhase ¶
func TrackerStatusToOperationPhase(status api.TrackerStatus) (OperationType, Phase)
TrackerStatusToOperationPhase takes an api.TrackerStatus and converts it to an OpType and Phase.
Types ¶
type Operation ¶
type Operation struct {
// contains filtered or unexported fields
}
Operation represents an ongoing operation involving a particular Cid. It provides the type and phase of operation and a way to mark the operation finished (also used to cancel).
func NewOperation ¶
NewOperation creates a new Operation.
func (*Operation) Cancel ¶
func (op *Operation) Cancel()
Cancel will cancel the context associated to this operation.
func (*Operation) Cancelled ¶
Cancelled returns whether the context for this operation has been cancelled.
func (*Operation) SetError ¶
SetError sets the phase to PhaseError along with an error message. It updates the timestamp.
func (*Operation) Timestamp ¶
Timestamp returns the time when this operation was last modified (phase changed, error was set...).
func (*Operation) ToTrackerStatus ¶
func (op *Operation) ToTrackerStatus() api.TrackerStatus
ToTrackerStatus returns an api.TrackerStatus reflecting the current status of this operation. It's a translation from the Type and the Phase.
type OperationTracker ¶
type OperationTracker struct {
// contains filtered or unexported fields
}
OperationTracker tracks and manages all inflight Operations.
func NewOperationTracker ¶
NewOperationTracker creates a new OperationTracker.
func (*OperationTracker) Clean ¶
func (opt *OperationTracker) Clean(op *Operation)
Clean deletes an operation from the tracker if it is the one we are tracking (compares pointers).
func (*OperationTracker) CleanAllDone ¶
func (opt *OperationTracker) CleanAllDone()
CleanAllDone deletes any operation from the tracker that is in PhaseDone.
func (*OperationTracker) CleanError ¶
func (opt *OperationTracker) CleanError(c cid.Cid)
CleanError removes the associated Operation, if it is in PhaseError.
func (*OperationTracker) Filter ¶
func (opt *OperationTracker) Filter(filters ...interface{}) []api.PinInfo
Filter returns a slice of api.PinInfos that had associated Operations that matched the provided filter. Note, only supports filters of type OperationType or Phase, any other type will result in a nil slice being returned.
func (*OperationTracker) Get ¶
func (opt *OperationTracker) Get(c cid.Cid) api.PinInfo
Get returns a PinInfo object for Cid.
func (*OperationTracker) GetAll ¶
func (opt *OperationTracker) GetAll() []api.PinInfo
GetAll returns PinInfo objets for all known operations.
func (*OperationTracker) GetExists ¶
GetExists returns a PinInfo object for a Cid only if there exists an associated Operation.
func (*OperationTracker) OpContext ¶
func (opt *OperationTracker) OpContext(c cid.Cid) context.Context
OpContext gets the context of an operation, if any.
func (*OperationTracker) SetError ¶
func (opt *OperationTracker) SetError(c cid.Cid, err error)
SetError transitions an operation for a Cid into PhaseError if its Status is PhaseDone. Any other phases are considered in-flight and not touched. For things already in error, the error message is updated. Remote pins are ignored too.
func (*OperationTracker) Status ¶
func (opt *OperationTracker) Status(c cid.Cid) (api.TrackerStatus, bool)
Status returns the TrackerStatus associated to the last operation known with the given Cid. It returns false if we are not tracking any operation for the given Cid.
func (*OperationTracker) TrackNewOperation ¶
func (opt *OperationTracker) TrackNewOperation(pin api.Pin, typ OperationType, ph Phase) *Operation
TrackNewOperation will create, track and return a new operation unless one already exists to do the same thing, in which case nil is returned.
If an operation exists it is of different type, it is cancelled and the new one replaces it in the tracker.
type OperationType ¶
type OperationType int
OperationType represents the kinds of operations that the PinTracker performs and the operationTracker tracks the status of.
const ( // OperationUnknown represents an unknown operation. OperationUnknown OperationType = iota // OperationPin represents a pin operation. OperationPin // OperationUnpin represents an unpin operation. OperationUnpin // OperationRemote represents an noop operation OperationRemote // OperationShard represents a meta pin. We don't // pin these. OperationShard )
func (OperationType) String ¶
func (i OperationType) String() string