Skip to content

Latest commit

 

History

History
34 lines (23 loc) · 2.22 KB

DistributedLock.ZooKeeper.md

File metadata and controls

34 lines (23 loc) · 2.22 KB

DistributedLock.ZooKeeper

Download the NuGet package NuGet Status

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
}

APIs

  • The ZooKeeperDistributedLock class implements the IDistributedLock interface.
  • The ZooKeeperDistributedReaderWriterLock class implements the IDistributedReaderWriterLock interface.
  • The ZooKeeperDistributedSemaphore class implements the IDistributedSemaphore interface.
  • The ZooKeeperDistributedSynchronizationProvider class implements the IDistributedLockProvider, IDistributedReaderWriterLockProvider, and IDistributedSemaphoreProvider interfaces.

Implementation notes

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.

Options

  • 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).