@@ -1164,10 +1164,11 @@ public boolean ping() {
1164
1164
* @return true if the server is alive, false otherwise
1165
1165
*/
1166
1166
public boolean ping (long timeout ) {
1167
+ long startTime = System .nanoTime ();
1167
1168
try (QueryResponse response = query ("SELECT 1 FORMAT TabSeparated" ).get (timeout , TimeUnit .MILLISECONDS )) {
1168
1169
return true ;
1169
1170
} catch (Exception e ) {
1170
- LOG .debug ("Failed to connect to the server" , e );
1171
+ LOG .debug ("Failed to connect to the server (Duration: {})" , System . nanoTime () - startTime , e );
1171
1172
return false ;
1172
1173
}
1173
1174
}
@@ -1284,7 +1285,6 @@ public CompletableFuture<InsertResponse> insert(String tableName, List<?> data)
1284
1285
* @return {@code CompletableFuture<InsertResponse>} - a promise to insert response
1285
1286
*/
1286
1287
public CompletableFuture <InsertResponse > insert (String tableName , List <?> data , InsertSettings settings ) {
1287
-
1288
1288
if (data == null || data .isEmpty ()) {
1289
1289
throw new IllegalArgumentException ("Data cannot be empty" );
1290
1290
}
@@ -1325,6 +1325,7 @@ public CompletableFuture<InsertResponse> insert(String tableName, List<?> data,
1325
1325
settings .setOption (ClientConfigProperties .INPUT_OUTPUT_FORMAT .getKey (), format .name ());
1326
1326
final InsertSettings finalSettings = settings ;
1327
1327
Supplier <InsertResponse > supplier = () -> {
1328
+ long startTime = System .nanoTime ();
1328
1329
// Selecting some node
1329
1330
ClickHouseNode selectedNode = getNextAliveNode ();
1330
1331
@@ -1355,7 +1356,7 @@ public CompletableFuture<InsertResponse> insert(String tableName, List<?> data,
1355
1356
1356
1357
// Check response
1357
1358
if (httpResponse .getCode () == HttpStatus .SC_SERVICE_UNAVAILABLE ) {
1358
- LOG .warn ("Failed to get response. Server returned {}. Retrying." , httpResponse .getCode ());
1359
+ LOG .warn ("Failed to get response. Server returned {}. Retrying. (Duration: {}) " , httpResponse .getCode (), System . nanoTime () - startTime );
1359
1360
selectedNode = getNextAliveNode ();
1360
1361
continue ;
1361
1362
}
@@ -1369,7 +1370,8 @@ public CompletableFuture<InsertResponse> insert(String tableName, List<?> data,
1369
1370
metrics .setQueryId (queryId );
1370
1371
return new InsertResponse (metrics );
1371
1372
} catch (Exception e ) {
1372
- lastException = httpClientHelper .wrapException ("Query request failed (Attempt " + (i + 1 ) + "/" + (maxRetries + 1 ) + ")" , e );
1373
+ lastException = httpClientHelper .wrapException (String .format ("Query request failed (Attempt: %s/%s - Duration: %s)" ,
1374
+ (i + 1 ), (maxRetries + 1 ), System .nanoTime () - startTime ), e );
1373
1375
if (httpClientHelper .shouldRetry (e , finalSettings .getAllSettings ())) {
1374
1376
LOG .warn ("Retrying." , e );
1375
1377
selectedNode = getNextAliveNode ();
@@ -1378,7 +1380,7 @@ public CompletableFuture<InsertResponse> insert(String tableName, List<?> data,
1378
1380
}
1379
1381
}
1380
1382
}
1381
- throw new ClientException ("Insert request failed after attempts: " + (maxRetries + 1 ), lastException );
1383
+ throw new ClientException ("Insert request failed after attempts: " + (maxRetries + 1 ) + " - Duration: " + ( System . nanoTime () - startTime ) , lastException );
1382
1384
};
1383
1385
1384
1386
return runAsyncOperation (supplier , settings .getAllSettings ());
@@ -1483,6 +1485,7 @@ public CompletableFuture<InsertResponse> insert(String tableName,
1483
1485
final String sqlStmt = "INSERT INTO " + tableName + " FORMAT " + format .name ();
1484
1486
finalSettings .serverSetting (ClickHouseHttpProto .QPARAM_QUERY_STMT , sqlStmt );
1485
1487
responseSupplier = () -> {
1488
+ long startTime = System .nanoTime ();
1486
1489
// Selecting some node
1487
1490
ClickHouseNode selectedNode = getNextAliveNode ();
1488
1491
@@ -1499,7 +1502,7 @@ public CompletableFuture<InsertResponse> insert(String tableName,
1499
1502
1500
1503
// Check response
1501
1504
if (httpResponse .getCode () == HttpStatus .SC_SERVICE_UNAVAILABLE ) {
1502
- LOG .warn ("Failed to get response. Server returned {}. Retrying." , httpResponse .getCode ());
1505
+ LOG .warn ("Failed to get response. Server returned {}. Retrying. (Duration: {})" , System . nanoTime () - startTime , httpResponse .getCode ());
1503
1506
selectedNode = getNextAliveNode ();
1504
1507
continue ;
1505
1508
}
@@ -1512,7 +1515,8 @@ public CompletableFuture<InsertResponse> insert(String tableName,
1512
1515
metrics .setQueryId (queryId );
1513
1516
return new InsertResponse (metrics );
1514
1517
} catch (Exception e ) {
1515
- lastException = httpClientHelper .wrapException ("Query request failed (Attempt " + (i + 1 ) + "/" + (maxRetries + 1 ) + ")" , e );
1518
+ lastException = httpClientHelper .wrapException (String .format ("Insert failed (Attempt: %s/%s - Duration: %s)" ,
1519
+ (i + 1 ), (maxRetries + 1 ), System .nanoTime () - startTime ), e );
1516
1520
if (httpClientHelper .shouldRetry (e , finalSettings .getAllSettings ())) {
1517
1521
LOG .warn ("Retrying." , e );
1518
1522
selectedNode = getNextAliveNode ();
@@ -1529,7 +1533,7 @@ public CompletableFuture<InsertResponse> insert(String tableName,
1529
1533
}
1530
1534
}
1531
1535
}
1532
- throw new ClientException ("Insert request failed after attempts: " + (maxRetries + 1 ), lastException );
1536
+ throw new ClientException ("Insert request failed after attempts: " + (maxRetries + 1 ) + " - Duration: " + ( System . nanoTime () - startTime ) , lastException );
1533
1537
};
1534
1538
1535
1539
return runAsyncOperation (responseSupplier , settings .getAllSettings ());
@@ -1608,6 +1612,7 @@ public CompletableFuture<QueryResponse> query(String sqlQuery, Map<String, Objec
1608
1612
}
1609
1613
final QuerySettings finalSettings = settings ;
1610
1614
responseSupplier = () -> {
1615
+ long startTime = System .nanoTime ();
1611
1616
// Selecting some node
1612
1617
ClickHouseNode selectedNode = getNextAliveNode ();
1613
1618
RuntimeException lastException = null ;
@@ -1621,7 +1626,7 @@ public CompletableFuture<QueryResponse> query(String sqlQuery, Map<String, Objec
1621
1626
1622
1627
// Check response
1623
1628
if (httpResponse .getCode () == HttpStatus .SC_SERVICE_UNAVAILABLE ) {
1624
- LOG .warn ("Failed to get response. Server returned {}. Retrying." , httpResponse .getCode ());
1629
+ LOG .warn ("Failed to get response. Server returned {}. Retrying. (Duration: {})" , System . nanoTime () - startTime , httpResponse .getCode ());
1625
1630
selectedNode = getNextAliveNode ();
1626
1631
continue ;
1627
1632
}
@@ -1638,7 +1643,8 @@ public CompletableFuture<QueryResponse> query(String sqlQuery, Map<String, Objec
1638
1643
return new QueryResponse (httpResponse , finalSettings .getFormat (), finalSettings , metrics );
1639
1644
1640
1645
} catch (Exception e ) {
1641
- lastException = httpClientHelper .wrapException ("Query request failed (Attempt " + (i + 1 ) + "/" + (maxRetries + 1 ) + ")" , e );
1646
+ lastException = httpClientHelper .wrapException (String .format ("Query request failed (Attempt: %s/%s - Duration: %s)" ,
1647
+ (i + 1 ), (maxRetries + 1 ), System .nanoTime () - startTime ), e );
1642
1648
if (httpClientHelper .shouldRetry (e , finalSettings .getAllSettings ())) {
1643
1649
LOG .warn ("Retrying." , e );
1644
1650
selectedNode = getNextAliveNode ();
@@ -1648,7 +1654,7 @@ public CompletableFuture<QueryResponse> query(String sqlQuery, Map<String, Objec
1648
1654
}
1649
1655
}
1650
1656
1651
- throw new ClientException ("Query request failed after attempts: " + (maxRetries + 1 ), lastException );
1657
+ throw new ClientException ("Query request failed after attempts: " + (maxRetries + 1 ) + " - Duration: " + ( System . nanoTime () - startTime ) , lastException );
1652
1658
};
1653
1659
1654
1660
return runAsyncOperation (responseSupplier , settings .getAllSettings ());
0 commit comments