From cf6f6c6b37071c23c3372b8b4ebdc9f51b4da3dc Mon Sep 17 00:00:00 2001 From: Adrien Guillo Date: Thu, 23 May 2024 15:00:22 -0400 Subject: [PATCH] Fix panic on index not found in Pg metastore --- .../src/metastore/postgres/metastore.rs | 8 +++++--- quickwit/quickwit-proto/src/metastore/mod.rs | 6 ++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/quickwit/quickwit-metastore/src/metastore/postgres/metastore.rs b/quickwit/quickwit-metastore/src/metastore/postgres/metastore.rs index 89e887c5e65..c6fcfb45ada 100644 --- a/quickwit/quickwit-metastore/src/metastore/postgres/metastore.rs +++ b/quickwit/quickwit-metastore/src/metastore/postgres/metastore.rs @@ -416,7 +416,7 @@ impl MetastoreService for PostgresqlMetastore { &mut self, request: IndexMetadataRequest, ) -> MetastoreResult { - let response = if let Some(index_uid) = &request.index_uid { + let pg_index_opt = if let Some(index_uid) = &request.index_uid { index_opt_for_uid(&self.connection_pool, index_uid.clone()).await? } else if let Some(index_id) = &request.index_id { index_opt(&self.connection_pool, index_id).await? @@ -427,9 +427,11 @@ impl MetastoreService for PostgresqlMetastore { cause: "".to_string(), }); }; - let index_metadata = response + let index_metadata = pg_index_opt .ok_or(MetastoreError::NotFound(EntityKind::Index { - index_id: request.index_id.expect("`index_id` should be set"), + index_id: request + .into_index_id() + .expect("`index_id` or `index_uid` should be set"), }))? .index_metadata()?; let response = IndexMetadataResponse::try_from_index_metadata(&index_metadata)?; diff --git a/quickwit/quickwit-proto/src/metastore/mod.rs b/quickwit/quickwit-proto/src/metastore/mod.rs index d065791ef17..768256447ff 100644 --- a/quickwit/quickwit-proto/src/metastore/mod.rs +++ b/quickwit/quickwit-proto/src/metastore/mod.rs @@ -262,6 +262,12 @@ impl fmt::Display for SourceType { } impl IndexMetadataRequest { + pub fn into_index_id(self) -> Option { + self.index_uid + .map(|index_uid| index_uid.index_id) + .or(self.index_id) + } + pub fn for_index_id(index_id: IndexId) -> Self { Self { index_uid: None,