Skip to content

Commit

Permalink
Fix panic on index not found in Pg metastore
Browse files Browse the repository at this point in the history
  • Loading branch information
guilload committed May 23, 2024
1 parent 0af2998 commit cf6f6c6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ impl MetastoreService for PostgresqlMetastore {
&mut self,
request: IndexMetadataRequest,
) -> MetastoreResult<IndexMetadataResponse> {
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?
Expand All @@ -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)?;
Expand Down
6 changes: 6 additions & 0 deletions quickwit/quickwit-proto/src/metastore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ impl fmt::Display for SourceType {
}

impl IndexMetadataRequest {
pub fn into_index_id(self) -> Option<IndexId> {
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,
Expand Down

0 comments on commit cf6f6c6

Please sign in to comment.