package lease
import "go.etcd.io/etcd/server/v3/lease"
Package lease provides an interface and implementation for time-limited leases over arbitrary resources.
Index ¶
- Constants
- Variables
- type Checkpointer
- type FakeLessor
- func (fl *FakeLessor) Attach(id LeaseID, items []LeaseItem) error
- func (fl *FakeLessor) Checkpoint(id LeaseID, remainingTTL int64) error
- func (fl *FakeLessor) Demote()
- func (fl *FakeLessor) Detach(id LeaseID, items []LeaseItem) error
- func (fl *FakeLessor) ExpiredLeasesC() <-chan []*Lease
- func (fl *FakeLessor) GetLease(item LeaseItem) LeaseID
- func (fl *FakeLessor) Grant(id LeaseID, ttl int64) (*Lease, error)
- func (fl *FakeLessor) Leases() []*Lease
- func (fl *FakeLessor) Lookup(id LeaseID) *Lease
- func (fl *FakeLessor) Promote(extend time.Duration)
- func (fl *FakeLessor) Recover(b backend.Backend, rd RangeDeleter)
- func (fl *FakeLessor) Renew(id LeaseID) (int64, error)
- func (fl *FakeLessor) Revoke(id LeaseID) error
- func (fl *FakeLessor) SetCheckpointer(cp Checkpointer)
- func (fl *FakeLessor) SetRangeDeleter(dr RangeDeleter)
- func (fl *FakeLessor) Stop()
- type FakeTxnDelete
- func (ftd *FakeTxnDelete) DeleteRange(key, end []byte) (n, rev int64)
- func (ftd *FakeTxnDelete) End()
- type Lease
- func NewLease(id LeaseID, ttl int64) *Lease
- func (l *Lease) Demoted() bool
- func (l *Lease) Keys() []string
- func (l *Lease) Remaining() time.Duration
- func (l *Lease) SetLeaseItem(item LeaseItem)
- func (l *Lease) TTL() int64
- type LeaseExpiredNotifier
- func (mq *LeaseExpiredNotifier) Init()
- func (mq *LeaseExpiredNotifier) Len() int
- func (mq *LeaseExpiredNotifier) Peek() *LeaseWithTime
- func (mq *LeaseExpiredNotifier) RegisterOrUpdate(item *LeaseWithTime)
- func (mq *LeaseExpiredNotifier) Unregister() *LeaseWithTime
- type LeaseID
- type LeaseItem
- type LeaseQueue
- func (pq LeaseQueue) Len() int
- func (pq LeaseQueue) Less(i, j int) bool
- func (pq *LeaseQueue) Pop() any
- func (pq *LeaseQueue) Push(x any)
- func (pq LeaseQueue) Swap(i, j int)
- type LeaseWithTime
- type Lessor
- type LessorConfig
- type RangeDeleter
- type TxnDelete
Constants ¶
const MaxLeaseTTL = 9000000000
MaxLeaseTTL is the maximum lease TTL value
const NoLease = LeaseID(0)
NoLease is a special LeaseID representing the absence of a lease.
Variables ¶
var ( ErrNotPrimary = errors.New("not a primary lessor") ErrLeaseNotFound = errors.New("lease not found") ErrLeaseExists = errors.New("lease already exists") ErrLeaseTTLTooLarge = errors.New("too large lease TTL") )
Types ¶
type Checkpointer ¶
type Checkpointer func(ctx context.Context, lc *pb.LeaseCheckpointRequest) error
Checkpointer permits checkpointing of lease remaining TTLs to the consensus log. Defined here to avoid circular dependency with mvcc.
type FakeLessor ¶
type FakeLessor struct {
LeaseSet map[LeaseID]struct{}
}
FakeLessor is a fake implementation of Lessor interface. Used for testing only.
func (*FakeLessor) Attach ¶
func (fl *FakeLessor) Attach(id LeaseID, items []LeaseItem) error
func (*FakeLessor) Checkpoint ¶
func (fl *FakeLessor) Checkpoint(id LeaseID, remainingTTL int64) error
func (*FakeLessor) Demote ¶
func (fl *FakeLessor) Demote()
func (*FakeLessor) Detach ¶
func (fl *FakeLessor) Detach(id LeaseID, items []LeaseItem) error
func (*FakeLessor) ExpiredLeasesC ¶
func (fl *FakeLessor) ExpiredLeasesC() <-chan []*Lease
func (*FakeLessor) GetLease ¶
func (fl *FakeLessor) GetLease(item LeaseItem) LeaseID
func (*FakeLessor) Grant ¶
func (fl *FakeLessor) Grant(id LeaseID, ttl int64) (*Lease, error)
func (*FakeLessor) Leases ¶
func (fl *FakeLessor) Leases() []*Lease
func (*FakeLessor) Lookup ¶
func (fl *FakeLessor) Lookup(id LeaseID) *Lease
func (*FakeLessor) Promote ¶
func (fl *FakeLessor) Promote(extend time.Duration)
func (*FakeLessor) Recover ¶
func (fl *FakeLessor) Recover(b backend.Backend, rd RangeDeleter)
func (*FakeLessor) Renew ¶
func (fl *FakeLessor) Renew(id LeaseID) (int64, error)
func (*FakeLessor) Revoke ¶
func (fl *FakeLessor) Revoke(id LeaseID) error
func (*FakeLessor) SetCheckpointer ¶
func (fl *FakeLessor) SetCheckpointer(cp Checkpointer)
func (*FakeLessor) SetRangeDeleter ¶
func (fl *FakeLessor) SetRangeDeleter(dr RangeDeleter)
func (*FakeLessor) Stop ¶
func (fl *FakeLessor) Stop()
type FakeTxnDelete ¶
func (*FakeTxnDelete) DeleteRange ¶
func (ftd *FakeTxnDelete) DeleteRange(key, end []byte) (n, rev int64)
func (*FakeTxnDelete) End ¶
func (ftd *FakeTxnDelete) End()
type Lease ¶
type Lease struct {
ID LeaseID
// contains filtered or unexported fields
}
func NewLease ¶
func (*Lease) Demoted ¶
Demoted returns true if the lease's expiry has been reset to forever.
func (*Lease) Keys ¶
Keys returns all the keys attached to the lease.
func (*Lease) Remaining ¶
Remaining returns the remaining time of the lease.
func (*Lease) SetLeaseItem ¶
SetLeaseItem sets the given lease item, this func is thread-safe
func (*Lease) TTL ¶
TTL returns the TTL of the Lease.
type LeaseExpiredNotifier ¶
type LeaseExpiredNotifier struct {
// contains filtered or unexported fields
}
LeaseExpiredNotifier is a queue used to notify lessor to revoke expired lease. Only save one item for a lease, `Register` will update time of the corresponding lease.
func (*LeaseExpiredNotifier) Init ¶
func (mq *LeaseExpiredNotifier) Init()
func (*LeaseExpiredNotifier) Len ¶
func (mq *LeaseExpiredNotifier) Len() int
func (*LeaseExpiredNotifier) Peek ¶
func (mq *LeaseExpiredNotifier) Peek() *LeaseWithTime
func (*LeaseExpiredNotifier) RegisterOrUpdate ¶
func (mq *LeaseExpiredNotifier) RegisterOrUpdate(item *LeaseWithTime)
func (*LeaseExpiredNotifier) Unregister ¶
func (mq *LeaseExpiredNotifier) Unregister() *LeaseWithTime
type LeaseID ¶
type LeaseID int64
type LeaseItem ¶
type LeaseItem struct {
Key string
}
type LeaseQueue ¶
type LeaseQueue []*LeaseWithTime
func (LeaseQueue) Len ¶
func (pq LeaseQueue) Len() int
func (LeaseQueue) Less ¶
func (pq LeaseQueue) Less(i, j int) bool
func (*LeaseQueue) Pop ¶
func (pq *LeaseQueue) Pop() any
func (*LeaseQueue) Push ¶
func (pq *LeaseQueue) Push(x any)
func (LeaseQueue) Swap ¶
func (pq LeaseQueue) Swap(i, j int)
type LeaseWithTime ¶
type LeaseWithTime struct {
// contains filtered or unexported fields
}
LeaseWithTime contains lease object with a time. For the lessor's lease heap, time identifies the lease expiration time. For the lessor's lease checkpoint heap, the time identifies the next lease checkpoint time.
type Lessor ¶
type Lessor interface {
// SetRangeDeleter lets the lessor create TxnDeletes to the store.
// Lessor deletes the items in the revoked or expired lease by creating
// new TxnDeletes.
SetRangeDeleter(rd RangeDeleter)
SetCheckpointer(cp Checkpointer)
// Grant grants a lease that expires at least after TTL seconds.
Grant(id LeaseID, ttl int64) (*Lease, error)
// Revoke revokes a lease with given ID. The item attached to the
// given lease will be removed. If the ID does not exist, an error
// will be returned.
Revoke(id LeaseID) error
// Checkpoint applies the remainingTTL of a lease. The remainingTTL is used in Promote to set
// the expiry of leases to less than the full TTL when possible.
Checkpoint(id LeaseID, remainingTTL int64) error
// Attach attaches given leaseItem to the lease with given LeaseID.
// If the lease does not exist, an error will be returned.
Attach(id LeaseID, items []LeaseItem) error
// GetLease returns LeaseID for given item.
// If no lease found, NoLease value will be returned.
GetLease(item LeaseItem) LeaseID
// Detach detaches given leaseItem from the lease with given LeaseID.
// If the lease does not exist, an error will be returned.
Detach(id LeaseID, items []LeaseItem) error
// Promote promotes the lessor to be the primary lessor. Primary lessor manages
// the expiration and renew of leases.
// Newly promoted lessor renew the TTL of all lease to extend + previous TTL.
Promote(extend time.Duration)
// Demote demotes the lessor from being the primary lessor.
Demote()
// Renew renews a lease with given ID. It returns the renewed TTL. If the ID does not exist,
// an error will be returned.
Renew(id LeaseID) (int64, error)
// Lookup gives the lease at a given lease id, if any
Lookup(id LeaseID) *Lease
// Leases lists all leases.
Leases() []*Lease
// ExpiredLeasesC returns a chan that is used to receive expired leases.
ExpiredLeasesC() <-chan []*Lease
// Recover recovers the lessor state from the given backend and RangeDeleter.
Recover(b backend.Backend, rd RangeDeleter)
// Stop stops the lessor for managing leases. The behavior of calling Stop multiple
// times is undefined.
Stop()
}
Lessor owns leases. It can grant, revoke, renew and modify leases for lessee.
func NewLessor ¶
type LessorConfig ¶
type LessorConfig struct {
MinLeaseTTL int64
CheckpointInterval time.Duration
ExpiredLeasesRetryInterval time.Duration
CheckpointPersist bool
// contains filtered or unexported fields
}
type RangeDeleter ¶
type RangeDeleter func() TxnDelete
RangeDeleter is a TxnDelete constructor.
type TxnDelete ¶
TxnDelete is a TxnWrite that only permits deletes. Defined here to avoid circular dependency with mvcc.
Source Files ¶
doc.go lease.go lease_queue.go lessor.go metrics.go
Directories ¶
| Path | Synopsis |
|---|---|
| lease/leasehttp | Package leasehttp serves lease renewals made through HTTP requests. |
| lease/leasepb |
- Version
- v3.6.10 (latest)
- Published
- Apr 1, 2026
- Platform
- linux/amd64
- Imports
- 15 packages
- Last checked
- 2 weeks ago –
Tools for package owners.