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) ClusterID(ctx context.Context) (string, error)
- func (l *Leaser) ClusterIDKey() string
- 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)
- func (l *Leaser) SetClusterID(ctx context.Context, clusterID string) error
- func (l *Leaser) Type() string
Constants ¶
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) Handoff ¶ added in v0.4.0
Handoff sends the nodeID to the channel returned by HandoffCh()
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) ClusterID ¶ added in v0.5.0
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
ClusterIDKey returns the key used to store the cluster ID.
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.
func (*Leaser) SetClusterID ¶ added in v0.5.0
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.