Expand description
Atomic Claim Protocol for Queue Operations
This module provides linearizable “claim + delete” pop semantics for queue operations, ensuring no double-delivery under concurrent access.
§Problem: Double-Delivery Under Concurrency
Without atomic claims, a naive “scan → delete” pattern can fail:
Worker A: scan() → finds task T
Worker B: scan() → finds task T (same task!)
Worker A: delete(T) → success
Worker B: delete(T) → fails or double-processes§Solution: CAS-Based Claim Protocol
The claim is the linearization point. Only one worker can successfully create the claim key, establishing ownership:
Worker A: scan() → finds task T
Worker A: CAS(claim/T, absent → A) → SUCCESS
Worker B: scan() → finds task T
Worker B: CAS(claim/T, absent → B) → FAIL (key exists)
Worker B: retry with next candidate§Lease-Based Crash Recovery
Claims have expiry times. If a worker crashes:
- Claim expires after
lease_duration - Next worker’s scan finds task with expired claim
- New claim can overwrite expired claim
- Task is reprocessed (at-least-once delivery)
§Integration with SochDB’s MVCC/SSI
The claim protocol works with SochDB’s transaction model:
- Claims use MVCC versioning for conflict detection
- The claim key insert is the durability boundary
- SSI’s dangerous-structure detection catches anomalies
- WAL + fsync ensures claim survives crashes
Structs§
- Atomic
Claim Manager - Atomic claim manager for queue task ownership
- Claim
Stats - Statistics for claim operations
- Claim
Token - A token proving ownership of a claimed task
- Lease
Config - Configuration for lease management
- Lease
Manager - Higher-level lease manager with periodic cleanup
Enums§
- Claim
Result - Result of attempting to claim a task
Traits§
- Compare
AndSwap - Compare-and-swap trait for storage backends