// Ensures the allocator is open.  If empty, create the object in the root object store,
// otherwise load and initialise the LSM tree.
Ensures the allocator is open.  If empty, create the object in the root object store,
otherwise load and initialise the LSM tree.
Ensures the allocator is open . If empty create the object in the root object store otherwise load and initialise the LSM tree .
pub async fn ensure_open(&self) -> Result<(), Error> {
        {
            if self.inner.lock().unwrap().opened {
                return Ok(());
            }
        }
        let _guard = self.allocation_lock.lock().await;
        {
            if self.inner.lock().unwrap().opened {
                // We lost a race.
                return Ok(());
            }
        }
        let filesystem = self.filesystem.upgrade().unwrap();
        let root_store = filesystem.root_store();
        if self.empty {
            let mut transaction = filesystem.clone().new_transaction(&[]).await?;
            ObjectStore::create_object_with_id(
                &root_store,
                &mut transaction,
                self.object_id(),
                HandleOptions::default(),
            )
            .await?;
            transaction.commit().await;
        } else {
            let handle =
                ObjectStore::open_object(&root_store, self.object_id, HandleOptions::default())
                    .await?;
            if handle.get_size() > 0 {
                let serialized_info = handle.contents(MAX_ALLOCATOR_INFO_SERIALIZED_SIZE).await?;
                let info: AllocatorInfo = deserialize_from(&serialized_info[..])?;
                let mut handles = Vec::new();
                for object_id in &info.layers {
                    handles.push(
                        ObjectStore::open_object(&root_store, *object_id, HandleOptions::default())
                            .await?,
                    );
                }
                {
                    let mut inner = self.inner.lock().unwrap();
                    // After replaying, allocated_bytes should include all the deltas since the time
                    // the allocator was last flushed, so here we just need to add whatever is
                    // recorded in info.
                    inner.allocated_bytes += info.allocated_bytes;
                    inner.info = info;
                }
                self.tree.append_layers(handles.into_boxed_slice()).await?;
            }
        }
        self.inner.lock().unwrap().opened = true;
        Ok(())
    }
pub async fn ensure_open ( & self ) -> Result < ( ) , Error > { { if self . inner . lock ( ) . unwrap ( ) . opened { return Ok ( ( ) ) ; } } let _guard = self . allocation_lock . lock ( ) . await ; { if self . inner . lock ( ) . unwrap ( ) . opened { // We lost a race. return Ok ( ( ) ) ; } } let filesystem = self . filesystem . upgrade ( ) . unwrap ( ) ; let root_store = filesystem . root_store ( ) ; if self . empty { let mut transaction = filesystem . clone ( ) . new_transaction ( & [ ] ) . await ? ; ObjectStore :: create_object_with_id ( & root_store , & mut transaction , self . object_id ( ) , HandleOptions :: default ( ) , ) . await ? ; transaction . commit ( ) . await ; } else { let handle = ObjectStore :: open_object ( & root_store , self . object_id , HandleOptions :: default ( ) ) . await ? ; if handle . get_size ( ) > 0 { let serialized_info = handle . contents ( MAX_ALLOCATOR_INFO_SERIALIZED_SIZE ) . await ? ; let info : AllocatorInfo = deserialize_from ( & serialized_info [ .. ] ) ? ; let mut handles = Vec :: new ( ) ; for object_id in & info . layers { handles . push ( ObjectStore :: open_object ( & root_store , * object_id , HandleOptions :: default ( ) ) . await ? , ) ; } { let mut inner = self . inner . lock ( ) . unwrap ( ) ; // After replaying, allocated_bytes should include all the deltas since the time // the allocator was last flushed, so here we just need to add whatever is // recorded in info. inner . allocated_bytes += info . allocated_bytes ; inner . info = info ; } self . tree . append_layers ( handles . into_boxed_slice ( ) ) . await ? ; } } self . inner . lock ( ) . unwrap ( ) . opened = true ; Ok ( ( ) ) }
Ensures the allocator is open.
Ensures the allocator is open .
&self