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 ¶
- Variables
- type Lock
- type LockProvider
- type LockTestSuite
- func (s *LockTestSuite) AssertLock(l Lock) (failCh <-chan struct{})
- func (s *LockTestSuite) AssertLockBeforeTimeout(l Lock, timeout time.Duration) <-chan struct{}
- func (s *LockTestSuite) AssertLockTimedOut(l Lock, timeout time.Duration)
- func (s *LockTestSuite) AssertUnlock(l Lock)
- func (s *LockTestSuite) AssertUnlockNotHeld(l Lock)
- func (s *LockTestSuite) TestLock()
- type MockLockProvider
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 (*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