Skip to content

Commit

Permalink
Memoize the redundant calls to overlord in sql statements endpoint (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Akshat-Jain authored Aug 5, 2024
1 parent c8323d1 commit 08f9ec1
Showing 1 changed file with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Collectors;


Expand Down Expand Up @@ -588,27 +587,27 @@ private Optional<SqlStatementResult> getStatementStatus(
MSQControllerTask msqControllerTask = getMSQControllerTaskAndCheckPermission(queryId, authenticationResult, forAction);
SqlStatementState sqlStatementState = SqlStatementResourceHelper.getSqlStatementState(statusPlus);

Supplier<Optional<MSQTaskReportPayload>> msqTaskReportPayloadSupplier = () -> {
MSQTaskReportPayload taskReportPayload = null;
if (detail || SqlStatementState.FAILED == sqlStatementState) {
try {
return Optional.ofNullable(SqlStatementResourceHelper.getPayload(
taskReportPayload = SqlStatementResourceHelper.getPayload(
contactOverlord(overlordClient.taskReportAsMap(queryId), queryId)
));
);
}
catch (DruidException e) {
if (e.getErrorCode().equals("notFound") || e.getMessage().contains("Unable to contact overlord")) {
return Optional.empty();
if (!e.getErrorCode().equals("notFound") && !e.getMessage().contains("Unable to contact overlord")) {
throw e;
}
throw e;
}
};
}

if (SqlStatementState.FAILED == sqlStatementState) {
return SqlStatementResourceHelper.getExceptionPayload(
queryId,
taskResponse,
statusPlus,
sqlStatementState,
msqTaskReportPayloadSupplier.get().orElse(null),
taskReportPayload,
jsonMapper,
detail
);
Expand All @@ -627,9 +626,9 @@ private Optional<SqlStatementResult> getStatementStatus(
msqControllerTask.getQuerySpec().getDestination()
).orElse(null) : null,
null,
detail ? SqlStatementResourceHelper.getQueryStagesReport(msqTaskReportPayloadSupplier.get().orElse(null)) : null,
detail ? SqlStatementResourceHelper.getQueryCounters(msqTaskReportPayloadSupplier.get().orElse(null)) : null,
detail ? SqlStatementResourceHelper.getQueryWarningDetails(msqTaskReportPayloadSupplier.get().orElse(null)) : null
SqlStatementResourceHelper.getQueryStagesReport(taskReportPayload),
SqlStatementResourceHelper.getQueryCounters(taskReportPayload),
SqlStatementResourceHelper.getQueryWarningDetails(taskReportPayload)
));
}
}
Expand Down

0 comments on commit 08f9ec1

Please sign in to comment.