Skip to main content

ObjectLockManager

Trait ObjectLockManager 

Source
pub trait ObjectLockManager: Send + Sync {
    // Required methods
    fn has_meta(&self, hash: SequenceHash) -> BoxFuture<'static, Result<bool>>;
    fn try_acquire_lock(
        &self,
        hash: SequenceHash,
    ) -> BoxFuture<'static, Result<bool>>;
    fn create_meta(&self, hash: SequenceHash) -> BoxFuture<'static, Result<()>>;
    fn release_lock(&self, hash: SequenceHash) -> BoxFuture<'static, Result<()>>;
}
Expand description

Object lock manager trait for distributed locking in object storage.

This trait provides the locking semantics for the object offload pipeline:

  1. Check .meta file to see if block is already offloaded
  2. Try to acquire .lock file with conditional PUT
  3. Create .meta file after successful offload
  4. Release .lock file after completion

§Locking Flow

has_meta() -> false -> try_acquire_lock() -> true -> execute transfer -> create_meta() -> release_lock()
                                          -> false -> skip (another instance owns it)
           -> true -> skip (already offloaded)

Required Methods§

Source

fn has_meta(&self, hash: SequenceHash) -> BoxFuture<'static, Result<bool>>

Check if meta file exists (block already offloaded).

Returns true if {hash}.meta exists, meaning the block has been successfully offloaded and should be skipped.

Source

fn try_acquire_lock( &self, hash: SequenceHash, ) -> BoxFuture<'static, Result<bool>>

Try to acquire a lock for the given block.

This method:

  1. Attempts conditional PUT of {hash}.lock with If-None-Match: *
  2. If lock exists, reads it to check deadline
  3. If deadline is breached (> timeout), overwrites the lock

Returns:

  • Ok(true) if lock was acquired or overwritten
  • Ok(false) if another instance owns a valid lock
  • Err(...) for other errors
Source

fn create_meta(&self, hash: SequenceHash) -> BoxFuture<'static, Result<()>>

Create the meta file after successful offload.

This marks the block as successfully offloaded by creating {hash}.meta.

Source

fn release_lock(&self, hash: SequenceHash) -> BoxFuture<'static, Result<()>>

Release the lock by deleting the lock file.

Deletes {hash}.lock after the transfer is complete.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§