/// Push all in-memory structures to the device. This is not necessary for sync since the
/// journal will take care of it.  This will panic if called on the root parent store, which is
/// in-memory only.  This is supposed to be called when there is either memory or space pressure
/// (flushing the store will persist in-memory data and allow the journal file to be trimmed).
Push all in-memory structures to the device. This is not necessary for sync since the
journal will take care of it.  This will panic if called on the root parent store, which is
in-memory only.  This is supposed to be called when there is either memory or space pressure
(flushing the store will persist in-memory data and allow the journal file to be trimmed).
Push all in - memory structures to the device . This is not necessary for sync since the journal will take care of it . This will panic if called on the root parent store which is in - memory only . This is supposed to be called when there is either memory or space pressure ( flushing the store will persist in - memory data and allow the journal file to be trimmed ) .
pub async fn flush(&self, force: bool) -> Result<(), Error> {
        self.ensure_open().await?;
        // TODO(csuter): This whole process needs to be within a transaction, or otherwise safe in
        // the event of power loss.
        let filesystem = self.filesystem();
        let object_sync = filesystem.begin_object_sync(self.store_object_id);
        if !force && !object_sync.needs_sync() {
            return Ok(());
        }
        let parent_store = self.parent_store.as_ref().unwrap();
        let mut transaction = Transaction::new();
        let object_handle =
            parent_store.clone().create_object(&mut transaction, HandleOptions::default()).await?;
        transaction.add(self.store_object_id(), Mutation::TreeSeal);
        self.filesystem.upgrade().unwrap().commit_transaction(transaction).await;
        let object_id = object_handle.object_id();
        let handle = parent_store
            .clone()
            .open_object(self.store_object_id, HandleOptions::default())
            .await?;
        self.tree.compact(object_handle).await?;
        let mut serialized_info = Vec::new();
        {
            let mut store_info = self.store_info.lock().unwrap();
            store_info.layers = vec![object_id];
            serialize_into(&mut serialized_info, &*store_info)?;
        }
        let mut buf = self.device.allocate_buffer(serialized_info.len());
        buf.as_mut_slice()[..serialized_info.len()].copy_from_slice(&serialized_info[..]);
        let mut transaction = Transaction::new();
        handle.txn_write(&mut transaction, 0u64, buf.as_ref()).await?;
        transaction.add(self.store_object_id(), Mutation::TreeCompact);
        filesystem.commit_transaction(transaction).await;
        object_sync.commit();
        Ok(())
    }
pub async fn flush ( & self , force : bool ) -> Result < ( ) , Error > { self . ensure_open ( ) . await ? ; // TODO(csuter): This whole process needs to be within a transaction, or otherwise safe in // the event of power loss. let filesystem = self . filesystem ( ) ; let object_sync = filesystem . begin_object_sync ( self . store_object_id ) ; if ! force && ! object_sync . needs_sync ( ) { return Ok ( ( ) ) ; } let parent_store = self . parent_store . as_ref ( ) . unwrap ( ) ; let mut transaction = Transaction :: new ( ) ; let object_handle = parent_store . clone ( ) . create_object ( & mut transaction , HandleOptions :: default ( ) ) . await ? ; transaction . add ( self . store_object_id ( ) , Mutation :: TreeSeal ) ; self . filesystem . upgrade ( ) . unwrap ( ) . commit_transaction ( transaction ) . await ; let object_id = object_handle . object_id ( ) ; let handle = parent_store . clone ( ) . open_object ( self . store_object_id , HandleOptions :: default ( ) ) . await ? ; self . tree . compact ( object_handle ) . await ? ; let mut serialized_info = Vec :: new ( ) ; { let mut store_info = self . store_info . lock ( ) . unwrap ( ) ; store_info . layers = vec ! [ object_id ] ; serialize_into ( & mut serialized_info , & * store_info ) ? ; } let mut buf = self . device . allocate_buffer ( serialized_info . len ( ) ) ; buf . as_mut_slice ( ) [ .. serialized_info . len ( ) ] . copy_from_slice ( & serialized_info [ .. ] ) ; let mut transaction = Transaction :: new ( ) ; handle . txn_write ( & mut transaction , 0u64 , buf . as_ref ( ) ) . await ? ; transaction . add ( self . store_object_id ( ) , Mutation :: TreeCompact ) ; filesystem . commit_transaction ( transaction ) . await ; object_sync . commit ( ) ; Ok ( ( ) ) }
Push all in-memory structures to the device.
Push all in - memory structures to the device .
&self
force
bool