65 lines
2.5 KiB
Markdown
65 lines
2.5 KiB
Markdown
---
|
|
id: mem-engine-locks
|
|
name: Mem engine — named locks (in-memory TTL registry)
|
|
status: pending
|
|
depends_on: [mem-engine-seam-tx]
|
|
scope: narrow
|
|
risk: low
|
|
impact: component
|
|
level: implementation
|
|
tags: [wave-6, mem-engine, locks]
|
|
---
|
|
|
|
## Description
|
|
|
|
The named-locks mechanism over an in-memory TTL registry
|
|
(engine-mem.md §Mapping the contract, locks row):
|
|
|
|
- `store.try_lock(name, owner, ttl)` — acquire or fail (`Option<Lock>
|
|
`; no-work is a value); validation at entry (empty → `InvalidName`,
|
|
reserved → `ReservedName`); **duration guard at entry** —
|
|
`ttl <= 0` rejects with opaque `Err`
|
|
([ADR-023](../architecture/decisions/023-fourth-review-round.md) §2,
|
|
durations kind), never a silent immediately-expired lease.
|
|
- **`Lock` handle** ([ADR-019](../architecture/decisions/019-mechanism-handle-surfaces.md)):
|
|
`renew(ttl)` (absolute reset; renews past expiry refused) and
|
|
`release`. Registry entries carry owner + deadline; expiry is a
|
|
clock check at try/renew boundaries (tokio time; no ambient
|
|
revoker) — after TTL expiry exclusion lapses *silently* (the
|
|
ADR-008 §7 row), re-acquirable; the holder may still release.
|
|
- **Single-instance contention semantics**: two `try_lock`s on the
|
|
same name within the registry are serialized by the guarded-state
|
|
discipline — first wins, second gets `None` cleanly (the SQLite
|
|
busy-path question has no mem analog; loser is a value, never an
|
|
error). Not part of the tx seam (no `lock_tx` — contract-verbatim:
|
|
a lock held across a business tx is held by explicit acquisition;
|
|
the overlay neither sees nor stages locks).
|
|
|
|
## Acceptance Criteria
|
|
|
|
- [ ] `try_lock`/`renew`/`release` over the TTL registry; entry
|
|
validation (names + duration guard) — pinned
|
|
- [ ] TTL expiry: silent lapse, re-acquisition, renew-past-expiry
|
|
refused — pinned (clock-controlled tests via the state core's
|
|
clock accessor)
|
|
- [ ] Concurrent-contention shape: loser is `None`, winner's lease
|
|
intact — pinned
|
|
- [ ] `cargo check --target wasm32-unknown-unknown -p alkstore-mem`
|
|
clean; workspace gates green
|
|
|
|
## References
|
|
|
|
- docs/architecture/core-contract.md §named locks
|
|
- docs/architecture/decisions/008-contract-v1-pinning.md §7;
|
|
019-mechanism-handle-surfaces.md; 023 §2
|
|
- docs/architecture/engine-mem.md §Mapping the contract (locks row)
|
|
- tasks/pg-engine-locks.md (the structural twin's task of record —
|
|
the duration guards land identically)
|
|
|
|
## Notes
|
|
|
|
> To be filled by implementation agent
|
|
|
|
## Summary
|
|
|
|
> To be filled on completion |