Documentation
¶
Overview ¶
Package lease provides an interface and implementation for time-limited leases over arbitrary resources.
Index ¶
- Constants
- Variables
- type FakeLessor
- func (fl *FakeLessor) Attach(id LeaseID, items []LeaseItem) 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) SetRangeDeleter(dr RangeDeleter)
- func (fl *FakeLessor) Stop()
- type Lease
- type LeaseID
- type LeaseItem
- type Lessor
- type RangeDeleter
- type TxnDelete
Constants ¶
View Source
const MaxLeaseTTL = 9000000000
MaxLeaseTTL is the maximum lease TTL value
View Source
const NoLease = LeaseID(0)
NoLease is a special LeaseID representing the absence of a lease.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type FakeLessor ¶
type FakeLessor struct{}
FakeLessor is a fake implementation of Lessor interface. Used for testing only.
func (*FakeLessor) Demote ¶
func (fl *FakeLessor) Demote()
func (*FakeLessor) ExpiredLeasesC ¶
func (fl *FakeLessor) ExpiredLeasesC() <-chan []*Lease
func (*FakeLessor) GetLease ¶
func (fl *FakeLessor) GetLease(item LeaseItem) LeaseID
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) Revoke ¶
func (fl *FakeLessor) Revoke(id LeaseID) error
func (*FakeLessor) SetRangeDeleter ¶
func (fl *FakeLessor) SetRangeDeleter(dr RangeDeleter)
func (*FakeLessor) Stop ¶
func (fl *FakeLessor) Stop()
type Lease ¶
type Lease struct { ID LeaseID //该Lease实例的唯一标识 // contains filtered or unexported fields }
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) // Grant grants a lease that expires at least after TTL seconds. 创建Lease实例,该Lease会在指定的时间(ttl)之后过期 Grant(id LeaseID, ttl int64) (*Lease, error) // Revoke revokes a lease with given ID. The item attached to the 撤销指定的Lease,该Lease实例相关的LeastItem也会被删除 // given lease will be removed. If the ID does not exist, an error // will be returned. Revoke(id LeaseID) error // Attach attaches given leaseItem to the lease with given LeaseID. 将指定Lease与指定LeastItem绑定,在LeaseItem中封装了键值对的Key值 // If the lease does not exist, an error will be returned. Attach(id LeaseID, items []LeaseItem) error // GetLease returns LeaseID for given item. 根据LeaseItem查询对应Lease实例的id // If no lease found, NoLease value will be returned. GetLease(item LeaseItem) LeaseID // Detach detaches given leaseItem from the lease with given LeaseID. 取消指定Lease与指定LeastItem之间的绑定关系 // 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 如果当前节点成为Leader节点,则其使用的Lessor实例将通过该方法晋升,成为主 // the expiration and renew of leases. Lessor。主Lessor将控制着整个集群中所有Lease实例 // 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. 如果当前节点从Leader状态转换为其他状态,则会通过该方法将其使用的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) //续约指定的Lease实例 // Lookup gives the lease at a given lease id, if any 查找指定id对应的Lease实例 Lookup(id LeaseID) *Lease // Leases lists all leases. Leases() []*Lease // ExpiredLeasesC returns a chan that is used to receive expired leases. 如果出现lease实例过期,则会被写入到ExpiredLeaseC通道中 ExpiredLeasesC() <-chan []*Lease // Recover recovers the lessor state from the given backend and RangeDeleter. 从底层的V3存储中恢复Lease实例 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.
Click to show internal directories.
Click to hide internal directories.