// Before we commit, we might need to extend the journal or write pending records to the
// journal.
Before we commit, we might need to extend the journal or write pending records to the
journal.
Before we commit we might need to extend the journal or write pending records to the journal .
async fn pre_commit(&self) -> Result<(), Error> {
        // TODO(csuter): this currently assumes that a transaction can fit in CHUNK_SIZE.
        let handle;
        let (size, zero_offset) = {
            let mut inner = self.inner.lock().unwrap();
            if let Some(discard_offset) = inner.discard_offset {
                serialize_into(&mut inner.writer, &JournalRecord::Discard(discard_offset))?;
                inner.discard_offset = None;
            }
            if inner.needs_did_flush_device {
                let offset = inner.device_flushed_offset;
                serialize_into(&mut inner.writer, &JournalRecord::DidFlushDevice(offset))?;
                inner.needs_did_flush_device = false;
            }
            handle = match self.handle.get() {
                None => return Ok(()),
                Some(x) => x,
            };
            let file_offset = inner.writer.journal_file_checkpoint().file_offset;
            let size = handle.get_size();
            let size = if file_offset + self.chunk_size() > size { Some(size) } else { None };
            if size.is_none() && inner.zero_offset.is_none() {
                return Ok(());
            }
            (size, inner.zero_offset)
        };
        let mut transaction = handle
            .new_transaction_with_options(Options {
                skip_journal_checks: true,
                borrow_metadata_space: true,
                allocator_reservation: Some(self.objects.metadata_reservation()),
                ..Default::default()
            })
            .await?;
        if let Some(size) = size {
            handle.preallocate_range(&mut transaction, size..size + self.chunk_size()).await?;
        }
        if let Some(zero_offset) = zero_offset {
            handle.zero(&mut transaction, 0..zero_offset).await?;
        }
        // We can't use regular transaction commit, because that can cause re-entrancy issues, so
        // instead we just apply the transaction directly here.
        self.write_and_apply_mutations(&mut transaction).await;
        let mut inner = self.inner.lock().unwrap();
        // Make sure the transaction to extend the journal made it to the journal within the old
        // size, since otherwise, it won't be possible to replay.
        if let Some(size) = size {
            assert!(inner.writer.journal_file_checkpoint().file_offset < size);
        }
        if inner.zero_offset == zero_offset {
            inner.zero_offset = None;
        }
        Ok(())
    }
async fn pre_commit ( & self ) -> Result < ( ) , Error > { // TODO(csuter): this currently assumes that a transaction can fit in CHUNK_SIZE. let handle ; let ( size , zero_offset ) = { let mut inner = self . inner . lock ( ) . unwrap ( ) ; if let Some ( discard_offset ) = inner . discard_offset { serialize_into ( & mut inner . writer , & JournalRecord :: Discard ( discard_offset ) ) ? ; inner . discard_offset = None ; } if inner . needs_did_flush_device { let offset = inner . device_flushed_offset ; serialize_into ( & mut inner . writer , & JournalRecord :: DidFlushDevice ( offset ) ) ? ; inner . needs_did_flush_device = false ; } handle = match self . handle . get ( ) { None => return Ok ( ( ) ) , Some ( x ) => x , } ; let file_offset = inner . writer . journal_file_checkpoint ( ) . file_offset ; let size = handle . get_size ( ) ; let size = if file_offset + self . chunk_size ( ) > size { Some ( size ) } else { None } ; if size . is_none ( ) && inner . zero_offset . is_none ( ) { return Ok ( ( ) ) ; } ( size , inner . zero_offset ) } ; let mut transaction = handle . new_transaction_with_options ( Options { skip_journal_checks : true , borrow_metadata_space : true , allocator_reservation : Some ( self . objects . metadata_reservation ( ) ) , .. Default :: default ( ) } ) . await ? ; if let Some ( size ) = size { handle . preallocate_range ( & mut transaction , size .. size + self . chunk_size ( ) ) . await ? ; } if let Some ( zero_offset ) = zero_offset { handle . zero ( & mut transaction , 0 .. zero_offset ) . await ? ; } // We can't use regular transaction commit, because that can cause re-entrancy issues, so // instead we just apply the transaction directly here. self . write_and_apply_mutations ( & mut transaction ) . await ; let mut inner = self . inner . lock ( ) . unwrap ( ) ; // Make sure the transaction to extend the journal made it to the journal within the old // size, since otherwise, it won't be possible to replay. if let Some ( size ) = size { assert ! ( inner writer journal_file_checkpoint ( ) file_offset size ) ; } if inner . zero_offset == zero_offset { inner . zero_offset = None ; } Ok ( ( ) ) }
Before we commit, we might need to extend the journal or write pending records to the
journal.
Before we commit we might need to extend the journal or write pending records to the journal .
&self