Skip to content

Commit

Permalink
[Elasticsearch] Fail on deletes, except when node is already absent (#…
Browse files Browse the repository at this point in the history
…9621)

Description
---
As per title

Risk
---
low
Introduces failures on deletes that are not from a missing node, but we should spot and act on those

Deploy
---
core
  • Loading branch information
philipperolet authored Dec 23, 2024
1 parent c9cd748 commit be2a9fb
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions core/src/search_stores/search_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,21 @@ 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,
globally_unique_id = node.unique_id(),
"[ElasticsearchSearchStore] Failed to delete {}",
node.node_type.to_string()
);
match response.status_code().is_success() {
true => Ok(()),
false => {
let error = response.json::<serde_json::Value>().await?;
if error["result"] == "not_found" {
info!(
globally_unique_id = node.unique_id(),
"[ElasticsearchSearchStore] Delete node on non-existent document"
);
Ok(())
} else {
Err(anyhow::anyhow!("Failed to delete node {}", error))
}
}
}
Ok(())
}

async fn delete_data_source_nodes(&self, data_source_id: &str) -> Result<()> {
Expand All @@ -211,15 +216,16 @@ 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"
);
match response.status_code().is_success() {
true => Ok(()),
false => {
let error = response.json::<serde_json::Value>().await?;
Err(anyhow::anyhow!(
"Failed to delete data source nodes {}",
error
))
}
}
Ok(())
}

fn clone_box(&self) -> Box<dyn SearchStore + Sync + Send> {
Expand Down

0 comments on commit be2a9fb

Please sign in to comment.