Expand description
§ash-lock — distributed coordination for the ash-* ecosystem
Status: the default build is single-process (InMemoryBackend). Real
distributed locking is provided by the etcd feature (EtcdBackend:
etcd leases + transactions, with cluster-wide monotonic revision-based
fencing tokens). Some collaborators named in the original spec are still
stubbed:
| Spec dependency | Status in this crate |
|---|---|
| lock backend | InMemoryBackend (default) or EtcdBackend (etcd feature) |
ash-telemetry | replaced by the in-crate telemetry counter module |
ash-discovery | seeds are recorded but unused; LockClient::connect runs in-process |
ash-time (HLC) | adopted behind the ash-time feature: stamps every acquire — see clock |
ash-flare | supervision contract honoured by the internal watchdog; no ash-flare dependency yet |
ash-rpc | remote backend transport not implemented |
§Fencing tokens — READ THIS
A distributed lock cannot prevent a stalled lock holder (GC pause, paused
VM) from waking up and writing after its lease has already expired and been
re-granted. The only robust defence is a fencing token: a strictly
monotonic number handed out on every acquire, which you attach to every write
to the protected resource. The resource rejects any write whose token is
lower than the highest it has seen. Use validate_write at the resource.
use ash_lock::{LockClient, LockConfig, validate_write};
use std::time::Duration;
let client = LockClient::connect(LockConfig {
default_ttl: Duration::from_secs(30),
watchdog_interval: Duration::from_secs(10),
..Default::default()
}).await?;
let guard = client.lock("orders/42").await.with_ttl(Duration::from_secs(20)).acquire().await?;
let token = guard.fencing_token()?; // attach `token` to every write
assert!(validate_write(token, token)); // resource-side check
// ... do work ...
guard.unlock().await?; // or just drop `guard`Re-exports§
pub use backend::InMemoryBackend;pub use backend::LockBackend;pub use clock::Stamp;
Modules§
- backend
- The
LockBackendabstraction and its implementations. - clock
- Causality clock used to stamp lock operations.
- telemetry
- Metrics for
ash-lock.
Structs§
- Lock
Builder - Fluent configuration for a single acquire attempt.
- Lock
Client - A handle to the distributed lock service.
- Lock
Config - Configuration for connecting a
LockClientto a lock cluster. - Lock
Guard - A held distributed lock.
Enums§
- Error
- Errors that can occur while acquiring, renewing, or releasing a lock.
Functions§
- validate_
write - Validate that a write carrying
tokenis still allowed against a resource whose last-seen fencing token iscurrent_token.
Type Aliases§
- Result
- The result type used throughout the public API.