The DistributedLock.ZooKeeper package offers distributed locks based on Apache ZooKeeper. For example:
var @lock = new ZooKeeperDistributedLock("MyLockName", connectionString);
await using (await @lock.AcquireAsync())
{
// I have the lock
}
- The
ZooKeeperDistributedLock
class implements theIDistributedLock
interface. - The
ZooKeeperDistributedReaderWriterLock
class implements theIDistributedReaderWriterLock
interface. - The
ZooKeeperDistributedSemaphore
class implements theIDistributedSemaphore
interface. - The
ZooKeeperDistributedSynchronizationProvider
class implements theIDistributedLockProvider
,IDistributedReaderWriterLockProvider
, andIDistributedSemaphoreProvider
interfaces.
ZooKeeper-based locks leverage ZooKeeper's recommended recipes for distributed synchronization.
By leveraging ZooKeeper watches under the hood, these recipes allow for very efficient event-driven waits when acquiring.
SessionTimeout
configures the underlying session timeout value for ZooKeeper connections. Because the underlying ZooKeeper client periodically renews the session, this value generally will not impact behavior. Lower values mean that locks will be released more quickly following a crash of the lock-holding process, but also increase the risk that transient connection issues will result in a dropped lock. Defaults to 20s.ConnectTimeout
configures how long to wait when establishing a connection to ZooKeeper. Defaults to 15s.AddAuthInfo
allows you to specify additional auth information to be added to the ZooKeeper session. This option can be specified multiple times to add multiple auth schemes.AddAccessControl
configures the ZooKeeper ACL for nodes created by the lock. This option can be specified multiple times to add multiple ACL entries. If left unspecified, the ACL used is (world, anyone).