Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Keyword search] Better error handling for search store #9590

Merged
merged 2 commits into from
Dec 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 40 additions & 13 deletions core/src/search_stores/search_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl SearchStore for ElasticsearchSearchStore {
let options = options.unwrap_or_default();

// then, search
match self
let response = self
.client
.search(SearchParts::Index(&[NODES_INDEX_NAME]))
.from(options.offset.unwrap_or(0) as i64)
Expand All @@ -122,9 +122,10 @@ impl SearchStore for ElasticsearchSearchStore {
}
}))
.send()
.await
{
Ok(response) => {
.await?;

match response.status_code().is_success() {
true => {
// get nodes from elasticsearch response in hits.hits
let response_body = response.json::<serde_json::Value>().await?;
let nodes: Vec<Node> = response_body["hits"]["hits"]
Expand All @@ -135,22 +136,26 @@ impl SearchStore for ElasticsearchSearchStore {
.collect();
Ok(nodes)
}
Err(e) => Err(e.into()),
false => {
let error = response.json::<serde_json::Value>().await?;
Err(anyhow::anyhow!("Failed to search nodes: {}", error))
}
}
}

async fn index_node(&self, node: Node) -> Result<()> {
// todo(kw-search): fail on error
let now = utils::now();
match self
let response = self
.client
.index(IndexParts::IndexId(NODES_INDEX_NAME, &node.unique_id()))
.timeout("200ms")
.body(node.clone())
.send()
.await
{
Ok(_) => {
.await?;

match response.status_code().is_success() {
true => {
info!(
duration = utils::now() - now,
globally_unique_id = node.unique_id(),
Expand All @@ -159,9 +164,10 @@ impl SearchStore for ElasticsearchSearchStore {
);
Ok(())
}
Err(e) => {
false => {
let error = response.json::<serde_json::Value>().await?;
error!(
error = %e,
error = %error,
duration = utils::now() - now,
globally_unique_id = node.unique_id(),
"[ElasticsearchSearchStore] Failed to index {}",
Expand All @@ -173,15 +179,27 @@ impl SearchStore for ElasticsearchSearchStore {
}

async fn delete_node(&self, node: Node) -> Result<()> {
self.client
let response = self
.client
.delete(DeleteParts::IndexId(NODES_INDEX_NAME, &node.unique_id()))
.send()
.await?;
// todo(kw-search): fail on error
if !response.status_code().is_success() {
let error = response.json::<serde_json::Value>().await?;
error!(
error = %error,
globally_unique_id = node.unique_id(),
"[ElasticsearchSearchStore] Failed to delete {}",
node.node_type.to_string()
);
}
Ok(())
}

async fn delete_data_source_nodes(&self, data_source_id: &str) -> Result<()> {
self.client
let response = self
.client
.delete_by_query(DeleteByQueryParts::Index(&[NODES_INDEX_NAME]))
.body(json!({
"query": {
Expand All @@ -190,6 +208,15 @@ impl SearchStore for ElasticsearchSearchStore {
}))
.send()
.await?;
// todo(kw-search): fail on error
if !response.status_code().is_success() {
let error = response.json::<serde_json::Value>().await?;
error!(
error = %error,
data_source_id = data_source_id,
"[ElasticsearchSearchStore] Failed to delete data source nodes"
);
}
Ok(())
}

Expand Down
Loading