Skip to main content

xet_data/file_reconstruction/data_writer/
data_writer.rs

1use std::future::Future;
2use std::pin::Pin;
3
4use bytes::Bytes;
5use xet_client::cas_types::FileRange;
6use xet_runtime::utils::adjustable_semaphore::AdjustableSemaphorePermit;
7
8use super::super::Result;
9
10/// A future that produces the data bytes to be written.
11pub type DataFuture = Pin<Box<dyn Future<Output = Result<Bytes>> + Send + 'static>>;
12
13#[async_trait::async_trait]
14pub trait DataWriter: Send + 'static {
15    /// Sets the data source for the next sequential term.
16    ///
17    /// The byte range must be sequential - its start must match the end of the
18    /// previous range (or 0 for the first call). The data future will be spawned
19    /// as a task and its result will be written when ready.
20    ///
21    /// SequentialWriter will ensure that the actual writes happen in order.
22    ///
23    /// An optional semaphore permit can be passed for rate limiting. The permit
24    /// will be released by the background writer after the data has been written.
25    async fn set_next_term_data_source(
26        &mut self,
27        byte_range: FileRange,
28        permit: Option<AdjustableSemaphorePermit>,
29        data_future: DataFuture,
30    ) -> Result<()>;
31
32    /// Consumes the writer, waits until all data has been written, and returns the
33    /// number of bytes written. Dropping the writer without calling `finish` cancels
34    /// the reconstruction via the shared run state.
35    async fn finish(mut self: Box<Self>) -> Result<u64>;
36}