Skip to content

Commit e12c99f

Browse files
committed
exceptions
1 parent 9c309e2 commit e12c99f

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

client-v2/src/main/java/com/clickhouse/client/api/Client.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.apache.commons.compress.compressors.lz4.FramedLZ4CompressorOutputStream;
4747
import org.apache.hc.core5.concurrent.DefaultThreadFactory;
4848
import org.apache.hc.core5.http.ClassicHttpResponse;
49+
import org.apache.hc.core5.http.ConnectionRequestTimeoutException;
4950
import org.apache.hc.core5.http.HttpStatus;
5051
import org.apache.hc.core5.http.NoHttpResponseException;
5152
import org.slf4j.Logger;
@@ -892,7 +893,7 @@ public CompletableFuture<InsertResponse> insert(String tableName, List<?> data,
892893
metrics.operationComplete();
893894
metrics.setQueryId(queryId);
894895
return new InsertResponse(metrics);
895-
} catch (NoHttpResponseException e) {
896+
} catch (NoHttpResponseException | ConnectionRequestTimeoutException e) {
896897
LOG.warn("Failed to get response. Retrying.", e);
897898
selectedNode = getNextAliveNode();
898899
continue;
@@ -1010,12 +1011,12 @@ public CompletableFuture<InsertResponse> insert(String tableName,
10101011
metrics.operationComplete();
10111012
metrics.setQueryId(queryId);
10121013
return new InsertResponse(metrics);
1013-
} catch (NoHttpResponseException e) {
1014+
} catch (NoHttpResponseException | ConnectionRequestTimeoutException e) {
10141015
if (i < maxRetries) {
10151016
try {
10161017
data.reset();
10171018
} catch (IOException ioe) {
1018-
throw new ClientException("Failed to get response", e);
1019+
throw new ClientException("Failed to reset stream for retry", e);
10191020
}
10201021
LOG.warn("Failed to get response. Retrying.", e);
10211022
selectedNode = getNextAliveNode();
@@ -1173,6 +1174,10 @@ public CompletableFuture<QueryResponse> query(String sqlQuery, Map<String, Objec
11731174
metrics.operationComplete();
11741175

11751176
return new QueryResponse(httpResponse, finalSettings.getFormat(), finalSettings, metrics);
1177+
} catch (NoHttpResponseException | ConnectionRequestTimeoutException e) {
1178+
LOG.warn("Failed to get response. Retrying.", e);
1179+
selectedNode = getNextAliveNode();
1180+
continue;
11761181
} catch (ClientException e) {
11771182
throw e;
11781183
} catch (Exception e) {

client-v2/src/main/java/com/clickhouse/client/api/internal/HttpAPIClientHelper.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.apache.hc.client5.http.socket.PlainConnectionSocketFactory;
2626
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
2727
import org.apache.hc.core5.http.ClassicHttpResponse;
28+
import org.apache.hc.core5.http.ConnectionRequestTimeoutException;
2829
import org.apache.hc.core5.http.ContentType;
2930
import org.apache.hc.core5.http.Header;
3031
import org.apache.hc.core5.http.HttpEntity;
@@ -246,11 +247,7 @@ public ClassicHttpResponse executeRequest(ClickHouseNode server, Map<String, Obj
246247
} catch (ConnectException | NoRouteToHostException e) {
247248
LOG.warn("Failed to connect to '{}': {}", server.getHost(), e.getMessage());
248249
throw new ClientException("Failed to connect", e);
249-
} catch (ServerException e) {
250-
throw e;
251-
} catch (NoHttpResponseException e) {
252-
throw e;
253-
} catch (ClientException e) {
250+
} catch (ServerException | NoHttpResponseException | ConnectionRequestTimeoutException | ClientException e) {
254251
throw e;
255252
} catch (Exception e) {
256253
throw new ClientException("Failed to execute request", e);

0 commit comments

Comments
 (0)