/// Extend the file with the given extent.  The only use case for this right now is for files
/// that must exist at certain offsets on the device, such as super-blocks.
Extend the file with the given extent.  The only use case for this right now is for files
that must exist at certain offsets on the device, such as super-blocks.
Extend the file with the given extent . The only use case for this right now is for files that must exist at certain offsets on the device such as super - blocks .
pub async fn extend(&self, transaction: &mut Transaction, device_range: Range<u64>) {
        // TODO(csuter): this needs locking
        let (old_size, new_size) = {
            let mut size = self.size.lock().unwrap();
            let old_size = *size;
            // TODO(csuter): roll back size change if transaction fails, or alternatively, change
            // the size when the transaction commits (whilst keeping the object locked).
            *size += device_range.end - device_range.start;
            (old_size, *size)
        };
        self.store.allocator().reserve(transaction, device_range.clone()).await;
        transaction.add(
            self.store.store_object_id,
            Mutation::ReplaceOrInsert {
                item: ObjectItem {
                    key: ObjectKey::attribute(self.object_id, self.attribute_id),
                    value: ObjectValue::attribute(new_size),
                },
            },
        );
        transaction.add(
            self.store.store_object_id(),
            Mutation::ReplaceExtent {
                item: ObjectItem {
                    key: ObjectKey::extent(self.object_id, self.attribute_id, old_size..new_size),
                    value: ObjectValue::extent(device_range.start),
                },
            },
        );
    }
pub async fn extend ( & self , transaction : & mut Transaction , device_range : Range < u64 > ) { // TODO(csuter): this needs locking let ( old_size , new_size ) = { let mut size = self . size . lock ( ) . unwrap ( ) ; let old_size = * size ; // TODO(csuter): roll back size change if transaction fails, or alternatively, change // the size when the transaction commits (whilst keeping the object locked). * size += device_range . end - device_range . start ; ( old_size , * size ) } ; self . store . allocator ( ) . reserve ( transaction , device_range . clone ( ) ) . await ; transaction . add ( self . store . store_object_id , Mutation :: ReplaceOrInsert { item : ObjectItem { key : ObjectKey :: attribute ( self . object_id , self . attribute_id ) , value : ObjectValue :: attribute ( new_size ) , } , } , ) ; transaction . add ( self . store . store_object_id ( ) , Mutation :: ReplaceExtent { item : ObjectItem { key : ObjectKey :: extent ( self . object_id , self . attribute_id , old_size .. new_size ) , value : ObjectValue :: extent ( device_range . start ) , } , } , ) ; }
Extend the file with the given extent.
Extend the file with the given extent .
&self
transaction
&mut Transaction
device_range
Range<u64>