/// Flushes any outstanding complete blocks to the journal object.  Part blocks can be flushed
/// by calling pad_to_block first.  Does nothing if no handle has been set yet.
Flushes any outstanding complete blocks to the journal object.  Part blocks can be flushed
by calling pad_to_block first.  Does nothing if no handle has been set yet.
Flushes any outstanding complete blocks to the journal object . Part blocks can be flushed by calling pad_to_block first . Does nothing if no handle has been set yet .
pub async fn maybe_flush_buffer(&mut self) -> Result<(), Error>
    where
        OH: ObjectHandle,
    {
        if let Some(ref handle) = self.handle {
            let to_do = self.buf.len() - self.buf.len() % self.block_size;
            if to_do > 0 {
                // TODO(jfsulliv): This is horribly inefficient. We should reuse the transfer
                // buffer. Doing so will require picking an appropriate size up front, and forcing
                // flush as we fill it up.
                let mut buf = handle.allocate_buffer(to_do);
                buf.as_mut_slice()[..to_do].copy_from_slice(self.buf.drain(..to_do).as_slice());
                buf.as_mut_slice()[to_do..].fill(0u8);
                let mut txn = handle.new_transaction().await?;
                handle.txn_write(&mut txn, self.checkpoint.file_offset, buf.as_ref()).await?;
                // Any mutations would rely on the journal to be applied, so the transaction must be
                // empty. Writes are done in overwrite mode and the journal file is pre-allocated,
                // so they should not cause any mutations to be added to the transaction.
                assert!(txn.is_empty());
                txn.commit().await;
                self.checkpoint.file_offset += to_do as u64;
                self.checkpoint.checksum = self.last_checksum;
            }
        }
        Ok(())
    }
pub async fn maybe_flush_buffer ( & mut self ) -> Result < ( ) , Error > where OH : ObjectHandle , { if let Some ( ref handle ) = self . handle { let to_do = self . buf . len ( ) - self . buf . len ( ) % self . block_size ; if to_do > 0 { // TODO(jfsulliv): This is horribly inefficient. We should reuse the transfer // buffer. Doing so will require picking an appropriate size up front, and forcing // flush as we fill it up. let mut buf = handle . allocate_buffer ( to_do ) ; buf . as_mut_slice ( ) [ .. to_do ] . copy_from_slice ( self . buf . drain ( .. to_do ) . as_slice ( ) ) ; buf . as_mut_slice ( ) [ to_do .. ] . fill ( 0u8 ) ; let mut txn = handle . new_transaction ( ) . await ? ; handle . txn_write ( & mut txn , self . checkpoint . file_offset , buf . as_ref ( ) ) . await ? ; // Any mutations would rely on the journal to be applied, so the transaction must be // empty. Writes are done in overwrite mode and the journal file is pre-allocated, // so they should not cause any mutations to be added to the transaction. assert ! ( txn is_empty ( ) ) ; txn . commit ( ) . await ; self . checkpoint . file_offset += to_do as u64 ; self . checkpoint . checksum = self . last_checksum ; } } Ok ( ( ) ) }
Flushes any outstanding complete blocks to the journal object.
Flushes any outstanding complete blocks to the journal object .
&mut self