Struct zookeeper_client::LockPrefix
source · pub struct LockPrefix<'a> { /* private fields */ }
Expand description
Prefix pattern for lock path creation.
This struct carries path prefix for ephemeral lock path, name filter for candidate contenders and hint to find created lock path in case of Error::ConnectionLoss.
Implementations§
source§impl<'a> LockPrefix<'a>
impl<'a> LockPrefix<'a>
sourcepub fn new_curator(dir: &'a str, name: &'a str) -> Result<Self, Error>
pub fn new_curator(dir: &'a str, name: &'a str) -> Result<Self, Error>
Apache Curator compatible unique prefix pattern, the final lock path will be
{dir}/_c_{uuid}-{name}{ephemeral_sequence}
.
Notable lock names
latch-
forLeaderLatch
.lock-
forLeaderSelector
andInterProcessMutex
.
Shared path prefix, the final lock path will be {prefix}{ephemeral_sequence}
.
CAUTION
All contenders share same prefix, so concurrent contenders must not share same session client. Otherwise, the lock could be ruined in case of Error::ConnectionLoss as there is no way to differentiate contenders using same session.
Notable usages
- Uses “{dir}/n-” as
prefix
for ZooKeeper java client’s LeaderElectionSupport.
sourcepub fn new_custom(prefix: String, name: &'a str) -> Result<Self, Error>
pub fn new_custom(prefix: String, name: &'a str) -> Result<Self, Error>
Custom path prefix, the final lock path will be {prefix}{ephemeral_sequence}
.
CAUTION
Don’t reuse same prefix among clients with same session. See LockPrefix::new_shared for details.
API
It is intentional for prefix
parameter to be String
but not impl Into<String>
nor
impl Into<Cow<'a, str>>
, so to attract attention for best wish.
Notable usages
- Uses “{dir}/x-{session_id}-” as
prefix
and “x-” or “” asname
for ZooKeeper java client’s WriteLock.