locking

package
v0.0.0-...-171db1f Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2015 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package locking provides distributed locking.

Locking is provided by a LockProvider implementation, from which specific locks are retrieved. These locks can subsequently be used to obtain mutually exclusive locking.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Lock is not currently held.
	ErrNotLocked = errors.New("lock is not currently held")

	// Lock is already held.
	ErrLocked = errors.New("lock is already held")

	// Lock acquisition timed out.
	ErrTimeout = errors.New("lock acquisition timed out")

	// Lock cancelled.
	ErrCancelled = errors.New("lock acquisition cancelled")
)

Functions

This section is empty.

Types

type Lock

type Lock interface {
	// Lock.
	//
	// Only returns an error if an unrecoverable error occurs. Otherwise,
	// returns a channel which receives an empty struct if the lock is lost.
	Lock() (<-chan struct{}, error)

	// Lock with timeout.
	//
	// Only returns an error if an unrecoverable error occurs or the lock is
	// not acquired before a certain timeout is reached. Otherwise, returns
	// a channel which receives an empty struct if the lock is lost.
	LockTimeout(time.Duration) (<-chan struct{}, error)

	// Unlock.
	//
	// Only returns an error if an unrecoverable error occurs.
	Unlock() error
}

Lock.

type LockProvider

type LockProvider interface {
	// Get a lock.
	GetLock(path string) Lock
}

Lock provider.

func NewZooKeeperLockProvider

func NewZooKeeperLockProvider(connMan *zkutils.ConnMan, acl []zk.ACL) LockProvider

New ZooKeeper lock provider.

type LockTestSuite

type LockTestSuite struct {
	unittest.TestSuite

	LockProvider LockProvider
}

Lock test suite.

func (*LockTestSuite) AssertLock

func (s *LockTestSuite) AssertLock(l Lock) (failCh <-chan struct{})

Assert that a lock is acquired by a call to Lock.

func (*LockTestSuite) AssertLockBeforeTimeout

func (s *LockTestSuite) AssertLockBeforeTimeout(l Lock, timeout time.Duration) <-chan struct{}

Assert that a lock is acquired before a timeout.

func (*LockTestSuite) AssertLockTimedOut

func (s *LockTestSuite) AssertLockTimedOut(l Lock, timeout time.Duration)

Assert that the attempt to acquire a lock with timeout times out.

func (*LockTestSuite) AssertUnlock

func (s *LockTestSuite) AssertUnlock(l Lock)

Assert that a lock is unlocked successfully.

func (*LockTestSuite) AssertUnlockNotHeld

func (s *LockTestSuite) AssertUnlockNotHeld(l Lock)

Assert that unlocking a lock returns that the lock is not held.

func (*LockTestSuite) TestLock

func (s *LockTestSuite) TestLock()

type MockLockProvider

type MockLockProvider struct {
	// contains filtered or unexported fields
}

Mock lock provider.

Provides mock locks. All mock locks must use the same provider for mutual exclusivity to be in effect.

func NewMockLockProvider

func NewMockLockProvider() *MockLockProvider

New mock lock provider.

func (*MockLockProvider) Fail

func (p *MockLockProvider) Fail()

Fail the lock provider.

Fails any currently held locks and does not allow new locks to be acquried until the lock provider is recovered.

func (*MockLockProvider) GetLock

func (p *MockLockProvider) GetLock(path string) Lock

func (*MockLockProvider) Recover

func (p *MockLockProvider) Recover()

Recover the lock provider.

Jump to

Keyboard shortcuts

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