pub struct DedupCache { /* private fields */ }Expand description
Haematite-backed idempotency-key cache for the lightweight dedup contract.
Implementations§
Source§impl DedupCache
impl DedupCache
Sourcepub fn new(store: Arc<dyn DurableStore>, namespace: impl Into<String>) -> Self
pub fn new(store: Arc<dyn DurableStore>, namespace: impl Into<String>) -> Self
Creates a dedup cache over the given durable store and namespace prefix.
Sourcepub fn stream_key_for(&self, idempotency_key: &str) -> String
pub fn stream_key_for(&self, idempotency_key: &str) -> String
Formats the haematite stream key for an idempotency key.
Sourcepub async fn lookup(
&self,
idempotency_key: &str,
) -> Result<Option<DedupDecision>, DurabilityError>
pub async fn lookup( &self, idempotency_key: &str, ) -> Result<Option<DedupDecision>, DurabilityError>
Looks up an existing key without appending or refreshing cache state.
§Errors
Propagates store read errors and returns DurabilityError::DedupCollision when
the hashed stream contains a different original idempotency key.
Sourcepub async fn claim_or_get(
&self,
idempotency_key: &str,
timestamp_millis: u64,
) -> Result<DedupDecision, DurabilityError>
pub async fn claim_or_get( &self, idempotency_key: &str, timestamp_millis: u64, ) -> Result<DedupDecision, DurabilityError>
Claims a new key or returns the existing completed/in-flight decision.
Callers must only deliver the message when this returns DedupDecision::Claimed.
§Errors
Propagates store errors and serialization errors. A concurrent first claim that wins the append race is converted into the duplicate completed/in-flight decision.
Sourcepub async fn complete_receipt(
&self,
idempotency_key: &str,
receipt: ProcessingReceipt,
) -> Result<(), DurabilityError>
pub async fn complete_receipt( &self, idempotency_key: &str, receipt: ProcessingReceipt, ) -> Result<(), DurabilityError>
Stores a processing receipt by appending a completed entry for an existing key.
§Errors
Returns DurabilityError::ConfigError when the current system time cannot be encoded.
Returns DurabilityError::DedupCollision when the key is missing or collides with
another original key, and propagates serialization/store append errors.
Sourcepub async fn release_claim(
&self,
idempotency_key: &str,
) -> Result<(), DurabilityError>
pub async fn release_claim( &self, idempotency_key: &str, ) -> Result<(), DurabilityError>
Releases an in-flight claim so the key becomes re-claimable.
Callers use this on the publish failure path: a key was claimed
(DedupDecision::Claimed) but the downstream delivery failed before a
receipt could be recorded, leaving the key dangling DedupDecision::InFlight
forever and permanently suppressing every re-publish. Releasing appends a
tombstone so the next claim succeeds.
This NEVER clobbers a stored receipt: an already-completed key (receipt present) and an absent key are both no-ops, preserving the at-most-once guarantee. Only a current in-flight entry (active, no receipt) is tombstoned.
§Errors
Propagates store read/append and serialization errors. A DurabilityError::SequenceConflict
on the tombstone append is re-checked: if the latest state is now completed
or already a tombstone the release is treated as successful, otherwise the
conflict is propagated.
Trait Implementations§
Source§impl Clone for DedupCache
impl Clone for DedupCache
Source§fn clone(&self) -> DedupCache
fn clone(&self) -> DedupCache
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more