-
Notifications
You must be signed in to change notification settings - Fork 592
Polish excpetion api + build in code list that is retryable #2453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
client-v2/src/main/java/com/clickhouse/client/api/exception/ClientException.java
Outdated
Show resolved
Hide resolved
client-v2/src/main/java/com/clickhouse/client/api/exception/Utils.java
Outdated
Show resolved
Hide resolved
client-v2/src/main/java/com/clickhouse/client/api/exception/ServerException.java
Outdated
Show resolved
Hide resolved
@mzitnik
|
client-v2/src/main/java/com/clickhouse/client/api/exception/Utils.java
Outdated
Show resolved
Hide resolved
client-v2/src/main/java/com/clickhouse/client/api/internal/HttpAPIClientHelper.java
Outdated
Show resolved
Hide resolved
/windsurf-review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other comments (4)
-
client-v2/src/main/java/com/clickhouse/client/api/ServerException.java (48-49)
There's a redundant comment `// UNEXPECTED_END_OF_FILE` in the switch statement that duplicates the first case label. This should be removed to avoid confusion.
//Let's check if we have a ServerException to reference the error code //https://github.com/ClickHouse/ClickHouse/blob/master/src/Common/ErrorCodes.cpp switch (code) {
-
client-v2/src/main/java/com/clickhouse/client/api/ServerException.java (66-66)
There's an unnecessary semicolon after the switch statement's closing brace which should be removed.
return true; }
- client-v2/src/main/java/com/clickhouse/client/api/Client.java (816-816) There's a typo in the documentation: 'ServerRetryable' is mentioned in the comment but this doesn't match the PR title which mentions 'excpetion' (should be 'exception'). Consider fixing the typo in both places for consistency.
- client-v2/src/main/java/com/clickhouse/client/api/ClientConfigProperties.java (123-123) There's a typo in the PR title: 'Polish excpetion api' should be 'Polish exception api'.
💡 To request another review, post a new comment with "/windsurf-review".
@@ -1464,7 +1464,8 @@ public CompletableFuture<InsertResponse> insert(String tableName, | |||
} | |||
} | |||
} | |||
throw new ClientException("Insert request failed after attempts: " + (retries + 1) + " - Duration: " + (System.nanoTime() - startTime), lastException); | |||
LOG.warn("Insert request failed after attempts: " + (retries + 1) + " - Duration: " + (System.nanoTime() - startTime)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The warning log is missing the exception object parameter. Consider adding the lastException
as the last parameter to the LOG.warn()
call to include the stack trace in logs:
LOG.warn("Insert request failed after attempts: " + (retries + 1) + " - Duration: " + (System.nanoTime() - startTime)); | |
LOG.warn("Insert request failed after attempts: " + (retries + 1) + " - Duration: " + (System.nanoTime() - startTime), lastException); |
@@ -1586,8 +1587,8 @@ public CompletableFuture<QueryResponse> query(String sqlQuery, Map<String, Objec | |||
} | |||
} | |||
} | |||
|
|||
throw new ClientException("Query request failed after attempts: " + (retries + 1) + " - Duration: " + (System.nanoTime() - startTime), lastException); | |||
LOG.warn("Query request failed after attempts: " + (retries + 1) + " - Duration: " + (System.nanoTime() - startTime)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The warning log is missing the exception object parameter. Consider adding the lastException
as the last parameter to the LOG.warn()
call to include the stack trace in logs:
LOG.warn("Query request failed after attempts: " + (retries + 1) + " - Duration: " + (System.nanoTime() - startTime)); | |
LOG.warn("Query request failed after attempts: " + (retries + 1) + " - Duration: " + (System.nanoTime() - startTime), lastException); |
super(message); | ||
this.code = code; | ||
this.transportProtocolCode = transportProtocolCode; | ||
this.isRetryable = discoverIsRetryable(code, message, transportProtocolCode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code references this.isRetryable
but there's no field declaration visible in this class. If this is inherited from ClickHouseException
, consider adding a comment to clarify this, or use a more explicit reference to make the code more maintainable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other comments (8)
- client-v2/src/main/java/com/clickhouse/client/api/internal/HttpAPIClientHelper.java (431-432) The catch block for multiple exception types (`ConnectionRequestTimeoutException`, `ServerException`, `NoHttpResponseException`, `ClientException`, `SocketTimeoutException`) has been removed. These exceptions will now propagate as-is rather than being wrapped in `ClientException`. This could break existing error handling code that expects these exceptions to be wrapped.
- client-v2/src/main/java/com/clickhouse/client/api/internal/HttpAPIClientHelper.java (668-670) The `wrapException` method now returns a `DataTransferException` for `SocketTimeoutException` and `IOException`, which is a new exception type. This could break existing error handling code that expects these exceptions to be wrapped in `ClientException`. Ensure all callers are updated to handle this new exception type.
- client-v2/src/main/java/com/clickhouse/client/api/internal/HttpAPIClientHelper.java (671-672) The `wrapException` method now returns a `ClickHouseException` as a fallback instead of `ClientException`. This could break existing error handling code that expects these exceptions to be wrapped in `ClientException`. Ensure all callers are updated to handle this new exception type.
- client-v2/src/main/java/com/clickhouse/client/api/Client.java (816-816) You've added 'ServerRetryable' to the default list of retryable causes, but there's no documentation about what this new cause represents. Consider adding a comment explaining what 'ServerRetryable' means and how it relates to the new exception handling mechanism.
- client-v2/src/main/java/com/clickhouse/client/api/DataTransferException.java (1-1) This new exception class is being created in the `com.clickhouse.client.api` package, but according to the PR description, exception classes are being reorganized into a dedicated `com.clickhouse.client.api.exception` package. For consistency, consider moving this class to the exception package as well.
- client-v2/src/main/java/com/clickhouse/client/api/Client.java (1467-1468) In the insert and query methods, you're now throwing `lastException` directly instead of wrapping it in a ClientException. However, it seems you might want to check if the exception is retryable using the new `isRetryable` utility method mentioned in the PR description before deciding whether to throw it directly or wrap it.
-
client-v2/src/main/java/com/clickhouse/client/api/ClickHouseException.java (4-4)
There's inconsistent spacing in the field declaration. Consider removing the extra space:
protected boolean isRetryable = false;
-
client-v2/src/main/java/com/clickhouse/client/api/ClickHouseException.java (17-17)
The `isRetryable()` method should follow standard Java formatting conventions:
public boolean isRetryable() { return isRetryable; }
💡 To request another review, post a new comment with "/windsurf-review".
@@ -379,7 +372,7 @@ public Exception readError(ClassicHttpResponse httpResponse) { | |||
private AtomicLong timeToPoolVent = new AtomicLong(0); | |||
|
|||
public ClassicHttpResponse executeRequest(Endpoint server, Map<String, Object> requestConfig, LZ4Factory lz4Factory, | |||
IOCallback<OutputStream> writeCallback) throws IOException { | |||
IOCallback<OutputStream> writeCallback) throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method signature has been changed from throwing IOException
to throwing Exception
, which is a more general exception type. This makes the method contract less specific and could lead to unexpected exception handling behavior in calling code. Consider keeping the original exception type or using a more specific exception type.
@@ -432,14 +425,10 @@ | |||
|
|||
} catch (UnknownHostException e) { | |||
LOG.warn("Host '{}' unknown", server.getBaseURL()); | |||
throw new ClientException("Unknown host", e); | |||
throw e; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change removes the wrapping of UnknownHostException
into ClientException
. Callers might be expecting a ClientException
rather than the original exception. Consider maintaining consistent exception wrapping behavior or updating all callers to handle the new exception type.
} catch (ConnectException | NoRouteToHostException e) { | ||
LOG.warn("Failed to connect to '{}': {}", server.getBaseURL(), e.getMessage()); | ||
throw new ClientException("Failed to connect", e); | ||
} catch (ConnectionRequestTimeoutException | ServerException | NoHttpResponseException | ClientException | SocketTimeoutException e) { | ||
throw e; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change removes the wrapping of ConnectException
and NoRouteToHostException
into ClientException
. This could break existing error handling code that expects these exceptions to be wrapped. Consider maintaining consistent exception wrapping behavior.
|
This pull request refactors the exception handling in the
client-v2
module by reorganizing exception classes into a dedicatedexception
package and introducing a utility method to determine if certain server errors are retryable. Additionally, minor cleanups were made to remove unused imports.Exception Handling Refactor:
Reorganized exception classes into a new
exception
package:ClientException
,ServerException
, andConnectionInitiationException
fromcom.clickhouse.client.api
tocom.clickhouse.client.api.exception
. [1] [2] [3]Enhanced
ServerException
:isRetryable
field and corresponding logic to determine if an exception is retryable based on error codes and transport protocol codes. [1] [2]Utils
class in theexception
package with a static methodisRetryable
to centralize retryability logic.Codebase Cleanup:
Updated imports across the codebase:
ClientException
,ServerException
, andConnectionInitiationException
. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16]Removed unused imports:
BinaryStreamReader
andMapBackedRecord
. [1] [2]## SummaryA few enhancements to the exception mechanism.
Checklist
Delete items not relevant to your PR: