From 7fc7eb7457a1bf96d49813277c6b02625ea46bfc Mon Sep 17 00:00:00 2001 From: many Date: Thu, 7 Oct 2021 15:14:25 +0200 Subject: [PATCH 1/3] Make sure to remove newly created index if uid is already taken --- .../src/index_controller/index_resolver/mod.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/meilisearch-lib/src/index_controller/index_resolver/mod.rs b/meilisearch-lib/src/index_controller/index_resolver/mod.rs index e68bd46f8..6400f0f19 100644 --- a/meilisearch-lib/src/index_controller/index_resolver/mod.rs +++ b/meilisearch-lib/src/index_controller/index_resolver/mod.rs @@ -98,8 +98,13 @@ where } let uuid = Uuid::new_v4(); let index = self.index_store.create(uuid, primary_key).await?; - self.index_uuid_store.insert(uid, uuid).await?; - Ok(index) + match self.index_uuid_store.insert(uid, uuid).await { + Err(e) => { + let _ = self.index_store.delete(uuid).await; + Err(e) + } + Ok(()) => Ok(index), + } } pub async fn list(&self) -> Result> { From 0774b1efa518850e34d86601b70b8ffef6f1676e Mon Sep 17 00:00:00 2001 From: many Date: Thu, 7 Oct 2021 15:15:34 +0200 Subject: [PATCH 2/3] Close index's heed environment when index is deleted --- .../src/index_controller/index_resolver/mod.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/meilisearch-lib/src/index_controller/index_resolver/mod.rs b/meilisearch-lib/src/index_controller/index_resolver/mod.rs index 6400f0f19..c468564a5 100644 --- a/meilisearch-lib/src/index_controller/index_resolver/mod.rs +++ b/meilisearch-lib/src/index_controller/index_resolver/mod.rs @@ -100,7 +100,9 @@ where let index = self.index_store.create(uuid, primary_key).await?; match self.index_uuid_store.insert(uid, uuid).await { Err(e) => { - let _ = self.index_store.delete(uuid).await; + if let Some(index) = self.index_store.delete(uuid).await? { + index.inner().clone().prepare_for_closing(); + } Err(e) } Ok(()) => Ok(index), @@ -126,7 +128,9 @@ where pub async fn delete_index(&self, uid: String) -> Result { match self.index_uuid_store.delete(uid.clone()).await? { Some(uuid) => { - let _ = self.index_store.delete(uuid).await; + if let Some(index) = self.index_store.delete(uuid).await? { + index.inner().clone().prepare_for_closing(); + } Ok(uuid) } None => Err(IndexResolverError::UnexistingIndex(uid)), From a92a0c3ed3788cd196486de2a5efdc186cf56e4f Mon Sep 17 00:00:00 2001 From: many Date: Thu, 7 Oct 2021 17:36:54 +0200 Subject: [PATCH 3/3] Log the error instead of returning it when deletion fails --- .../src/index_controller/index_resolver/mod.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/meilisearch-lib/src/index_controller/index_resolver/mod.rs b/meilisearch-lib/src/index_controller/index_resolver/mod.rs index c468564a5..979f6dc6c 100644 --- a/meilisearch-lib/src/index_controller/index_resolver/mod.rs +++ b/meilisearch-lib/src/index_controller/index_resolver/mod.rs @@ -6,6 +6,7 @@ use std::path::Path; use error::{IndexResolverError, Result}; use index_store::{IndexStore, MapIndexStore}; +use log::error; use uuid::Uuid; use uuid_store::{HeedUuidStore, UuidStore}; @@ -100,8 +101,12 @@ where let index = self.index_store.create(uuid, primary_key).await?; match self.index_uuid_store.insert(uid, uuid).await { Err(e) => { - if let Some(index) = self.index_store.delete(uuid).await? { - index.inner().clone().prepare_for_closing(); + match self.index_store.delete(uuid).await { + Ok(Some(index)) => { + index.inner().clone().prepare_for_closing(); + } + Ok(None) => (), + Err(e) => error!("Error while deleting index: {:?}", e), } Err(e) } @@ -128,8 +133,12 @@ where pub async fn delete_index(&self, uid: String) -> Result { match self.index_uuid_store.delete(uid.clone()).await? { Some(uuid) => { - if let Some(index) = self.index_store.delete(uuid).await? { - index.inner().clone().prepare_for_closing(); + match self.index_store.delete(uuid).await { + Ok(Some(index)) => { + index.inner().clone().prepare_for_closing(); + } + Ok(None) => (), + Err(e) => error!("Error while deleting index: {:?}", e), } Ok(uuid) }