lock

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2016 License: Apache-2.0 Imports: 7 Imported by: 12

Documentation

Overview

Package lock implements coordinated etcd locking across multiple locks to provide a safe experience between different parts of the volplugin system.

Currently this package coordinates create, remove, mount and snapshot locks. Snapshot locks in particular are special; they are a secondary lock that exists for remove operations only.

goroutine-safe functions to manage TTL-safe reporting also exist here.

Index

Constants

View Source
const (
	// ReasonCreate is the "create" reason for the lock
	ReasonCreate = "Create"
	// ReasonMount is the "mount" reason for the lock
	ReasonMount = "Mount"
	// ReasonRemove is the "remove" reason for the lock
	ReasonRemove = "Remove"

	// ReasonSnapshot is the "snapshot" reason for the lock
	ReasonSnapshot = "Snapshot"
	// ReasonSnapshotPrune is the prune operation for snapshots
	ReasonSnapshotPrune = "SnapshotPrune"

	// ReasonCopy indicates a copy from snapshot operation.
	ReasonCopy = "Copy"
	// ReasonMaintenance indicates that an operator is acquiring the lock.
	ReasonMaintenance = "Maintenance"
)

Variables

View Source
var (
	// Unlocked is a string indicating unlocked operation, this is typically used
	// as a hostname for our locking system.
	Unlocked = "-unlocked-"
)

Functions

This section is empty.

Types

type Driver

type Driver struct {
	Config *config.Client
}

Driver is the top-level struct for lock objects

func NewDriver

func NewDriver(config *config.Client) *Driver

NewDriver creates a Driver. Requires a configured Client.

func (*Driver) AcquireWithTTLRefresh added in v0.2.0

func (d *Driver) AcquireWithTTLRefresh(uc config.UseLocker, ttl, timeout time.Duration) (chan struct{}, error)

AcquireWithTTLRefresh accepts a UseLocker, and attempts to acquire the lock. When it successfully does, it then spawns a goroutine to refresh the lock after a timeout, returning a stop channel. Timeout is jittered to mitigate thundering herd problems.

func (*Driver) ClearLock added in v0.2.0

func (d *Driver) ClearLock(uc config.UseLocker, timeout time.Duration) error

ClearLock removes a lock with a compare/swap first.

func (*Driver) ExecuteWithMultiUseLock

func (d *Driver) ExecuteWithMultiUseLock(ucs []config.UseLocker, timeout time.Duration, runFunc func(d *Driver, ucs []config.UseLocker) error) error

ExecuteWithMultiUseLock takes several UseLockers and tries to lock them all at the same time. If it fails, it returns an error. If timeout is zero, it will not attempt to retry acquiring the lock. Otherwise, it will attempt to wait for the provided timeout and only return an error if it fails to acquire them in time.

func (*Driver) ExecuteWithUseLock

func (d *Driver) ExecuteWithUseLock(uc config.UseLocker, runFunc func(d *Driver, uc config.UseLocker) error) error

ExecuteWithUseLock executes a function within a lock/context of the passed *config.UseMount.

Directories

Path Synopsis
Package client implements a client to the apiserver to acquire locks.
Package client implements a client to the apiserver to acquire locks.

Jump to

Keyboard shortcuts

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