consul

package
v0.5.11 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultSessionName = "litefs"
	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) Handoff added in v0.4.0

func (l *Lease) Handoff(ctx context.Context, nodeID uint64) error

Handoff sends the nodeID to the channel returned by HandoffCh()

func (*Lease) HandoffCh added in v0.4.0

func (l *Lease) HandoffCh() <-chan uint64

HandoffCh returns the handoff channel.

func (*Lease) ID added in v0.4.0

func (l *Lease) ID() string

ID returns the lease session ID.

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, key, hostname, advertiseURL string) *Leaser

NewLeaser returns a new instance of Leaser.

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) ClusterID added in v0.5.0

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

ClusterID returns the current cluster ID from Consul. Returns a blank string if no cluster ID has been set yet.

func (*Leaser) ClusterIDKey added in v0.5.0

func (l *Leaser) ClusterIDKey() string

ClusterIDKey returns the key used to store the cluster ID.

func (*Leaser) Hostname added in v0.2.0

func (l *Leaser) Hostname() string

Hostname returns the hostname for this node.

func (*Leaser) NodeName added in v0.2.0

func (l *Leaser) NodeName() string

NodeName returns a name for a node based on the key prefix.

func (*Leaser) Open

func (l *Leaser) Open() error

Open initializes the Consul client.

func (*Leaser) PrimaryInfo added in v0.2.0

func (l *Leaser) PrimaryInfo(ctx context.Context) (info litefs.PrimaryInfo, err error)

PrimaryInfo attempts to return the current primary URL.

func (*Leaser) SetClusterID added in v0.5.0

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

SetClusterID sets the cluster ID on Consul. The cluster ID can only be set once and it will return an error if attemping to reassign the cluster ID.

func (*Leaser) Type added in v0.5.0

func (l *Leaser) Type() string

Type returns "consul".

Jump to

Keyboard shortcuts

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