implement index delete

This commit is contained in:
mpostma 2021-03-06 12:57:56 +01:00
parent 86211b1ddd
commit d9254c4355
No known key found for this signature in database
GPG key ID: CBC8A7C1D7A28C3A
5 changed files with 171 additions and 30 deletions

View file

@ -1,11 +1,13 @@
mod updates;
mod index_actor;
mod update_actor;
mod uuid_resolver;
mod update_store;
mod update_handler;
mod update_store;
mod updates;
mod uuid_resolver;
use std::path::Path;
use std::sync::Arc;
use std::time::Duration;
use actix_web::web::{Bytes, Payload};
use anyhow::Context;
@ -14,6 +16,7 @@ use futures::stream::StreamExt;
use milli::update::{IndexDocumentsMethod, UpdateFormat};
use serde::{Serialize, Deserialize};
use tokio::sync::{mpsc, oneshot};
use tokio::time::sleep;
use uuid::Uuid;
pub use updates::{Processed, Processing, Failed};
@ -146,8 +149,14 @@ impl IndexController {
Ok(index_meta)
}
fn delete_index(&self, index_uid: String) -> anyhow::Result<()> {
todo!()
pub async fn delete_index(&self, index_uid: String) -> anyhow::Result<()> {
let uuid = self.uuid_resolver
.delete(index_uid)
.await?
.context("index not found")?;
self.update_handle.delete(uuid.clone()).await?;
self.index_handle.delete(uuid).await?;
Ok(())
}
pub async fn update_status(&self, index: String, id: u64) -> anyhow::Result<Option<UpdateStatus>> {
@ -219,3 +228,16 @@ impl IndexController {
Ok(result)
}
}
pub async fn get_arc_ownership_blocking<T>(mut item: Arc<T>) -> T {
loop {
match Arc::try_unwrap(item) {
Ok(item) => return item,
Err(item_arc) => {
item = item_arc;
sleep(Duration::from_millis(100)).await;
continue;
}
}
}
}