lease - ActiveState ActiveGo 1.8
...

Package lease

import "github.com/coreos/etcd/lease"
Overview
Index
Subdirectories

Overview ▾

Package lease provides an interface and implemetation for time-limited leases over arbitrary resources.

Constants

const (
    // NoLease is a special LeaseID representing the absence of a lease.
    NoLease = LeaseID(0)
)

Variables

var (
    ErrNotPrimary    = errors.New("not a primary lessor")
    ErrLeaseNotFound = errors.New("lease not found")
    ErrLeaseExists   = errors.New("lease already exists")
)

type FakeLessor

FakeLessor is a fake implementation of Lessor interface. Used for testing only.

type FakeLessor struct{}

func (*FakeLessor) Attach

func (fl *FakeLessor) Attach(id LeaseID, items []LeaseItem) 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) Lookup

func (le *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) SetRangeDeleter

func (fl *FakeLessor) SetRangeDeleter(dr RangeDeleter)

func (*FakeLessor) Stop

func (fl *FakeLessor) Stop()

type Lease

type Lease struct {
    ID LeaseID
    // contains filtered or unexported fields
}

func (*Lease) Keys

func (l *Lease) Keys() []string

Keys returns all the keys attached to the lease.

func (*Lease) Remaining

func (l *Lease) Remaining() time.Duration

Remaining returns the remaining time of the lease.

func (*Lease) TTL

func (l *Lease) TTL() int64

TTL returns the TTL of the Lease.

type LeaseID

type LeaseID int64

type LeaseItem

type LeaseItem struct {
    Key string
}

type Lessor

Lessor owns leases. It can grant, revoke, renew and modify leases for lessee.

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.
    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

    // 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

    // 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()
}

func NewLessor

func NewLessor(b backend.Backend, minLeaseTTL int64) Lessor

type RangeDeleter

RangeDeleter is a TxnDelete constructor.

type RangeDeleter func() TxnDelete

type TxnDelete

TxnDelete is a TxnWrite that only permits deletes. Defined here to avoid circular dependency with mvcc.

type TxnDelete interface {
    DeleteRange(key, end []byte) (n, rev int64)
    End()
}

Subdirectories

Name Synopsis
..
leasehttp Package leasehttp serves lease renewals made through HTTP requests.
leasepb Package leasepb is a generated protocol buffer package.