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) AttemptCount() int
- func (op *Operation) Cancel()
- func (op *Operation) Canceled() bool
- func (op *Operation) Cid() api.Cid
- func (op *Operation) Context() context.Context
- func (op *Operation) Error() string
- func (op *Operation) IncAttempt()
- func (op *Operation) Phase() Phase
- func (op *Operation) Pin() api.Pin
- func (op *Operation) PriorityPin() bool
- func (op *Operation) SetError(err error)
- func (op *Operation) SetPhase(ph Phase)
- func (op *Operation) SetPriorityPin(p bool)
- func (op *Operation) String() string
- func (op *Operation) Timestamp() time.Time
- func (op *Operation) ToTrackerStatus() api.TrackerStatus
- func (op *Operation) Type() OperationType
- type OperationTracker
- func (opt *OperationTracker) Clean(ctx context.Context, op *Operation)
- func (opt *OperationTracker) CleanAllDone(ctx context.Context)
- func (opt *OperationTracker) Filter(ctx context.Context, ipfs api.IPFSID, filters ...interface{}) []api.PinInfo
- func (opt *OperationTracker) Get(ctx context.Context, c api.Cid, ipfs api.IPFSID) api.PinInfo
- func (opt *OperationTracker) GetAll(ctx context.Context, ipfs api.IPFSID) []api.PinInfo
- func (opt *OperationTracker) GetAllChannel(ctx context.Context, filter api.TrackerStatus, ipfs api.IPFSID, ...) error
- func (opt *OperationTracker) GetExists(ctx context.Context, c api.Cid, ipfs api.IPFSID) (api.PinInfo, bool)
- func (opt *OperationTracker) OpContext(ctx context.Context, c api.Cid) context.Context
- func (opt *OperationTracker) PinQueueSize() int64
- func (opt *OperationTracker) SetError(ctx context.Context, c api.Cid, err error)
- func (opt *OperationTracker) Status(ctx context.Context, c api.Cid) (api.TrackerStatus, bool)
- func (opt *OperationTracker) String() string
- func (opt *OperationTracker) TrackNewOperation(ctx context.Context, 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 (*Operation) AttemptCount ¶
AttemptCount returns the number of times that this operation has been in progress.
func (*Operation) Cancel ¶
func (op *Operation) Cancel()
Cancel will cancel the context associated to this operation.
func (*Operation) Canceled ¶
Canceled returns whether the context for this operation has been canceled.
func (*Operation) IncAttempt ¶
func (op *Operation) IncAttempt()
IncAttempt does a plus-one on the AttemptCount.
func (*Operation) PriorityPin ¶
PriorityPin returns true if the pin has been marked as priority pin.
func (*Operation) SetError ¶
SetError sets the phase to PhaseError along with an error message. It updates the timestamp.
func (*Operation) SetPriorityPin ¶
SetPriorityPin returns true if the pin has been marked as priority pin.
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(ctx context.Context, 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(ctx context.Context)
CleanAllDone deletes any operation from the tracker that is in PhaseDone.
func (*OperationTracker) Filter ¶
func (opt *OperationTracker) Filter(ctx context.Context, ipfs api.IPFSID, 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) GetAllChannel ¶
func (opt *OperationTracker) GetAllChannel(ctx context.Context, filter api.TrackerStatus, ipfs api.IPFSID, out chan<- api.PinInfo) error
GetAllChannel returns all known operations that match the filter on the provided channel. Blocks until done.
func (*OperationTracker) GetExists ¶
func (opt *OperationTracker) GetExists(ctx context.Context, c api.Cid, ipfs api.IPFSID) (api.PinInfo, bool)
GetExists returns a PinInfo object for a Cid only if there exists an associated Operation.
func (*OperationTracker) PinQueueSize ¶
func (opt *OperationTracker) PinQueueSize() int64
PinQueueSize returns the current number of items queued to pin.
func (*OperationTracker) SetError ¶
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. Only used in tests right now.
func (*OperationTracker) Status ¶
func (opt *OperationTracker) Status(ctx context.Context, c api.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) String ¶
func (opt *OperationTracker) String() string
func (*OperationTracker) TrackNewOperation ¶
func (opt *OperationTracker) TrackNewOperation(ctx context.Context, 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 canceled 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