Documentation
¶
Overview ¶
Distributed Lock Manager (DLM) provides locking between threads on the same system and between threads on different systems.
Example use of the lock:
type myStruct struct { Acct string Volume string InodeNum uint64 myRwLock *RWLockStruct }
func my_function() { var myval myStruct myval.Acct = "Acct1" myval.Volume = "Vol1" myval.InodeNum = 11 myLockId := fmt.Sprintf("%s:%s:%v\n", myval.Acct, myval.Volume, myval.InodeNum) myCookie := GenerateCallerID() myval.myRwLock = &RWLockStruct{LockID: myLockId, Notify: nil, LockCallerID: myCookie} myval.myRwLock.ReadLock() myval.myRwLock.Unlock() myval.myRwLock.WriteLock() myval.myRwLock.Unlock() err := myval.myRwLock.TryReadLock() errno := blunder.Errno(err) switch errno { case 0: log.Printf("Got TryReadLock") myval.myRwLock.Unlock() case EAGAIN: // give up other locks. default: // something wrong.. } err = myval.myRwLock.TryWriteLock() errno := blunder.Errno(err) switch errno { case 0: log.Printf("Got TryWriteLock") myval.myRwLock.Unlock() case EAGAIN: // give up other locks. default: // something wrong.. } }
Index ¶
- func IsLockHeld(lockID string, callerID CallerID, lockHeldType LockHeldType) (held bool)
- type CallerID
- type LockHeldType
- type Notify
- type NotifyReason
- type RWLockStruct
- func (l *RWLockStruct) GetCallerID() CallerID
- func (l *RWLockStruct) GetLockID() string
- func (l *RWLockStruct) IsReadHeld() bool
- func (l *RWLockStruct) IsWriteHeld() bool
- func (l *RWLockStruct) ReadLock() (err error)
- func (l *RWLockStruct) TryReadLock() (err error)
- func (l *RWLockStruct) TryWriteLock() (err error)
- func (l *RWLockStruct) Unlock() (err error)
- func (l *RWLockStruct) WriteLock() (err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsLockHeld ¶
func IsLockHeld(lockID string, callerID CallerID, lockHeldType LockHeldType) (held bool)
IsLockHeld() returns
Types ¶
type CallerID ¶
type CallerID *string
func GenerateCallerID ¶
func GenerateCallerID() (callerID CallerID)
GenerateCallerID() returns a cluster wide unique number useful in deadlock detection.
type LockHeldType ¶
type LockHeldType uint32
const ( ANYLOCK LockHeldType = iota + 1 READLOCK WRITELOCK )
type Notify ¶
type Notify interface {
NotifyNodeChange(reason NotifyReason) // DLM will call the last node which owns the lock before handing over
}
type NotifyReason ¶
type NotifyReason uint32
const ( ReasonWriteRequest NotifyReason = iota + 1 // Another thread in the cluster wants "Write" access ReasonReadRequest // Another thread wants "Read" access )
type RWLockStruct ¶
func (*RWLockStruct) GetCallerID ¶
func (l *RWLockStruct) GetCallerID() CallerID
CallerID returns the caller ID from the lock struct
func (*RWLockStruct) GetLockID ¶
func (l *RWLockStruct) GetLockID() string
GetLockID() returns the lock ID from the lock struct
func (*RWLockStruct) IsReadHeld ¶
func (l *RWLockStruct) IsReadHeld() bool
Returns whether the lock is held for reading
func (*RWLockStruct) IsWriteHeld ¶
func (l *RWLockStruct) IsWriteHeld() bool
Returns whether the lock is held for writing
func (*RWLockStruct) ReadLock ¶
func (l *RWLockStruct) ReadLock() (err error)
ReadLock() blocks until the lock for the inode can be held shared.
func (*RWLockStruct) TryReadLock ¶
func (l *RWLockStruct) TryReadLock() (err error)
TryReadLock() attempts to grab the lock if is is free or shared. Otherwise, it returns EAGAIN.
func (*RWLockStruct) TryWriteLock ¶
func (l *RWLockStruct) TryWriteLock() (err error)
TryWriteLock() attempts to grab the lock if is is free. Otherwise, it returns EAGAIN.
func (*RWLockStruct) Unlock ¶
func (l *RWLockStruct) Unlock() (err error)
Unlock() releases the lock and signals any waiters that the lock is free.
func (*RWLockStruct) WriteLock ¶
func (l *RWLockStruct) WriteLock() (err error)
WriteLock() blocks until the lock for the inode can be held exclusively.