leaser

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LeaseStore

type LeaseStore interface {
	// TryAcquire tries to create a lease with the given leaseName and leaseHolder. If it is
	// successful (implying the given leaseHolder is the active holder), then it should return
	// true for the first value. If creation fails, the store should query for the leaseholder
	// value of the existing lease. The second returned value is the actual current leaseholder,
	// which can only differ from the given value if creation failed. If creation failed, but
	// the current process is the holder (i.e. the given leaseHolder matches the value in the
	// store), the store should bump the lease's TTL, so that the current process will continue
	// to hold it.
	//
	// This method is invoked regardless of whether the leaser believes that the current process
	// is the leaseholder. This is used to both try to acquire a lease, bump the TTL on a lease
	// if already held, and check the owner of the lease if not held. The store must be able to
	// do all of this atomically so that it is safe and correct in the face of concurrent
	// processes all trying to manage the same leaseName.
	TryAcquire(ctx context.Context, leaseName string, leaseHolder []byte, ttl time.Duration) (created bool, holder []byte, err error)
	// Release tries to delete a lease with the given leaseName and leaseHolder. If the lease
	// exists but is held by a different owner, it should not be deleted.
	//
	// This method will only be called when the leaser believes that the current process holds
	// the lease, for cleanup.
	Release(ctx context.Context, leaseName string, leaseHolder []byte) error
}

LeaseStore is the interface used to try to acquire and release leases.

type PollingLeaser

type PollingLeaser struct {
	LeaseStore    LeaseStore
	LeaseTTL      time.Duration
	PollingPeriod time.Duration
}

PollingLeaser implements prototransform.Leaser by polling a lease store, periodically trying to create a lease or query for the current owner. Leaser implementations need only provide a lease store implementation. This is suitable for many types of stores, including Redis, memcached, or an RDBMS. It is not necessarily suitable for stores that have better primitives for distributed locking or leader election, such as ZooKeeper.

func (*PollingLeaser) NewLease

func (l *PollingLeaser) NewLease(ctx context.Context, leaseName string, leaseHolder []byte) prototransform.Lease

NewLease implements the prototransform.Leaser interface.

Directories

Path Synopsis
internal
Package memcacheleaser provides an implementation of prototransform.Leaser that is backed by a memcached instance: https://memcached.org/.
Package memcacheleaser provides an implementation of prototransform.Leaser that is backed by a memcached instance: https://memcached.org/.
Package redisleaser provides an implementation of prototransform.Leaser that is backed by a Redis instance: https://redis.io/.
Package redisleaser provides an implementation of prototransform.Leaser that is backed by a Redis instance: https://redis.io/.

Jump to

Keyboard shortcuts

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