-
Notifications
You must be signed in to change notification settings - Fork 623
Expand file tree
/
Copy pathServerException.java
More file actions
71 lines (59 loc) · 2.27 KB
/
ServerException.java
File metadata and controls
71 lines (59 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.clickhouse.client.api;
public class ServerException extends ClickHouseException {
public static final int CODE_UNKNOWN = 0;
public static final int TABLE_NOT_FOUND = 60;
public static final int UNKNOWN_SETTING = 115;
private final int code;
private final int transportProtocolCode;
public ServerException(int code, String message) {
this(code, message, 500);
}
public ServerException(int code, String message, int transportProtocolCode) {
super(message);
this.code = code;
this.transportProtocolCode = transportProtocolCode;
this.isRetryable = discoverIsRetryable(code, message, transportProtocolCode);
}
/**
* Returns CH server error code. May return 0 if code is unknown.
* @return - error code from server response
*/
public int getCode() {
return code;
}
/**
* Returns error code of underlying transport protocol. For example, HTTP status.
* By default, will return {@code 500 } what is derived from HTTP Server Internal Error.
*
* @return - transport status code
*/
public int getTransportProtocolCode() {
return transportProtocolCode;
}
public boolean isRetryable() {
return isRetryable;
}
private boolean discoverIsRetryable(int code, String message, int transportProtocolCode) {
//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) { // UNEXPECTED_END_OF_FILE
case 3: // UNEXPECTED_END_OF_FILE
case 107: // FILE_DOESNT_EXIST
case 159: // TIMEOUT_EXCEEDED
case 164: // READONLY
case 202: // TOO_MANY_SIMULTANEOUS_QUERIES
case 203: // NO_FREE_CONNECTION
case 209: // SOCKET_TIMEOUT
case 210: // NETWORK_ERROR
case 241: // MEMORY_LIMIT_EXCEEDED
case 242: // TABLE_IS_READ_ONLY
case 252: // TOO_MANY_PARTS
case 285: // TOO_FEW_LIVE_REPLICAS
case 319: // UNKNOWN_STATUS_OF_INSERT
case 425: // SYSTEM_ERROR
case 999: // KEEPER_EXCEPTION
return true;
};
return false;
}
}