ipfs-cluster: github.com/ipfs/ipfs-cluster/pintracker/optracker Index | Files

package optracker

import "github.com/ipfs/ipfs-cluster/pintracker/optracker"

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

Package Files

operation.go operationtracker.go operationtype_string.go phase_string.go

func TrackerStatusToOperationPhase Uses

func TrackerStatusToOperationPhase(status api.TrackerStatus) (OperationType, Phase)

TrackerStatusToOperationPhase takes an api.TrackerStatus and converts it to an OpType and Phase.

type Operation Uses

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 Uses

func NewOperation(ctx context.Context, pin *api.Pin, typ OperationType, ph Phase) *Operation

NewOperation creates a new Operation.

func (*Operation) Cancel Uses

func (op *Operation) Cancel()

Cancel will cancel the context associated to this operation.

func (*Operation) Cancelled Uses

func (op *Operation) Cancelled() bool

Cancelled returns whether the context for this operation has been cancelled.

func (*Operation) Cid Uses

func (op *Operation) Cid() cid.Cid

Cid returns the Cid associated to this operation.

func (*Operation) Context Uses

func (op *Operation) Context() context.Context

Context returns the context associated to this operation.

func (*Operation) Error Uses

func (op *Operation) Error() string

Error returns any error message attached to the operation.

func (*Operation) Phase Uses

func (op *Operation) Phase() Phase

Phase returns the Phase.

func (*Operation) Pin Uses

func (op *Operation) Pin() *api.Pin

Pin returns the Pin object associated to the operation.

func (*Operation) SetError Uses

func (op *Operation) SetError(err error)

SetError sets the phase to PhaseError along with an error message. It updates the timestamp.

func (*Operation) SetPhase Uses

func (op *Operation) SetPhase(ph Phase)

SetPhase changes the Phase and updates the timestamp.

func (*Operation) String Uses

func (op *Operation) String() string

String returns a string representation of an Operation.

func (*Operation) Timestamp Uses

func (op *Operation) Timestamp() time.Time

Timestamp returns the time when this operation was last modified (phase changed, error was set...).

func (*Operation) ToTrackerStatus Uses

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.

func (*Operation) Type Uses

func (op *Operation) Type() OperationType

Type returns the operation Type.

type OperationTracker Uses

type OperationTracker struct {
    // contains filtered or unexported fields
}

OperationTracker tracks and manages all inflight Operations.

func NewOperationTracker Uses

func NewOperationTracker(ctx context.Context, pid peer.ID, peerName string) *OperationTracker

NewOperationTracker creates a new OperationTracker.

func (*OperationTracker) Clean Uses

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 Uses

func (opt *OperationTracker) CleanAllDone(ctx context.Context)

CleanAllDone deletes any operation from the tracker that is in PhaseDone.

func (*OperationTracker) Filter Uses

func (opt *OperationTracker) Filter(ctx context.Context, 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 Uses

func (opt *OperationTracker) Get(ctx context.Context, c cid.Cid) *api.PinInfo

Get returns a PinInfo object for Cid.

func (*OperationTracker) GetAll Uses

func (opt *OperationTracker) GetAll(ctx context.Context) []*api.PinInfo

GetAll returns PinInfo objects for all known operations.

func (*OperationTracker) GetExists Uses

func (opt *OperationTracker) GetExists(ctx context.Context, c cid.Cid) (*api.PinInfo, bool)

GetExists returns a PinInfo object for a Cid only if there exists an associated Operation.

func (*OperationTracker) OpContext Uses

func (opt *OperationTracker) OpContext(ctx context.Context, c cid.Cid) context.Context

OpContext gets the context of an operation, if any.

func (*OperationTracker) SetError Uses

func (opt *OperationTracker) SetError(ctx context.Context, 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 Uses

func (opt *OperationTracker) Status(ctx context.Context, 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) String Uses

func (opt *OperationTracker) String() string

func (*OperationTracker) TrackNewOperation Uses

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 cancelled and the new one replaces it in the tracker.

type OperationType Uses

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 Uses

func (i OperationType) String() string

type Phase Uses

type Phase int

Phase represents the multiple phase that an operation can be in.

const (
    // PhaseError represents an error state.
    PhaseError Phase = iota
    // PhaseQueued represents the queued phase of an operation.
    PhaseQueued
    // PhaseInProgress represents the operation as in progress.
    PhaseInProgress
    // PhaseDone represents the operation once finished.
    PhaseDone
)

func (Phase) String Uses

func (i Phase) String() string

Package optracker imports 11 packages (graph) and is imported by 1 packages. Updated 2020-06-07. Refresh now. Tools for package owners.