Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
### 0.9.4
## 0.9.5

### New Features
- [client-v2] Log durations in ISO-8601 duration format

## 0.9.4

### New Features
- [client-v2] Added support for different compression algorithms when HTTP compression is enabled. (https://github.com/ClickHouse/clickhouse-java/pull/2645)
Expand Down
23 changes: 13 additions & 10 deletions client-v2/src/main/java/com/clickhouse/client/api/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ public boolean ping(long timeout) {
return true;
}
} catch (Exception e) {
LOG.debug("Failed to connect to the server (Duration: {})", System.nanoTime() - startTime, e);
LOG.debug("Failed to connect to the server (Duration: {})", durationSince(startTime), e);
return false;
}
}
Expand Down Expand Up @@ -1277,7 +1277,7 @@ public CompletableFuture<InsertResponse> insert(String tableName, List<?> data,

// Check response
if (httpResponse.getCode() == HttpStatus.SC_SERVICE_UNAVAILABLE) {
LOG.warn("Failed to get response. Server returned {}. Retrying. (Duration: {})", httpResponse.getCode(), System.nanoTime() - startTime);
LOG.warn("Failed to get response. Server returned {}. Retrying. (Duration: {})", httpResponse.getCode(), durationSince(startTime));
selectedEndpoint = getNextAliveNode();
continue;
}
Expand All @@ -1292,7 +1292,7 @@ public CompletableFuture<InsertResponse> insert(String tableName, List<?> data,
return new InsertResponse(metrics);
} catch (Exception e) {
lastException = httpClientHelper.wrapException(String.format("Query request failed (Attempt: %s/%s - Duration: %s)",
(i + 1), (maxRetries + 1), System.nanoTime() - startTime), e);
(i + 1), (maxRetries + 1), durationSince(startTime)), e);
if (httpClientHelper.shouldRetry(e, requestSettings.getAllSettings())) {
LOG.warn("Retrying.", e);
selectedEndpoint = getNextAliveNode();
Expand All @@ -1301,7 +1301,7 @@ public CompletableFuture<InsertResponse> insert(String tableName, List<?> data,
}
}
}
throw new ClientException("Insert request failed after attempts: " + (maxRetries + 1) + " - Duration: " + (System.nanoTime() - startTime), lastException);
throw new ClientException("Insert request failed after attempts: " + (maxRetries + 1) + " - Duration: " + durationSince(startTime), lastException);
};

return runAsyncOperation(supplier, requestSettings.getAllSettings());
Expand Down Expand Up @@ -1480,7 +1480,7 @@ public CompletableFuture<InsertResponse> insert(String tableName,

// Check response
if (httpResponse.getCode() == HttpStatus.SC_SERVICE_UNAVAILABLE) {
LOG.warn("Failed to get response. Server returned {}. Retrying. (Duration: {})", System.nanoTime() - startTime, httpResponse.getCode());
LOG.warn("Failed to get response. Server returned {}. Retrying. (Duration: {})", httpResponse.getCode(), durationSince(startTime));
selectedEndpoint = getNextAliveNode();
continue;
}
Expand All @@ -1494,7 +1494,7 @@ public CompletableFuture<InsertResponse> insert(String tableName,
return new InsertResponse(metrics);
} catch (Exception e) {
lastException = httpClientHelper.wrapException(String.format("Insert failed (Attempt: %s/%s - Duration: %s)",
(i + 1), (retries + 1), System.nanoTime() - startTime), e);
(i + 1), (retries + 1), durationSince(startTime)), e);
if (httpClientHelper.shouldRetry(e, requestSettings.getAllSettings())) {
LOG.warn("Retrying.", e);
selectedEndpoint = getNextAliveNode();
Expand All @@ -1511,7 +1511,7 @@ public CompletableFuture<InsertResponse> insert(String tableName,
}
}
}
LOG.warn("Insert request failed after attempts: " + (retries + 1) + " - Duration: " + (System.nanoTime() - startTime));
LOG.warn("Insert request failed after attempts: {} - Duration: {}", retries + 1, durationSince(startTime));
throw (lastException == null ? new ClientException("Failed to complete insert operation") : lastException);
};

Expand Down Expand Up @@ -1603,7 +1603,7 @@ public CompletableFuture<QueryResponse> query(String sqlQuery, Map<String, Objec

// Check response
if (httpResponse.getCode() == HttpStatus.SC_SERVICE_UNAVAILABLE) {
LOG.warn("Failed to get response. Server returned {}. Retrying. (Duration: {})", System.nanoTime() - startTime, httpResponse.getCode());
LOG.warn("Failed to get response. Server returned {}. Retrying. (Duration: {})", httpResponse.getCode(), durationSince(startTime));
selectedEndpoint = getNextAliveNode();
HttpAPIClientHelper.closeQuietly(httpResponse);
continue;
Expand All @@ -1628,7 +1628,7 @@ public CompletableFuture<QueryResponse> query(String sqlQuery, Map<String, Objec
} catch (Exception e) {
HttpAPIClientHelper.closeQuietly(httpResponse);
lastException = httpClientHelper.wrapException(String.format("Query request failed (Attempt: %s/%s - Duration: %s)",
(i + 1), (retries + 1), System.nanoTime() - startTime), e);
(i + 1), (retries + 1), durationSince(startTime)), e);
if (httpClientHelper.shouldRetry(e, requestSettings.getAllSettings())) {
LOG.warn("Retrying.", e);
selectedEndpoint = getNextAliveNode();
Expand All @@ -1637,7 +1637,7 @@ public CompletableFuture<QueryResponse> query(String sqlQuery, Map<String, Objec
}
}
}
LOG.warn("Query request failed after attempts: " + (retries + 1) + " - Duration: " + (System.nanoTime() - startTime));
LOG.warn("Query request failed after attempts: {} - Duration: {}", retries + 1, durationSince(startTime));
throw (lastException == null ? new ClientException("Failed to complete query") : lastException);
};

Expand Down Expand Up @@ -2115,4 +2115,7 @@ private Map<String, Object> buildRequestSettings(Map<String, Object> opSettings)
return requestSettings;
}

private Duration durationSince(long sinceNanos) {
return Duration.ofNanos(System.nanoTime() - sinceNanos);
}
}
Loading