dsync

package
v0.0.0-...-fb0f190 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2022 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTimeouts = Timeouts{
	Acquire:         drwMutexAcquireTimeout,
	RefreshCall:     drwMutexRefreshCallTimeout,
	UnlockCall:      drwMutexUnlockCallTimeout,
	ForceUnlockCall: drwMutexForceUnlockCallTimeout,
}

DefaultTimeouts contains default timeouts.

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

func NewDRWMutex(clnt *Dsync, names ...string) *DRWMutex

NewDRWMutex - initializes a new dsync RW mutex.

func (*DRWMutex) GetLock

func (dm *DRWMutex) GetLock(ctx context.Context, cancel context.CancelFunc, id, source string, opts Options) (locked bool)

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

func (dm *DRWMutex) GetRLock(ctx context.Context, cancel context.CancelFunc, id, source string, opts Options) (locked bool)

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

func (dm *DRWMutex) Lock(id, source string)

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

func (dm *DRWMutex) RLock(id, source string)

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.

func (*DRWMutex) RUnlock

func (dm *DRWMutex) RUnlock()

RUnlock releases a read lock held on dm.

It is a run-time error if dm is not locked on entry to RUnlock.

func (*DRWMutex) Unlock

func (dm *DRWMutex) Unlock()

Unlock unlocks the write lock.

It is a run-time error if dm is not locked on entry to Unlock.

type Dsync

type Dsync struct {
	// List of rest client objects, one per lock server.
	GetLockers func() ([]NetLocker, string)

	// Timeouts to apply.
	Timeouts Timeouts
}

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

	// Owner represents unique ID for this instance, an owner who originally requested
	// the locked resource, useful primarily in figuring our stale locks.
	Owner string

	// Quorum represents the expected quorum for this lock type.
	Quorum int
}

LockArgs is minimal required values for any dsync compatible lock operation.

func (*LockArgs) DecodeMsg

func (z *LockArgs) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*LockArgs) EncodeMsg

func (z *LockArgs) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*LockArgs) MarshalMsg

func (z *LockArgs) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*LockArgs) Msgsize

func (z *LockArgs) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*LockArgs) UnmarshalMsg

func (z *LockArgs) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

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.
	// Canceling the context will abort the remote call.
	// In that case, the resource may or may not be unlocked.
	RUnlock(ctx context.Context, 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.
	// Canceling the context will abort the remote call.
	// In that case, the resource may or may not be unlocked.
	Unlock(ctx context.Context, args LockArgs) (bool, error)

	// Refresh the given lock to prevent it from becoming stale
	Refresh(ctx context.Context, args LockArgs) (bool, error)

	// Unlock (read/write) forcefully for given LockArgs. It should return
	// * a boolean to indicate success/failure of the operation
	// * an error on failure of unlock request operation.
	ForceUnlock(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

	// Is the underlying locker local to this server?
	IsLocal() bool
}

NetLocker is dsync compatible locker interface.

type Options

type Options struct {
	Timeout       time.Duration
	RetryInterval time.Duration
}

Options lock options.

type Timeouts

type Timeouts struct {
	// Acquire - tolerance limit to wait for lock acquisition before.
	Acquire time.Duration

	// RefreshCall - timeout for the refresh call
	RefreshCall time.Duration

	// UnlockCall - timeout for the unlock call
	UnlockCall time.Duration

	// ForceUnlockCall - timeout for the force unlock call
	ForceUnlockCall time.Duration
}

Timeouts are timeouts for specific operations.

Jump to

Keyboard shortcuts

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