dlock

package
v0.0.0-...-625d4c4 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DLock

type DLock interface {
	Acquire()
	Release()
}

DLock constrains the methods a real distributed lock should implement.

type FastDLock

type FastDLock struct {
	// contains filtered or unexported fields
}

FastDLock implements the distributed lock using zookeeper.

func NewFastDLock

func NewFastDLock() *FastDLock

NewFastDLock creates a FastDLock instance.

==> acquire lock n = create("/zklock/fast-lock/request-", "", empheral|sequential) retry:

requests = getChildren("/zklock/fast-lock", false)
if n is lowest znode in requests:
    return
else:
    exists("/zklock/fast-lock/request-" % n - 1, watch = True)

watch_event:

goto retry

==> release lock (voluntarily or session timeout) delete("/zklock/fast-lock/request-" % n)

func (*FastDLock) Acquire

func (dl *FastDLock) Acquire(conn *zookeeper.Conn, tryTimeout time.Duration) bool

Acquire implements the distributed lock methed.

func (*FastDLock) Release

func (dl *FastDLock) Release(conn *zookeeper.Conn) bool

Release implements the distributed unlock methed.

type SlowDLock

type SlowDLock struct {
}

SlowDLock implements the distributed lock using zookeeper.

func NewSlowDLock

func NewSlowDLock() *SlowDLock

NewSlowDLock creates a SlowDLock instance.

==> acquire lock retry:

r = create("/zklock/slow-lock", "", empheral)
if r:
    return
else:
    exist("/zklock/slow-lock", watch=True)

watch_event:

goto retry

==> release lock (voluntarily or session timeout) delete("/zklock/slow-lock")

func (*SlowDLock) Acquire

func (dl *SlowDLock) Acquire(conn *zookeeper.Conn, tryTimeout time.Duration) bool

Acquire implements the distributed lock methed.

func (*SlowDLock) Release

func (dl *SlowDLock) Release(conn *zookeeper.Conn) bool

Release implements the distributed unlock methed.

Jump to

Keyboard shortcuts

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