@@ -1317,7 +1317,7 @@ public CompletableFuture<InsertResponse> insert(String tableName, List<?> data,
13171317 Supplier <InsertResponse > supplier = () -> {
13181318 long startTime = System .nanoTime ();
13191319 // Selecting some node
1320- Endpoint selectedEndpoint = getEndpoint ();
1320+ Endpoint selectedEndpoint = nodeSelector . getEndpoint ();
13211321
13221322 RuntimeException lastException = null ;
13231323 for (int i = 0 ; i <= maxRetries ; i ++) {
@@ -1343,14 +1343,6 @@ public CompletableFuture<InsertResponse> insert(String tableName, List<?> data,
13431343 out .close ();
13441344 })) {
13451345
1346-
1347- // Check response
1348- if (httpResponse .getCode () == HttpStatus .SC_SERVICE_UNAVAILABLE ) {
1349- LOG .warn ("Failed to get response. Server returned {}. Retrying. (Duration: {})" , httpResponse .getCode (), durationSince (startTime ));
1350- selectedEndpoint = getNextAliveNode (selectedEndpoint );
1351- continue ;
1352- }
1353-
13541346 ClientStatisticsHolder clientStats = globalClientStats .remove (operationId );
13551347 OperationMetrics metrics = new OperationMetrics (clientStats );
13561348 String summary = HttpAPIClientHelper .getHeaderVal (httpResponse .getFirstHeader (ClickHouseHttpProto .HEADER_SRV_SUMMARY ), "{}" );
@@ -1364,7 +1356,7 @@ public CompletableFuture<InsertResponse> insert(String tableName, List<?> data,
13641356 lastException = httpClientHelper .wrapException (msg , e , requestSettings .getQueryId ());
13651357 if (httpClientHelper .shouldRetry (e , requestSettings .getAllSettings ())) {
13661358 LOG .warn ("Retrying." , e );
1367- selectedEndpoint = getNextAliveNode (selectedEndpoint );
1359+ selectedEndpoint = nodeSelector . getNextAliveNode (selectedEndpoint );
13681360 } else {
13691361 throw lastException ;
13701362 }
@@ -1539,7 +1531,7 @@ public CompletableFuture<InsertResponse> insert(String tableName,
15391531 responseSupplier = () -> {
15401532 long startTime = System .nanoTime ();
15411533 // Selecting some node
1542- Endpoint selectedEndpoint = getEndpoint ();
1534+ Endpoint selectedEndpoint = nodeSelector . getEndpoint ();
15431535
15441536 RuntimeException lastException = null ;
15451537 for (int i = 0 ; i <= retries ; i ++) {
@@ -1551,21 +1543,6 @@ public CompletableFuture<InsertResponse> insert(String tableName,
15511543 out .close ();
15521544 })) {
15531545
1554-
1555- // Check response
1556- if (httpResponse .getCode () == HttpStatus .SC_SERVICE_UNAVAILABLE ) {
1557- LOG .warn ("Failed to get response. Server returned {}. Retrying. (Duration: {})" , httpResponse .getCode (), durationSince (startTime ));
1558- selectedEndpoint = getNextAliveNode (selectedEndpoint );
1559- if (i < retries ) {
1560- try {
1561- writer .onRetry ();
1562- } catch (IOException ioe ) {
1563- throw new ClientException ("Failed to reset stream before next attempt" , ioe );
1564- }
1565- }
1566- continue ;
1567- }
1568-
15691546 OperationMetrics metrics = new OperationMetrics (finalClientStats );
15701547 String summary = HttpAPIClientHelper .getHeaderVal (httpResponse .getFirstHeader (ClickHouseHttpProto .HEADER_SRV_SUMMARY ), "{}" );
15711548 ProcessParser .parseSummary (summary , metrics );
@@ -1578,7 +1555,7 @@ public CompletableFuture<InsertResponse> insert(String tableName,
15781555 lastException = httpClientHelper .wrapException (msg , e , requestSettings .getQueryId ());
15791556 if (httpClientHelper .shouldRetry (e , requestSettings .getAllSettings ())) {
15801557 LOG .warn ("Retrying." , e );
1581- selectedEndpoint = getNextAliveNode (selectedEndpoint );
1558+ selectedEndpoint = nodeSelector . getNextAliveNode (selectedEndpoint );
15821559 } else {
15831560 throw lastException ;
15841561 }
@@ -1675,27 +1652,20 @@ public CompletableFuture<QueryResponse> query(String sqlQuery, Map<String, Objec
16751652 Supplier <QueryResponse > responseSupplier = () -> {
16761653 long startTime = System .nanoTime ();
16771654 // Selecting some node
1678- Endpoint selectedEndpoint = getEndpoint ();
1655+ Endpoint selectedEndpoint = nodeSelector . getEndpoint ();
16791656 RuntimeException lastException = null ;
16801657 for (int i = 0 ; i <= retries ; i ++) {
16811658 ClassicHttpResponse httpResponse = null ;
16821659 try {
16831660 boolean useMultipart = ClientConfigProperties .HTTP_SEND_PARAMS_IN_BODY .getOrDefault (requestSettings .getAllSettings ());
16841661 if (queryParams != null && useMultipart ) {
16851662 httpResponse = httpClientHelper .executeMultiPartRequest (selectedEndpoint ,
1686- requestSettings .getAllSettings (), sqlQuery );
1663+ requestSettings .getAllSettings (), sqlQuery );
16871664 } else {
16881665 httpResponse = httpClientHelper .executeRequest (selectedEndpoint ,
16891666 requestSettings .getAllSettings (),
16901667 sqlQuery );
16911668 }
1692- // Check response
1693- if (httpResponse .getCode () == HttpStatus .SC_SERVICE_UNAVAILABLE ) {
1694- LOG .warn ("Failed to get response. Server returned {}. Retrying. (Duration: {})" , httpResponse .getCode (), durationSince (startTime ));
1695- selectedEndpoint = getNextAliveNode (selectedEndpoint );
1696- HttpAPIClientHelper .closeQuietly (httpResponse );
1697- continue ;
1698- }
16991669
17001670 OperationMetrics metrics = new OperationMetrics (clientStats );
17011671 String summary = HttpAPIClientHelper .getHeaderVal (httpResponse
@@ -1720,7 +1690,7 @@ public CompletableFuture<QueryResponse> query(String sqlQuery, Map<String, Objec
17201690 lastException = httpClientHelper .wrapException (msg , e , requestSettings .getQueryId ());
17211691 if (httpClientHelper .shouldRetry (e , requestSettings .getAllSettings ())) {
17221692 LOG .warn ("Retrying." , e );
1723- selectedEndpoint = getNextAliveNode (selectedEndpoint );
1693+ selectedEndpoint = nodeSelector . getNextAliveNode (selectedEndpoint );
17241694 } else {
17251695 throw lastException ;
17261696 }
@@ -2232,24 +2202,7 @@ public void updateAccessToken(String accessToken) {
22322202 this .credentialsManager .setAccessToken (accessToken );
22332203 }
22342204
2235- /**
2236- * Returns the first alive endpoint for the initial request attempt.
2237- * Keeps affinity to the primary server when it is healthy.
2238- */
2239- private Endpoint getEndpoint () {
2240- return nodeSelector .getEndpoint ();
2241- }
22422205
2243- /**
2244- * Quarantines the failed endpoint and returns the next alive endpoint.
2245- * Used inside retry loops after a retryable failure.
2246- *
2247- * @param failedEndpoint the endpoint that just failed
2248- * @return the next alive endpoint
2249- */
2250- private Endpoint getNextAliveNode (Endpoint failedEndpoint ) {
2251- return nodeSelector .getNextAliveNode (failedEndpoint );
2252- }
22532206
22542207 public static final String VALUES_LIST_DELIMITER = "," ;
22552208
0 commit comments