lease

package
v0.3.1-0...-e7f50d8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2016 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

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

Variables

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

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) Attach

func (fl *FakeLessor) Attach(id LeaseID, items []LeaseItem) error

func (*FakeLessor) Demote

func (fl *FakeLessor) Demote()

func (*FakeLessor) ExpiredLeasesC

func (fl *FakeLessor) ExpiredLeasesC() <-chan []*Lease

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

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
	TTL int64 // time to live in seconds
	// contains filtered or unexported fields
}

type LeaseID

type LeaseID int64

type LeaseItem

type LeaseItem struct {
	Key string
}

type Lessor

type Lessor interface {
	// SetDeleteableRange sets the RangeDeleter to the Lessor.
	// Lessor deletes the items in the revoked or expired lease from the
	// the set RangeDeleter.
	SetRangeDeleter(dr 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

	// Promote promotes the lessor to be the primary lessor. Primary lessor manages
	// the expiration and renew of leases.
	Promote()

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

	// Stop stops the lessor for managing leases. The behavior of calling Stop multiple
	// times is undefined.
	Stop()
}

A Lessor is the owner of leases. It can grant, revoke, renew and modify leases for lessee.

func NewLessor

func NewLessor(b backend.Backend) Lessor

type RangeDeleter

type RangeDeleter interface {
	DeleteRange(key, end []byte) (int64, int64)
}

RangeDeleter defines an interface with DeleteRange method. We define this interface only for lessor to limit the number of methods of storage.KV to what lessor actually needs.

Having a minimum interface makes testing easy.

Directories

Path Synopsis
Package leasepb is a generated protocol buffer package.
Package leasepb is a generated protocol buffer package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL