Skip to main content

AtomicRemoteBackend

Trait AtomicRemoteBackend 

Source
pub trait AtomicRemoteBackend: RemoteBackend {
    // Required methods
    fn object_version(
        &self,
        remote_key: &str,
    ) -> Result<Option<BackendObjectVersion>, BackendError>;
    fn upload_conditional(
        &self,
        local_path: &Path,
        remote_key: &str,
        condition: ConditionalPut,
    ) -> Result<BackendObjectVersion, BackendError>;
    fn delete_conditional(
        &self,
        remote_key: &str,
        condition: ConditionalDelete,
    ) -> Result<(), BackendError>;
}
Expand description

Backends that can enforce compare-and-swap atomically.

Where RemoteBackend is “snapshot transport,” AtomicRemoteBackend is the contract callers need when they cannot tolerate lost updates (writer leases, distributed locks, ledger appenders). Implementing this trait is a promise the backend never silently overwrites a versioned object — preconditions translate to backend-native guarantees (S3 ETag + If-Match, FS lock + content-hash CAS, HTTP servers that honor RFC 7232 preconditions).

Backends that cannot meet that promise (Turso, D1, HTTP servers without ETag) deliberately do not implement this trait, so a caller that needs CAS will fail at compile time rather than at the first contended write.

Required Methods§

Source

fn object_version( &self, remote_key: &str, ) -> Result<Option<BackendObjectVersion>, BackendError>

Return the current opaque version token for an object. Ok(None) means the object does not exist.

Source

fn upload_conditional( &self, local_path: &Path, remote_key: &str, condition: ConditionalPut, ) -> Result<BackendObjectVersion, BackendError>

Upload a local file only if the backend-side condition still holds. Returns the new version token on success; BackendError::PreconditionFailed on contention.

Source

fn delete_conditional( &self, remote_key: &str, condition: ConditionalDelete, ) -> Result<(), BackendError>

Delete a remote object only if the backend-side condition still holds. BackendError::PreconditionFailed on contention.

Implementors§