consul

package
v0.1.0-alpha1 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultSessionName = "litefs"
	DefaultKey         = "litefs/primary"
	DefaultTTL         = 10 * time.Second
	DefaultLockDelay   = 1 * time.Second
)

Default lease settings.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lease

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

Lease represents a distributed lock obtained by the Leaser.

func (*Lease) Close

func (l *Lease) Close() error

Close destroys the underlying session.

func (*Lease) Renew

func (l *Lease) Renew(ctx context.Context) error

Renew attempts to reset the TTL on the lease by renewing it. Returns ErrLeaseExpired if lease no longer exists.

func (*Lease) RenewedAt

func (l *Lease) RenewedAt() time.Time

RenewedAt returns the time that the lease was created or renewed.

func (*Lease) TTL

func (l *Lease) TTL() time.Duration

TTL returns the time-to-live value the lease was initialized with.

type Leaser

type Leaser struct {

	// SessionName is the name associated with the Consul session.
	SessionName string

	// Key is the Consul KV key use to acquire the lock.
	Key string

	// Prefix that is prepended to the key. Automatically set if the URL contains a path.
	KeyPrefix string

	// TTL is the time until the lease expires.
	TTL time.Duration

	// LockDefault is the time after the lock expires that a new lock can be acquired.
	LockDelay time.Duration
	// contains filtered or unexported fields
}

Leaser represents an API for obtaining a distributed lock on a single key.

func NewLeaser

func NewLeaser(consulURL, advertiseURL string) *Leaser

NewLeaser

func (*Leaser) Acquire

func (l *Leaser) Acquire(ctx context.Context) (_ litefs.Lease, retErr error)

Acquire acquires a lock on the key and sets the value. Returns an error if the lease could not be obtained.

func (*Leaser) AcquireExisting

func (l *Leaser) AcquireExisting(ctx context.Context, leaseID string) (litefs.Lease, error)

AcquireExisting acquires a lock using an existing session ID. This can occur if an existing primary hands off to a replica. Returns an error if the lease could not be renewed.

func (*Leaser) AdvertiseURL

func (l *Leaser) AdvertiseURL() string

AdvertiseURL returns the URL being advertised to nodes when primary.

func (*Leaser) Close

func (l *Leaser) Close() (err error)

Close closes the underlying client.

func (*Leaser) Open

func (l *Leaser) Open() error

Open initializes the Consul client.

func (*Leaser) PrimaryURL

func (l *Leaser) PrimaryURL(ctx context.Context) (string, error)

PrimaryURL attempts to return the current primary URL.

Jump to

Keyboard shortcuts

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