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

[Backport 2.11-with-features] [Backport 2.11] Fixing hanging tasks for correlations #923

Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensearch.OpenSearchStatusException;
import org.opensearch.ResourceNotFoundException;
import org.opensearch.cluster.routing.Preference;
import org.opensearch.core.action.ActionListener;
import org.opensearch.action.bulk.BulkRequest;
Expand Down Expand Up @@ -84,6 +85,11 @@ public void onResponse(SearchResponse response) {
correlateFindingAction.onFailures(new OpenSearchStatusException("Search request timed out", RestStatus.REQUEST_TIMEOUT));
}

if (response.getHits().getHits().length == 0) {
correlateFindingAction.onFailures(
new ResourceNotFoundException("Failed to find hits in metadata index for finding id {}", finding.getId()));
}

Map<String, Object> hitSource = response.getHits().getHits()[0].getSourceAsMap();
long counter = Long.parseLong(hitSource.get("counter").toString());

Expand Down Expand Up @@ -125,7 +131,7 @@ public void onResponse(MultiSearchResponse items) {
continue;
}

long totalHits = response.getResponse().getHits().getTotalHits().value;
long totalHits = response.getResponse().getHits().getHits().length;
totalNeighbors += totalHits;

for (int idx = 0; idx < totalHits; ++idx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.apache.logging.log4j.Logger;
import org.apache.lucene.search.join.ScoreMode;
import org.opensearch.OpenSearchStatusException;
import org.opensearch.ResourceNotFoundException;
import org.opensearch.cluster.routing.Preference;
import org.opensearch.core.action.ActionListener;
import org.opensearch.action.ActionRequest;
Expand Down Expand Up @@ -515,6 +516,11 @@ public void onFailure(Exception e) {
client.search(searchRequest, new ActionListener<>() {
@Override
public void onResponse(SearchResponse response) {
if (response.getHits().getHits().length == 0) {
onFailures(new ResourceNotFoundException(
"Failed to find hits in metadata index for finding id {}", request.getFinding().getId()));
}

String id = response.getHits().getHits()[0].getId();
Map<String, Object> hitSource = response.getHits().getHits()[0].getSourceAsMap();
long scoreTimestamp = (long) hitSource.get("scoreTimestamp");
Expand Down Expand Up @@ -653,6 +659,7 @@ public void onOperation() {
}

public void onFailures(Exception t) {
log.error("Exception occurred while processing correlations", t);
if (counter.compareAndSet(false, true)) {
finishHim(t);
}
Expand Down
Loading