optracker

package
v0.0.0-...-8c384fb Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2023 License: Apache-2.0, MIT, Apache-2.0, + 1 more Imports: 14 Imported by: 0

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 (*Operation) AttemptCount

func (op *Operation) AttemptCount() int

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

func (op *Operation) Canceled() bool

Canceled returns whether the context for this operation has been canceled.

func (*Operation) Cid

func (op *Operation) Cid() api.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) IncAttempt

func (op *Operation) IncAttempt()

IncAttempt does a plus-one on the AttemptCount.

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) PriorityPin

func (op *Operation) PriorityPin() bool

PriorityPin returns true if the pin has been marked as priority pin.

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) SetPriorityPin

func (op *Operation) SetPriorityPin(p bool)

SetPriorityPin returns true if the pin has been marked as priority pin.

func (*Operation) String

func (op *Operation) String() string

String returns a string representation of an Operation.

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(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) Get

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

Get returns a PinInfo object for Cid.

func (*OperationTracker) GetAll

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

GetAll returns PinInfo objects for all known operations.

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) GetOperation

func (opt *OperationTracker) GetOperation(ctx context.Context, c api.Cid) (op *Operation, ok bool)

GetOperation returns a Operation for Cid.

func (*OperationTracker) OpContext

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

OpContext gets the context of an operation, if any.

func (*OperationTracker) PinQueueSize

func (opt *OperationTracker) PinQueueSize() int64

PinQueueSize returns the current number of items queued to pin.

func (*OperationTracker) SetClient

func (opt *OperationTracker) SetClient(c *rpc.Client)

func (*OperationTracker) SetError

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

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