cockroach: Index | Files

package leasemanager

import ""

Package leasemanager provides functionality for acquiring and managing leases via the kv api for use during sqlmigrations.


Package Files

lease.go lease.pb.go


const DefaultLeaseDuration = 1 * time.Minute

DefaultLeaseDuration is the duration a lease will be acquired for if no duration was specified in a LeaseManager's options. Exported for testing purposes.


var (
    ErrInvalidLengthLease = fmt.Errorf("proto: negative length found during unmarshaling")
    ErrIntOverflowLease   = fmt.Errorf("proto: integer overflow")

type Lease Uses

type Lease struct {
    // contains filtered or unexported fields

Lease contains the state of a lease on a particular key.

type LeaseManager Uses

type LeaseManager struct {
    // contains filtered or unexported fields

LeaseManager provides functionality for acquiring and managing leases via the kv api.

func New Uses

func New(db *kv.DB, clock *hlc.Clock, options Options) *LeaseManager

New allocates a new LeaseManager.

func (*LeaseManager) AcquireLease Uses

func (m *LeaseManager) AcquireLease(ctx context.Context, key roachpb.Key) (*Lease, error)

AcquireLease attempts to grab a lease on the provided key. Returns a non-nil lease object if it was successful, or an error if it failed to acquire the lease for any reason.

NB: Acquiring a non-expired lease is allowed if this LeaseManager's clientID matches the lease owner's ID. This behavior allows a process to re-grab leases without having to wait if it restarts and uses the same ID.

func (*LeaseManager) ExtendLease Uses

func (m *LeaseManager) ExtendLease(ctx context.Context, l *Lease) error

ExtendLease attempts to push the expiration time of the lease farther out into the future.

func (*LeaseManager) ReleaseLease Uses

func (m *LeaseManager) ReleaseLease(ctx context.Context, l *Lease) error

ReleaseLease attempts to release the given lease so that another process can grab it.

func (*LeaseManager) TimeRemaining Uses

func (m *LeaseManager) TimeRemaining(l *Lease) time.Duration

TimeRemaining returns the amount of time left on the given lease.

type LeaseNotAvailableError Uses

type LeaseNotAvailableError struct {
    // contains filtered or unexported fields

LeaseNotAvailableError indicates that the lease the caller attempted to acquire is currently held by a different client.

func (*LeaseNotAvailableError) Error Uses

func (e *LeaseNotAvailableError) Error() string

type LeaseVal Uses

type LeaseVal struct {
    // An opaque string that should be unique per client to identify which client
    // owns the lease.
    Owner string `protobuf:"bytes,1,opt,name=owner" json:"owner"`
    // The expiration time of the lease.
    Expiration hlc.Timestamp `protobuf:"bytes,2,opt,name=expiration" json:"expiration"`

func (*LeaseVal) Descriptor Uses

func (*LeaseVal) Descriptor() ([]byte, []int)

func (*LeaseVal) Marshal Uses

func (m *LeaseVal) Marshal() (dAtA []byte, err error)

func (*LeaseVal) MarshalTo Uses

func (m *LeaseVal) MarshalTo(dAtA []byte) (int, error)

func (*LeaseVal) ProtoMessage Uses

func (*LeaseVal) ProtoMessage()

func (*LeaseVal) Reset Uses

func (m *LeaseVal) Reset()

func (*LeaseVal) Size Uses

func (m *LeaseVal) Size() (n int)

func (*LeaseVal) String Uses

func (m *LeaseVal) String() string

func (*LeaseVal) Unmarshal Uses

func (m *LeaseVal) Unmarshal(dAtA []byte) error

func (*LeaseVal) XXX_DiscardUnknown Uses

func (m *LeaseVal) XXX_DiscardUnknown()

func (*LeaseVal) XXX_Marshal Uses

func (m *LeaseVal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*LeaseVal) XXX_Merge Uses

func (dst *LeaseVal) XXX_Merge(src proto.Message)

func (*LeaseVal) XXX_Size Uses

func (m *LeaseVal) XXX_Size() int

func (*LeaseVal) XXX_Unmarshal Uses

func (m *LeaseVal) XXX_Unmarshal(b []byte) error

type Options Uses

type Options struct {
    // ClientID must be unique to this LeaseManager instance.
    ClientID      string
    LeaseDuration time.Duration

Options are used to configure a new LeaseManager.

Package leasemanager imports 11 packages (graph) and is imported by 3 packages. Updated 2020-08-12. Refresh now. Tools for package owners.