Verified lease/lock client for DynamoDB and DSQL, in Rust
// momentum
// why it's here
- Created 8 days ago and already shipping
- Built almost entirely by one person
- Health 84/100 with only 26 stars
// how to help
// readme
distributed-lock-client
A lease-based distributed lock client in Rust for Amazon DynamoDB and Aurora DSQL, in the style of amazon-dynamodb-lock-client, built around a formal verification story.
let store = Arc::new(DynamoStore::from_env("locks").await);
let client = LockClient::new(store.clone(), Config::default())?;
if let Some(lease) = client.acquire("job-42", Duration::from_secs(30)).await? {
// Clock-free exclusion for data in the same store: a fenced write.
// `guard()` is `None` once the session has ended.
if let Some(guard) = lease.guard() {
match store.fenced(&guard, writes).await {
FencedOutcome::Applied => { /* done */ }
FencedOutcome::Rejected => { /* lost the lock: stop */ }
_ => { /* Retry, Unknown, Fatal: see "Relying on the lock" */ }
}
}
// Timing-based exclusion: check before acting, act within max_pause.
if lease.is_valid() { /* ... */ }
lease.release().await?;
}