Documentation
¶
Index ¶
- Constants
- type Lease
- type Leaser
- func (l *Leaser) Acquire(ctx context.Context) (_ litefs.Lease, retErr error)
- func (l *Leaser) AcquireExisting(ctx context.Context, leaseID string) (litefs.Lease, error)
- func (l *Leaser) AdvertiseURL() string
- func (l *Leaser) Close() (err error)
- func (l *Leaser) Hostname() string
- func (l *Leaser) NodeName() string
- func (l *Leaser) Open() error
- func (l *Leaser) PrimaryInfo(ctx context.Context) (info litefs.PrimaryInfo, err error)
Constants ¶
const ( DefaultSessionName = "litefs" DefaultKey = "litefs/primary" DefaultTTL = 10 * time.Second DefaultLockDelay = 5 * 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) Renew ¶
Renew attempts to reset the TTL on the lease by renewing it. Returns ErrLeaseExpired if lease no longer exists.
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 (*Leaser) Acquire ¶
Acquire acquires a lock on the key and sets the value. Returns an error if the lease could not be obtained.
func (*Leaser) AcquireExisting ¶
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 ¶
AdvertiseURL returns the URL being advertised to nodes when primary.
func (*Leaser) NodeName ¶ added in v0.2.0
NodeName returns a name for a node based on the key prefix.
func (*Leaser) PrimaryInfo ¶ added in v0.2.0
PrimaryInfo attempts to return the current primary URL.