TransactionalBinaryWriter

Struct TransactionalBinaryWriter 

Source
pub struct TransactionalBinaryWriter { /* private fields */ }
Expand description

Transactional binary writer providing ACID guarantees for concurrent chunk operations.

The TransactionalBinaryWriter manages the complex process of writing multiple data chunks to a file while maintaining transactional integrity. It supports high-concurrency scenarios where multiple chunks can be written simultaneously from different threads or async tasks.

§ACID Guarantees

§Atomicity

Either all chunks are successfully written and committed, or no changes are made to the final output file. Partial writes are isolated in temporary files until the complete transaction is ready for commit.

§Consistency

The file system remains in a consistent state throughout the operation. Temporary files are used to prevent corruption of the final output.

§Isolation

Concurrent chunk writes do not interfere with each other. Each chunk is written to its designated position without affecting other chunks.

§Durability

Once committed, the written data survives system crashes and power failures. Data is properly flushed to disk before the transaction is considered complete.

§Core Capabilities

  • Transactional Semantics: All-or-nothing commit behavior
  • Concurrent Writing: Multiple chunks written simultaneously
  • Progress Tracking: Real-time monitoring of write completion
  • Crash Recovery: Checkpoint-based recovery mechanisms
  • Resource Management: Automatic cleanup of temporary resources

§Thread Safety

All operations are thread-safe and can be called concurrently:

  • File access is protected by Arc<Mutex<File>>
  • Progress counters use atomic operations
  • Chunk tracking uses mutex-protected HashSet
  • No data races or undefined behavior in concurrent scenarios

Implementations§

Source§

impl TransactionalBinaryWriter

Source

pub async fn new( output_path: PathBuf, expected_chunk_count: u64, ) -> Result<Self, PipelineError>

Creates a new transactional binary writer.

§Arguments
  • output_path - Final path where the file will be written
  • expected_chunk_count - Total number of chunks expected
§Returns
  • Result<Self, PipelineError> - New writer or error
Source

pub async fn commit(self) -> Result<(), PipelineError>

Commits all written chunks atomically.

This method validates that all expected chunks have been written, flushes data to disk, and atomically moves the temporary file to the final output location.

§Returns
  • Result<(), PipelineError> - Success or error
Source

pub async fn rollback(self) -> Result<(), PipelineError>

Rolls back the transaction and cleans up temporary files.

§Returns
  • Result<(), PipelineError> - Success or error
Source

pub async fn progress(&self) -> (u64, u64, u64)

Returns the current progress of the transaction.

§Returns
  • (completed_chunks, total_expected, bytes_written) - Progress information
Source

pub async fn is_complete(&self) -> bool

Checks if the transaction is complete (all chunks written).

Source

pub fn total_chunks(&self) -> u64

Returns the total number of chunks expected.

Source

pub fn progress_percentage(&self) -> f64

Returns the progress as a percentage.

Source

pub fn is_transaction_active(&self) -> bool

Checks if a transaction is currently active.

Trait Implementations§

Source§

impl BinaryFormatWriter for TransactionalBinaryWriter

Implement BinaryFormatWriter trait for TransactionalBinaryWriter

Source§

fn write_chunk(&mut self, chunk: ChunkFormat) -> Result<(), PipelineError>

Writes a processed chunk (compressed/encrypted data) to the .adapipe file
Source§

fn write_chunk_at_position<'life0, 'async_trait>( &'life0 self, chunk: ChunkFormat, sequence_number: u64, ) -> Pin<Box<dyn Future<Output = Result<(), PipelineError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Writes a processed chunk at a specific position for concurrent processing Read more
Source§

fn finalize<'life0, 'async_trait>( &'life0 self, final_header: FileHeader, ) -> Pin<Box<dyn Future<Output = Result<u64, PipelineError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Finalizes the .adapipe file by writing the footer with complete metadata Read more
Source§

fn bytes_written(&self) -> u64

Gets the current number of bytes written
Source§

fn chunks_written(&self) -> u32

Gets the current number of chunks written
Source§

impl Drop for TransactionalBinaryWriter

Implement Drop to ensure cleanup on panic or early termination

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,