Documentation ¶
Index ¶
- Constants
- Variables
- func Create(ctx context.Context, tr Tracker, id string, pointsTo []string, ...) error
- func Delete(ctx context.Context, tr Tracker, id string) error
- func Drop(ctx context.Context, tr Tracker, id string) error
- func SetupPostgresTrackerV0(ctx context.Context, tx *pachsql.Tx) error
- func TestTracker(t *testing.T, newTracker func(testing.TB) Tracker)
- type Deleter
- type DeleterMux
- type GarbageCollector
- type Tracker
Constants ¶
const ExpireNow = time.Duration(math.MinInt32)
ExpireNow will expire the object immediately.
const NoTTL = time.Duration(0)
NoTTL will cause the object to live forever
Variables ¶
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 SetupPostgresTrackerV0 ¶
SetupPostgresTrackerV0 sets up the table for the postgres tracker DO NOT MODIFY THIS FUNCTION IT HAS BEEN USED IN A RELEASED MIGRATION
Types ¶
type DeleterMux ¶
DeleterMux returns a Deleter based on the id being deleted
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) (_ 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 ¶
NewPostgresTracker returns a