mirror of https://github.com/apache/druid.git
Memoize the redundant calls to overlord in sql statements endpoint (#16839)
This commit is contained in:
parent
c8323d1a7c
commit
08f9ec1cae
|
@ -113,7 +113,6 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Supplier;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
|
@ -588,19 +587,19 @@ public class SqlStatementResource
|
||||||
MSQControllerTask msqControllerTask = getMSQControllerTaskAndCheckPermission(queryId, authenticationResult, forAction);
|
MSQControllerTask msqControllerTask = getMSQControllerTaskAndCheckPermission(queryId, authenticationResult, forAction);
|
||||||
SqlStatementState sqlStatementState = SqlStatementResourceHelper.getSqlStatementState(statusPlus);
|
SqlStatementState sqlStatementState = SqlStatementResourceHelper.getSqlStatementState(statusPlus);
|
||||||
|
|
||||||
Supplier<Optional<MSQTaskReportPayload>> msqTaskReportPayloadSupplier = () -> {
|
MSQTaskReportPayload taskReportPayload = null;
|
||||||
|
if (detail || SqlStatementState.FAILED == sqlStatementState) {
|
||||||
try {
|
try {
|
||||||
return Optional.ofNullable(SqlStatementResourceHelper.getPayload(
|
taskReportPayload = SqlStatementResourceHelper.getPayload(
|
||||||
contactOverlord(overlordClient.taskReportAsMap(queryId), queryId)
|
contactOverlord(overlordClient.taskReportAsMap(queryId), queryId)
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
catch (DruidException e) {
|
catch (DruidException e) {
|
||||||
if (e.getErrorCode().equals("notFound") || e.getMessage().contains("Unable to contact overlord")) {
|
if (!e.getErrorCode().equals("notFound") && !e.getMessage().contains("Unable to contact overlord")) {
|
||||||
return Optional.empty();
|
throw e;
|
||||||
}
|
}
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
if (SqlStatementState.FAILED == sqlStatementState) {
|
if (SqlStatementState.FAILED == sqlStatementState) {
|
||||||
return SqlStatementResourceHelper.getExceptionPayload(
|
return SqlStatementResourceHelper.getExceptionPayload(
|
||||||
|
@ -608,7 +607,7 @@ public class SqlStatementResource
|
||||||
taskResponse,
|
taskResponse,
|
||||||
statusPlus,
|
statusPlus,
|
||||||
sqlStatementState,
|
sqlStatementState,
|
||||||
msqTaskReportPayloadSupplier.get().orElse(null),
|
taskReportPayload,
|
||||||
jsonMapper,
|
jsonMapper,
|
||||||
detail
|
detail
|
||||||
);
|
);
|
||||||
|
@ -627,9 +626,9 @@ public class SqlStatementResource
|
||||||
msqControllerTask.getQuerySpec().getDestination()
|
msqControllerTask.getQuerySpec().getDestination()
|
||||||
).orElse(null) : null,
|
).orElse(null) : null,
|
||||||
null,
|
null,
|
||||||
detail ? SqlStatementResourceHelper.getQueryStagesReport(msqTaskReportPayloadSupplier.get().orElse(null)) : null,
|
SqlStatementResourceHelper.getQueryStagesReport(taskReportPayload),
|
||||||
detail ? SqlStatementResourceHelper.getQueryCounters(msqTaskReportPayloadSupplier.get().orElse(null)) : null,
|
SqlStatementResourceHelper.getQueryCounters(taskReportPayload),
|
||||||
detail ? SqlStatementResourceHelper.getQueryWarningDetails(msqTaskReportPayloadSupplier.get().orElse(null)) : null
|
SqlStatementResourceHelper.getQueryWarningDetails(taskReportPayload)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue