Documentation ¶
Index ¶
- Constants
- type DRWMutex
- func (dm *DRWMutex) GetLock(ctx context.Context, id, source string, opts Options) (locked bool)
- func (dm *DRWMutex) GetRLock(ctx context.Context, id, source string, opts Options) (locked bool)
- func (dm *DRWMutex) Lock(id, source string)
- func (dm *DRWMutex) RLock(id, source string)
- func (dm *DRWMutex) RUnlock()
- func (dm *DRWMutex) Unlock()
- type Dsync
- type Granted
- type LockArgs
- type NetLocker
- type Options
Constants ¶
const DRWMutexAcquireTimeout = 1 * time.Second // 1 second.
DRWMutexAcquireTimeout - tolerance limit to wait for lock acquisition before.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DRWMutex ¶
type DRWMutex struct { Names []string // contains filtered or unexported fields }
A DRWMutex is a distributed mutual exclusion lock.
func NewDRWMutex ¶
NewDRWMutex - initializes a new dsync RW mutex.
func (*DRWMutex) GetLock ¶
GetLock tries to get a write lock on dm before the timeout elapses.
If the lock is already in use, the calling go routine blocks until either the mutex becomes available and return success or more time has passed than the timeout value and return false.
func (*DRWMutex) GetRLock ¶
GetRLock tries to get a read lock on dm before the timeout elapses.
If one or more read locks are already in use, it will grant another lock. Otherwise the calling go routine blocks until either the mutex becomes available and return success or more time has passed than the timeout value and return false.
func (*DRWMutex) Lock ¶
Lock holds a write lock on dm.
If the lock is already in use, the calling go routine blocks until the mutex is available.
func (*DRWMutex) RLock ¶
RLock holds a read lock on dm.
If one or more read locks are already in use, it will grant another lock. Otherwise the calling go routine blocks until the mutex is available.
type Dsync ¶
type Dsync struct { // List of rest client objects, one per lock server. GetLockersFn func() []NetLocker }
Dsync represents dsync client object which is initialized with authenticated clients, used to initiate lock REST calls.
type Granted ¶
type Granted struct {
// contains filtered or unexported fields
}
Granted - represents a structure of a granted lock.
type LockArgs ¶
type LockArgs struct { // Unique ID of lock/unlock request. UID string // Resources contains single or multiple entries to be locked/unlocked. Resources []string // Source contains the line number, function and file name of the code // on the client node that requested the lock. Source string }
LockArgs is minimal required values for any dsync compatible lock operation.
type NetLocker ¶
type NetLocker interface { // Do read lock for given LockArgs. It should return // * a boolean to indicate success/failure of the operation // * an error on failure of lock request operation. RLock(ctx context.Context, args LockArgs) (bool, error) // Do write lock for given LockArgs. It should return // * a boolean to indicate success/failure of the operation // * an error on failure of lock request operation. Lock(ctx context.Context, args LockArgs) (bool, error) // Do read unlock for given LockArgs. It should return // * a boolean to indicate success/failure of the operation // * an error on failure of unlock request operation. RUnlock(args LockArgs) (bool, error) // Do write unlock for given LockArgs. It should return // * a boolean to indicate success/failure of the operation // * an error on failure of unlock request operation. Unlock(args LockArgs) (bool, error) // Expired returns if current lock args has expired. Expired(ctx context.Context, args LockArgs) (bool, error) // Returns underlying endpoint of this lock client instance. String() string // Close closes any underlying connection to the service endpoint Close() error // Is the underlying connection online? (is always true for any local lockers) IsOnline() bool }
NetLocker is dsync compatible locker interface.