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
impl TransactionalBinaryWriter
Sourcepub async fn new(
output_path: PathBuf,
expected_chunk_count: u64,
) -> Result<Self, PipelineError>
pub async fn new( output_path: PathBuf, expected_chunk_count: u64, ) -> Result<Self, PipelineError>
Sourcepub async fn commit(self) -> Result<(), PipelineError>
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
Sourcepub async fn rollback(self) -> Result<(), PipelineError>
pub async fn rollback(self) -> Result<(), PipelineError>
Rolls back the transaction and cleans up temporary files.
§Returns
Result<(), PipelineError>- Success or error
Sourcepub async fn progress(&self) -> (u64, u64, u64)
pub async fn progress(&self) -> (u64, u64, u64)
Returns the current progress of the transaction.
§Returns
(completed_chunks, total_expected, bytes_written)- Progress information
Sourcepub async fn is_complete(&self) -> bool
pub async fn is_complete(&self) -> bool
Checks if the transaction is complete (all chunks written).
Sourcepub fn total_chunks(&self) -> u64
pub fn total_chunks(&self) -> u64
Returns the total number of chunks expected.
Sourcepub fn progress_percentage(&self) -> f64
pub fn progress_percentage(&self) -> f64
Returns the progress as a percentage.
Sourcepub fn is_transaction_active(&self) -> bool
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
impl BinaryFormatWriter for TransactionalBinaryWriter
Implement BinaryFormatWriter trait for TransactionalBinaryWriter
Source§fn write_chunk(&mut self, chunk: ChunkFormat) -> Result<(), PipelineError>
fn write_chunk(&mut self, chunk: ChunkFormat) -> Result<(), PipelineError>
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,
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,
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,
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,
Source§fn bytes_written(&self) -> u64
fn bytes_written(&self) -> u64
Source§fn chunks_written(&self) -> u32
fn chunks_written(&self) -> u32
Auto Trait Implementations§
impl Freeze for TransactionalBinaryWriter
impl !RefUnwindSafe for TransactionalBinaryWriter
impl Send for TransactionalBinaryWriter
impl Sync for TransactionalBinaryWriter
impl Unpin for TransactionalBinaryWriter
impl !UnwindSafe for TransactionalBinaryWriter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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