Module: ZK::Locker
- Defined in:
- lib/zk/locker.rb
Overview
These lock instances are not safe for use across threads. If you want to use the same Locker instance between threads, it is your responsibility to synchronize operations.
Lockers are instances that hold the lock. A single connection may have many instances trying to lock the same path and only one (in the case of an ExclusiveLocker) will hold the lock.
The most convenient way to create instances of locks is by using the methods
This module contains implementations of the locking primitives described here, that allow a user to implement cluster-wide global locks (with both blocking and non-blocking semantics).
There are both shared and exclusive lock implementations.
The implementation is fairly true to the description in the recipes, and
the key is generated using a combination of the name provided, and a
root_lock_node path whose default value is /_zklocking. If you look
below at the 'Key path creation' example, you'll see that we do a very
simple escaping of the name given. There was a distinct tradeoff to be made
between making the locks easy to debug in zookeeper and making them more
collision tolerant. If the key naming causees issues, please file a bug and
we'll try to work out a solution (hearing about use cases is incredibly halpful
in guiding development).
If you're interested in how the algorithm works, have a look at ExclusiveLocker's documentation.
Defined Under Namespace
Classes: ExclusiveLocker, LockerBase, SharedLocker
Constant Summary
- SHARED_LOCK_PREFIX =
'sh'.freeze
- EXCLUSIVE_LOCK_PREFIX =
'ex'.freeze
Class Method Summary (collapse)
-
+ (ExclusiveLocker) exclusive_locker(client, name, *args)
Create an ExclusiveLocker instance.
-
+ (SharedLocker) shared_locker(client, name, *args)
Create a SharedLocker instance.
Class Method Details
+ (ExclusiveLocker) exclusive_locker(client, name, *args)
Create an ExclusiveLocker instance
56 57 58 |
# File 'lib/zk/locker.rb', line 56 def self.exclusive_locker(client, name, *args) ExclusiveLocker.new(client, name, *args) end |
+ (SharedLocker) shared_locker(client, name, *args)
Create a SharedLocker instance
47 48 49 |
# File 'lib/zk/locker.rb', line 47 def self.shared_locker(client, name, *args) SharedLocker.new(client, name, *args) end |