Documentation
¶
Overview ¶
Package leases provides an API for acquiring and releasing leases.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrLeaseHeld = errors.New("lease is held")
ErrLeaseHeld is returned when the lease acquisition times out because the lease is already held.
View Source
var ErrLeaseNotHeld = errors.New("lease is not held")
ErrLeaseNotHeld is returned by Release when the lease is not held.
Functions ¶
func SQLLeaserMigrations ¶
func SQLLeaserMigrations() zerosql.Migrations
Types ¶
type Leaser ¶
type Leaser interface {
// Acquire acquires a lease for the given key.
//
// It will block until the lease is acquired, timeout is reached, or context is cancelled. Once acquired, the lease
// will be automatically released when the context is canceled, or when the Release function is called.
//
// Leases are automatically renewed, but if renewal fails after a period of retries, the process will be terminated
// to avoid split-brain.
Acquire(ctx context.Context, key string, timeout time.Duration) (Release, error)
// Close releases all resources associated with the leaser.
Close() error
}
Leaser is an interface for lease acquisition and release.
func NewMemoryLeaser ¶
func NewMemoryLeaser() Leaser
NewMemoryLeaser creates a Leaser that holds leases using an in-memory map.
On the upside, it can never fail.
type MemoryLeaser ¶
type MemoryLeaser struct {
// contains filtered or unexported fields
}
func (*MemoryLeaser) Close ¶
func (m *MemoryLeaser) Close() error
Click to show internal directories.
Click to hide internal directories.