pub trait BlockWrite:
Send
+ Sync
+ Unpin
+ 'static {
// Required methods
fn write_once(
&self,
size: u64,
body: Buffer,
) -> impl Future<Output = Result<Metadata>> + 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<Metadata>> + 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 BlockWriterimplWrite- Expose
BlockWriterasAccessor::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
BlockWriteinstead of services. - Complete block by an ordered block id list.
Required Methods§
Sourcefn write_once(
&self,
size: u64,
body: Buffer,
) -> impl Future<Output = Result<Metadata>> + MaybeSend
fn write_once( &self, size: u64, body: Buffer, ) -> impl Future<Output = Result<Metadata>> + 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.
Sourcefn write_block(
&self,
block_id: Uuid,
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
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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".