Trait opendal::raw::oio::BlockWrite

source ·
pub trait BlockWrite: Send + Sync + Unpin + 'static {
    // Required methods
    fn write_once(
        &self,
        size: u64,
        body: Buffer,
    ) -> impl Future<Output = Result<()>> + MaybeSend;
    fn write_block(
        &self,
        block_id: Uuid,
        size: u64,
        body: Buffer,
    ) -> impl Future<Output = Result<()>> + MaybeSend;
    fn complete_block(
        &self,
        block_ids: Vec<Uuid>,
    ) -> impl Future<Output = Result<()>> + MaybeSend;
    fn abort_block(
        &self,
        block_ids: Vec<Uuid>,
    ) -> impl Future<Output = Result<()>> + MaybeSend;
}
Expand description

BlockWrite is used to implement oio::Write based on block uploads. By implementing BlockWrite, services don’t need to care about the details of uploading blocks.

§Architecture

The architecture after adopting BlockWrite:

  • Services impl BlockWrite
  • BlockWriter impl Write
  • Expose BlockWriter as Accessor::Writer

§Notes

BlockWrite has an oneshot optimization when write has been called only once:

w.write(bs).await?;
w.close().await?;

We will use write_once instead of starting a new block upload.

§Requirements

Services that implement BlockWrite must fulfill the following requirements:

  • Must be a http service that could accept AsyncBody.
  • Don’t need initialization before writing.
  • Block ID is generated by caller BlockWrite instead of services.
  • Complete block by an ordered block id list.

Required Methods§

source

fn write_once( &self, size: u64, body: Buffer, ) -> impl Future<Output = Result<()>> + MaybeSend

write_once is used to write the data to underlying storage at once.

BlockWriter will call this API when:

  • All the data has been written to the buffer and we can perform the upload at once.
source

fn write_block( &self, block_id: Uuid, size: u64, body: Buffer, ) -> impl Future<Output = Result<()>> + MaybeSend

write_block will write a block of the data.

BlockWriter will call this API and stores the result in order.

  • block_id is the id of the block.
source

fn complete_block( &self, block_ids: Vec<Uuid>, ) -> impl Future<Output = Result<()>> + MaybeSend

complete_block will complete the block upload to build the final file.

source

fn abort_block( &self, block_ids: Vec<Uuid>, ) -> impl Future<Output = Result<()>> + MaybeSend

abort_block will cancel the block upload and purge all data.

Object Safety§

This trait is not object safe.

Implementors§