track

package
v2.9.4 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const ExpireNow = time.Duration(math.MinInt32)

ExpireNow will expire the object immediately.

View Source
const NoTTL = time.Duration(0)

NoTTL will cause the object to live forever

Variables

View Source
var (
	// ErrDifferentObjectExists the object already exists, with different downstream objects.
	ErrDifferentObjectExists = errors.Errorf("a different object exists at that id")
	// ErrDanglingRef the operation would create a dangling reference
	ErrDanglingRef = errors.Errorf("the operation would create a dangling reference")
	// ErrSelfReference object cannot reference itself
	ErrSelfReference = errors.Errorf("object cannot reference itself")
)

Functions

func Create

func Create(ctx context.Context, tr Tracker, id string, pointsTo []string, ttl time.Duration) error

Create creates uses tracker to create the object id.

func Delete

func Delete(ctx context.Context, tr Tracker, id string) error

Delete deletes id from the tracker

func Drop

func Drop(ctx context.Context, tr Tracker, id string) error

Drop sets the object at id to expire now

func SetupPostgresTrackerV0

func SetupPostgresTrackerV0(ctx context.Context, tx *pachsql.Tx) error

SetupPostgresTrackerV0 sets up the table for the postgres tracker DO NOT MODIFY THIS FUNCTION IT HAS BEEN USED IN A RELEASED MIGRATION

func TestTracker

func TestTracker(t *testing.T, newTracker func(testing.TB) Tracker)

TestTracker runs a TestSuite to ensure Tracker is properly implemented

Types

type Deleter

type Deleter interface {
	DeleteTx(tx *pachsql.Tx, id string) error
}

Deleter is used to delete external data associated with a tracked object

type DeleterMux

type DeleterMux func(string) Deleter

DeleterMux returns a Deleter based on the id being deleted

func (DeleterMux) DeleteTx

func (dm DeleterMux) DeleteTx(tx *pachsql.Tx, id string) error

DeleteTx implements Deleter

type GarbageCollector

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

GarbageCollector periodically runs garbage collection on tracker objects

func NewGarbageCollector

func NewGarbageCollector(tracker Tracker, period time.Duration, deleter Deleter) *GarbageCollector

NewGarbageCollector returns a garbage collector monitoring tracker, and kicking off a cycle every period. It will use deleter to deleted associated data before deleting objects from the Tracker

func (*GarbageCollector) RunForever

func (gc *GarbageCollector) RunForever(ctx context.Context) error

RunForever runs the gc loop, until the context is cancelled. It returns context.Canceled on exit.

func (*GarbageCollector) RunOnce

func (gc *GarbageCollector) RunOnce(ctx context.Context) (n int, retErr error)

RunOnce run's one cycle of garbage collection.

func (*GarbageCollector) RunUntilEmpty

func (gc *GarbageCollector) RunUntilEmpty(ctx context.Context) error

RunUntilEmpty calls RunOnce repeatedly until it returns an error or 0.

type Tracker

type Tracker interface {
	// DB returns the database the tracker is using
	DB() *pachsql.DB

	// CreateTx creates an object with id=id, and pointers to everything in pointsTo
	// It errors with ErrDifferentObjectExists if the object already exists.  Callers may be able to ignore this.
	// It errors with ErrDanglingRef if any of the elements in pointsTo do not exist
	CreateTx(tx *pachsql.Tx, id string, pointsTo []string, ttl time.Duration) error

	// SetTTL sets the expiration time to current_time + ttl for the specified object
	SetTTL(ctx context.Context, id string, ttl time.Duration) (time.Time, error)

	// GetExpiresAt returns the time that the object expires or a pacherr.ErrNotExist if it has expired.
	GetExpiresAt(ctx context.Context, id string) (time.Time, error)

	// GetDownstream gets all objects immediately downstream of (pointed to by) object with id
	GetDownstream(ctx context.Context, id string) ([]string, error)

	// GetUpstream gets all objects immediately upstream of (pointing to) the object with id
	GetUpstream(ctx context.Context, id string) ([]string, error)

	// DeleteTx deletes the object, or returns ErrDanglingRef if deleting it would create dangling refs.
	// If the id doesn't exist, no error is returned
	DeleteTx(tx *pachsql.Tx, id string) error

	// IterateDeletable calls cb with some top-level objects which are no longer referenced and have expired
	// Even if it deletes all top-level objects, there may be more to delete after it runs
	IterateDeletable(ctx context.Context, cb func(id string) error) error
}

Tracker tracks objects and their references to one another.

func NewPostgresTracker

func NewPostgresTracker(db *pachsql.DB) Tracker

NewPostgresTracker returns a

func NewTestTracker

func NewTestTracker(t testing.TB, db *pachsql.DB) Tracker

NewTestTracker returns a tracker scoped to the lifetime of the test

Jump to

Keyboard shortcuts

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