dlm

package
v0.0.0-...-4017c26 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

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

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

type RWLockStruct struct {
	LockID       string
	Notify       Notify
	LockCallerID CallerID
}

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.

Jump to

Keyboard shortcuts

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