Skip to content

Commit

Permalink
fix: Ensure to display version_conflict ES error message as warn - EX…
Browse files Browse the repository at this point in the history
…O-74730

When we send analytics to ES, we firstly try to send it in a bulk.
If an element of the bulk generates an error in ES, we resend each request of the bulk one by one.
If the failed one is the i-st element, then request 1..i-1 will generated a version_conflict_engine_exception.
In 6.5, this was seen as a warn, an not generates an error.
In 7.0, it is seen as error, and then, like for each error, we try to resend it 5 times before dropping it, which could generate a log of logs.

This commit ensure to not raise an exception in this case :
- ES answer contains "error":true
AND ES answer contains "type":"version_conflict_engine_exception"
AND ES anwser concern only one entry.

If we have more than one entry, then we are in a bulk, and we cannot know which entry generated the version conflict, so we have to consider this as an error, and rerun each request separatly.

Resolves meesd-io/meeds#2487
  • Loading branch information
rdenarie committed Oct 14, 2024
1 parent 507da6e commit 79a66d1
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,24 @@ private boolean isError(int status) {
}

private ElasticsearchResponse handleESResponse(ElasticsearchResponse response, String uri, String content) {
if (isError(response) || StringUtils.contains(response.getMessage(), "\"errors\":true")) {
if (isError(response)) {
throw new IllegalStateException(String.format("Error message returned from ES: %s. URI: %s. Content: %s",
response.getMessage(),
uri,
content));
} else if (StringUtils.contains(response.getMessage(), "\"type\":\"version_conflict_engine_exception\"")) {
LOG.warn("ID conflict in some content: {}", response.getMessage());
}
if (StringUtils.contains(response.getMessage(), "\"errors\":true")) {
if (StringUtils.contains(response.getMessage(), "\"type\":\"version_conflict_engine_exception\"")
&& StringUtils.countMatches(response.getMessage(),"{\"create\":{") == 1) {
//the ES response is not answer of a bulk, but of a single insert
//it means the entry already exists in ES, no need to raise an error
LOG.warn("ID conflict in some content: {}", response.getMessage());
} else {
throw new IllegalStateException(String.format("Error message returned from ES: %s. URI: %s. Content: %s",
response.getMessage(),
uri,
content));
}
}
return response;
}
Expand Down

0 comments on commit 79a66d1

Please sign in to comment.