-
Notifications
You must be signed in to change notification settings - Fork 623
Expand file tree
/
Copy pathServerException.java
More file actions
104 lines (84 loc) · 2.96 KB
/
ServerException.java
File metadata and controls
104 lines (84 loc) · 2.96 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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;
public static final int QUERY_CANCELLED = 394;
private final int code;
private final int transportProtocolCode;
private final String queryId;
public ServerException(int code, String message, int transportProtocolCode, String queryId) {
super(message);
this.code = code;
this.transportProtocolCode = transportProtocolCode;
this.isRetryable = discoverIsRetryable(code, message, transportProtocolCode);
this.queryId = queryId;
}
/**
* 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;
}
@Override
public boolean isRetryable() {
return super.isRetryable();
}
/**
* Returns query ID that is returned by server in {@link com.clickhouse.client.api.http.ClickHouseHttpProto#HEADER_QUERY_ID}
* @return query id non-null string
*/
public String getQueryId() {
return queryId;
}
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;
}
/**
* Not every server code is listed - only most common
*/
public enum ErrorCodes {
UNKNOWN(0),
TABLE_NOT_FOUND(60),
DATABASE_NOT_FOUND(81),
UNKNOWN_SETTING(115),
;
private int code;
ErrorCodes(int code) {
this.code = code;
}
public int getCode() {
return code;
}
}
}