JNSimba commented on code in PR #305:
URL:
https://github.com/apache/doris-spark-connector/pull/305#discussion_r2036621815
##########
spark-doris-connector/spark-doris-connector-base/src/main/java/org/apache/doris/spark/client/write/AbstractStreamLoadProcessor.java:
##########
@@ -402,15 +395,38 @@ private Future<CloseableHttpResponse>
buildReqAndExec(String host, Integer port,
entity = new GzipCompressingEntity(entity);
}
httpPut.setEntity(entity);
+ Thread currentThread = Thread.currentThread();
- logger.info("table {}.{} stream load started for {} on host {}:{}",
database, table, currentLabel != null ? currentLabel : "group commit", host,
port);
- return getExecutors().submit(() -> client.execute(httpPut));
+ logger.info("table {}.{} stream load started for {} on host {}:{}",
database, table,
+ currentLabel != null ? currentLabel : "group commit", host,
port);
+ return getExecutors().submit(() -> {
+ CloseableHttpResponse response = client.execute(httpPut);
+ // stream load http request finished unexpectedly
+ if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
+ unexpectedException = new StreamLoadException(
+ "stream load failed, status: " +
response.getStatusLine().getStatusCode()
+ + ", reason: " +
response.getStatusLine().getReasonPhrase());
+ currentThread.interrupt();
+ }
+ String entityStr = EntityUtils.toString(response.getEntity());
+ StreamLoadResponse streamLoadResponse =
MAPPER.readValue(entityStr, StreamLoadResponse.class);
+ logger.info("stream load response: " + entityStr);
+ if (streamLoadResponse != null && !streamLoadResponse.isSuccess())
{
+ unexpectedException = new StreamLoadException(
+ "stream load failed, txnId: " +
streamLoadResponse.getTxnId()
+ + ", status: " + streamLoadResponse.getStatus()
+ + ", msg: " + streamLoadResponse.getMessage());
+ currentThread.interrupt();
+ }
+ return streamLoadResponse;
+ });
}
@Override
public void close() throws IOException {
createNewBatch = true;
isFirstRecordOfBatch = true;
Review Comment:
```suggestion
try(CloseableHttpResponse response = client.execute(httpPut)){
if (response.getStatusLine().getStatusCode() !=
HttpStatus.SC_OK) {
unexpectedException = new StreamLoadException(
"stream load failed, status: " +
response.getStatusLine().getStatusCode()
+ ", reason: " +
response.getStatusLine().getReasonPhrase());
throw unexpectedException;
}
String entityStr =
EntityUtils.toString(response.getEntity());
StreamLoadResponse streamLoadResponse =
MAPPER.readValue(entityStr, StreamLoadResponse.class);
logger.info("stream load response: " + entityStr);
if (streamLoadResponse != null &&
!streamLoadResponse.isSuccess()) {
unexpectedException = new StreamLoadException(
"stream load failed, txnId: " +
streamLoadResponse.getTxnId()
+ ", status: " +
streamLoadResponse.getStatus()
+ ", msg: " +
streamLoadResponse.getMessage());
throw unexpectedException;
}
return streamLoadResponse;
}catch(Exception ex){
// stream load http request finished unexpectedly
currentThread.interrupt();
};
});
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]