Skip to content

Commit b92615b

Browse files
committed
[Elasticsearch] Fail on deletes, except when node is already absent
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
1 parent c9cd748 commit b92615b

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

core/src/search_stores/search_store.rs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,21 @@ impl SearchStore for ElasticsearchSearchStore {
187187
.send()
188188
.await?;
189189
// todo(kw-search): fail on error
190-
if !response.status_code().is_success() {
191-
let error = response.json::<serde_json::Value>().await?;
192-
error!(
193-
error = %error,
194-
globally_unique_id = node.unique_id(),
195-
"[ElasticsearchSearchStore] Failed to delete {}",
196-
node.node_type.to_string()
197-
);
190+
match response.status_code().is_success() {
191+
true => Ok(()),
192+
false => {
193+
let error = response.json::<serde_json::Value>().await?;
194+
if error["result"] == "not_found" {
195+
info!(
196+
globally_unique_id = node.unique_id(),
197+
"[ElasticsearchSearchStore] Delete node on non-existent document"
198+
);
199+
Ok(())
200+
} else {
201+
Err(anyhow::anyhow!("Failed to delete node {}", error))
202+
}
203+
}
198204
}
199-
Ok(())
200205
}
201206

202207
async fn delete_data_source_nodes(&self, data_source_id: &str) -> Result<()> {
@@ -211,15 +216,16 @@ impl SearchStore for ElasticsearchSearchStore {
211216
.send()
212217
.await?;
213218
// todo(kw-search): fail on error
214-
if !response.status_code().is_success() {
215-
let error = response.json::<serde_json::Value>().await?;
216-
error!(
217-
error = %error,
218-
data_source_id = data_source_id,
219-
"[ElasticsearchSearchStore] Failed to delete data source nodes"
220-
);
219+
match response.status_code().is_success() {
220+
true => Ok(()),
221+
false => {
222+
let error = response.json::<serde_json::Value>().await?;
223+
Err(anyhow::anyhow!(
224+
"Failed to delete data source nodes {}",
225+
error
226+
))
227+
}
221228
}
222-
Ok(())
223229
}
224230

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

0 commit comments

Comments
 (0)