optracker

package
v0.0.0-...-6646f2c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2019 License: MIT Imports: 8 Imported by: 2

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

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

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

NewOperation creates a new Operation.

func (*Operation) Cancel

func (op *Operation) Cancel()

Cancel will cancel the context associated to this operation.

func (*Operation) Cancelled

func (op *Operation) Cancelled() bool

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

func (*Operation) Cid

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

Cid returns the Cid associated to this operation.

func (*Operation) Context

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

Context returns the context associated to this operation.

func (*Operation) Error

func (op *Operation) Error() string

Error returns any error message attached to the operation.

func (*Operation) Phase

func (op *Operation) Phase() Phase

Phase returns the Phase.

func (*Operation) Pin

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

Pin returns the Pin object associated to the operation.

func (*Operation) SetError

func (op *Operation) SetError(err error)

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

func (*Operation) SetPhase

func (op *Operation) SetPhase(ph Phase)

SetPhase changes the Phase and updates the timestamp.

func (*Operation) Timestamp

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

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.

func (*Operation) Type

func (op *Operation) Type() OperationType

Type returns the operation Type.

type OperationTracker

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

OperationTracker tracks and manages all inflight Operations.

func NewOperationTracker

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

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

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

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

type Phase

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

func (i Phase) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL