// 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 .
async fn ensure_open(&self) -> Result<(), Error> {
        {
            if self.inner.lock().unwrap().opened {
                return Ok(());
            }
        }
        let root_store = self.filesystem.upgrade().unwrap().root_store();
        if self.empty {
            let mut transaction = Transaction::new();
            root_store
                .create_object_with_id(&mut transaction, self.object_id(), HandleOptions::default())
                .await?;
            self.filesystem.upgrade().unwrap().commit_transaction(transaction).await;
        } else {
            let handle = root_store.open_object(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(root_store.open_object(*object_id, HandleOptions::default()).await?);
                }
                self.inner.lock().unwrap().info = info;
                self.tree.set_layers(handles.into_boxed_slice()).await?;
            }
        }
        self.inner.lock().unwrap().opened = true;
        Ok(())
    }
async fn ensure_open ( & self ) -> Result < ( ) , Error > { { if self . inner . lock ( ) . unwrap ( ) . opened { return Ok ( ( ) ) ; } } let root_store = self . filesystem . upgrade ( ) . unwrap ( ) . root_store ( ) ; if self . empty { let mut transaction = Transaction :: new ( ) ; root_store . create_object_with_id ( & mut transaction , self . object_id ( ) , HandleOptions :: default ( ) ) . await ? ; self . filesystem . upgrade ( ) . unwrap ( ) . commit_transaction ( transaction ) . await ; } else { let handle = root_store . open_object ( 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 ( root_store . open_object ( * object_id , HandleOptions :: default ( ) ) . await ? ) ; } self . inner . lock ( ) . unwrap ( ) . info = info ; self . tree . set_layers ( handles . into_boxed_slice ( ) ) . await ? ; } } self . inner . lock ( ) . unwrap ( ) . opened = true ; Ok ( ( ) ) }
Ensures the allocator is open.
Ensures the allocator is open .
&self