|
15 | 15 | import com.clickhouse.client.api.http.ClickHouseHttpProto; |
16 | 16 | import com.clickhouse.client.api.insert.InsertResponse; |
17 | 17 | import com.clickhouse.client.api.insert.InsertSettings; |
18 | | -import com.clickhouse.client.api.internal.ClickHouseLZ4OutputStream; |
19 | 18 | import com.clickhouse.client.api.internal.ClientStatisticsHolder; |
20 | 19 | import com.clickhouse.client.api.internal.HttpAPIClientHelper; |
21 | 20 | import com.clickhouse.client.api.internal.MapUtils; |
|
80 | 79 | import java.util.function.Supplier; |
81 | 80 | import java.util.stream.Collectors; |
82 | 81 |
|
83 | | -import static java.time.temporal.ChronoUnit.MILLIS; |
84 | | -import static java.time.temporal.ChronoUnit.SECONDS; |
85 | | - |
86 | 82 | /** |
87 | 83 | * <p>Client is the starting point for all interactions with ClickHouse. </p> |
88 | 84 | * |
@@ -141,12 +137,12 @@ public class Client implements AutoCloseable { |
141 | 137 | private int retries; |
142 | 138 | private LZ4Factory lz4Factory = null; |
143 | 139 |
|
144 | | - private Client(Set<String> endpoints, Map<String,String> configuration, boolean useNewImplementation, |
| 140 | + private Client(Set<String> endpoints, Map<String,String> configuration, |
145 | 141 | ExecutorService sharedOperationExecutor, ColumnToMethodMatchingStrategy columnToMethodMatchingStrategy) { |
146 | | - this(endpoints, configuration, useNewImplementation, sharedOperationExecutor, columnToMethodMatchingStrategy, null); |
| 142 | + this(endpoints, configuration, sharedOperationExecutor, columnToMethodMatchingStrategy, null); |
147 | 143 | } |
148 | 144 |
|
149 | | - private Client(Set<String> endpoints, Map<String,String> configuration, boolean useNewImplementation, |
| 145 | + private Client(Set<String> endpoints, Map<String,String> configuration, |
150 | 146 | ExecutorService sharedOperationExecutor, ColumnToMethodMatchingStrategy columnToMethodMatchingStrategy, Object metricsRegistry) { |
151 | 147 | // Simple initialization |
152 | 148 | this.configuration = configuration; |
@@ -256,14 +252,22 @@ public static class Builder { |
256 | 252 |
|
257 | 253 | // Read-only configuration |
258 | 254 | private Map<String, String> configuration; |
259 | | - private boolean useNewImplementation = true; |
260 | 255 |
|
261 | 256 | private ExecutorService sharedOperationExecutor = null; |
262 | 257 | private ColumnToMethodMatchingStrategy columnToMethodMatchingStrategy; |
263 | 258 | private Object metricRegistry = null; |
264 | 259 | public Builder() { |
265 | 260 | this.endpoints = new HashSet<>(); |
266 | | - this.configuration = new HashMap<String, String>(); |
| 261 | + this.configuration = new HashMap<>(); |
| 262 | + |
| 263 | + for (ClientConfigProperties p : ClientConfigProperties.values()) { |
| 264 | + if (p.getDefaultValue() != null) { |
| 265 | + this.configuration.put(p.getKey(), p.getDefaultValue()); |
| 266 | + } |
| 267 | + } |
| 268 | + |
| 269 | + allowBinaryReaderToReuseBuffers(false); |
| 270 | + columnToMethodMatchingStrategy = DefaultColumnToMethodMatchingStrategy.INSTANCE; |
267 | 271 | } |
268 | 272 |
|
269 | 273 | /** |
@@ -510,7 +514,7 @@ public Builder setSocketRcvbuf(long size) { |
510 | 514 | * @param size - socket send buffer size in bytes |
511 | 515 | */ |
512 | 516 | public Builder setSocketSndbuf(long size) { |
513 | | - this.configuration.put(ClientConfigProperties.SOCKET_RCVBUF_OPT.getKey(), String.valueOf(size)); |
| 517 | + this.configuration.put(ClientConfigProperties.SOCKET_SNDBUF_OPT.getKey(), String.valueOf(size)); |
514 | 518 | return this; |
515 | 519 | } |
516 | 520 |
|
@@ -656,25 +660,12 @@ public Builder setExecutionTimeout(long timeout, ChronoUnit timeUnit) { |
656 | 660 | return this; |
657 | 661 | } |
658 | 662 |
|
659 | | - /** |
660 | | - * Switches to new implementation of the client. Default is true. |
661 | | - * Throws exception if {@code useNewImplementation == false} |
662 | | - * @deprecated |
663 | | - */ |
664 | | - public Builder useNewImplementation(boolean useNewImplementation) { |
665 | | - if (!useNewImplementation) { |
666 | | - throw new ClientException("switch between new and old version is remove because old version is deprecated."); |
667 | | - } |
668 | | - return this; |
669 | | - } |
670 | | - |
671 | 663 | public Builder setHttpCookiesEnabled(boolean enabled) { |
672 | 664 | //TODO: extract to settings string constants |
673 | 665 | this.configuration.put("client.http.cookies_enabled", String.valueOf(enabled)); |
674 | 666 | return this; |
675 | 667 | } |
676 | 668 |
|
677 | | - |
678 | 669 | /** |
679 | 670 | * Defines path to the trust store file. It cannot be combined with |
680 | 671 | * certificates. Either trust store or certificates should be used. |
@@ -1013,8 +1004,6 @@ public Builder setServerVersion(String serverVersion) { |
1013 | 1004 | } |
1014 | 1005 |
|
1015 | 1006 | public Client build() { |
1016 | | - setDefaults(); |
1017 | | - |
1018 | 1007 | // check if endpoint are empty. so can not initiate client |
1019 | 1008 | if (this.endpoints.isEmpty()) { |
1020 | 1009 | throw new IllegalArgumentException("At least one endpoint is required"); |
@@ -1070,128 +1059,9 @@ public Client build() { |
1070 | 1059 | throw new IllegalArgumentException("Nor server timezone nor specific timezone is set"); |
1071 | 1060 | } |
1072 | 1061 |
|
1073 | | - return new Client(this.endpoints, this.configuration, this.useNewImplementation, this.sharedOperationExecutor, |
| 1062 | + return new Client(this.endpoints, this.configuration, this.sharedOperationExecutor, |
1074 | 1063 | this.columnToMethodMatchingStrategy, this.metricRegistry); |
1075 | 1064 | } |
1076 | | - |
1077 | | - |
1078 | | - private static final int DEFAULT_NETWORK_BUFFER_SIZE = 300_000; |
1079 | | - |
1080 | | - /** |
1081 | | - * Default size for a buffers used in networking. |
1082 | | - */ |
1083 | | - public static final int DEFAULT_BUFFER_SIZE = 8192; |
1084 | | - public static final int DEFAULT_SOCKET_BUFFER_SIZE = 804800; |
1085 | | - |
1086 | | - private void setDefaults() { |
1087 | | - |
1088 | | - // set default database name if not specified |
1089 | | - if (!configuration.containsKey(ClientConfigProperties.DATABASE.getKey())) { |
1090 | | - setDefaultDatabase((String) "default"); |
1091 | | - } |
1092 | | - |
1093 | | - if (!configuration.containsKey(ClientConfigProperties.MAX_EXECUTION_TIME.getKey())) { |
1094 | | - setExecutionTimeout(0, MILLIS); |
1095 | | - } |
1096 | | - |
1097 | | - if (!configuration.containsKey(ClientConfigProperties.MAX_THREADS_PER_CLIENT.getKey())) { |
1098 | | - configuration.put(ClientConfigProperties.MAX_THREADS_PER_CLIENT.getKey(), |
1099 | | - String.valueOf(0)); |
1100 | | - } |
1101 | | - |
1102 | | - if (!configuration.containsKey("compression.lz4.uncompressed_buffer_size")) { |
1103 | | - setLZ4UncompressedBufferSize(ClickHouseLZ4OutputStream.UNCOMPRESSED_BUFF_SIZE); |
1104 | | - } |
1105 | | - |
1106 | | - if (!configuration.containsKey(ClientConfigProperties.DISABLE_NATIVE_COMPRESSION.getKey())) { |
1107 | | - disableNativeCompression(false); |
1108 | | - } |
1109 | | - |
1110 | | - if (!configuration.containsKey(ClientConfigProperties.USE_SERVER_TIMEZONE.getKey())) { |
1111 | | - useServerTimeZone(true); |
1112 | | - } |
1113 | | - |
1114 | | - if (!configuration.containsKey(ClientConfigProperties.SERVER_TIMEZONE.getKey())) { |
1115 | | - setServerTimeZone("UTC"); |
1116 | | - } |
1117 | | - |
1118 | | - if (!configuration.containsKey(ClientConfigProperties.ASYNC_OPERATIONS.getKey())) { |
1119 | | - useAsyncRequests(false); |
1120 | | - } |
1121 | | - |
1122 | | - if (!configuration.containsKey(ClientConfigProperties.HTTP_MAX_OPEN_CONNECTIONS.getKey())) { |
1123 | | - setMaxConnections(10); |
1124 | | - } |
1125 | | - |
1126 | | - if (!configuration.containsKey(ClientConfigProperties.CONNECTION_REQUEST_TIMEOUT.getKey())) { |
1127 | | - setConnectionRequestTimeout(10, SECONDS); |
1128 | | - } |
1129 | | - |
1130 | | - if (!configuration.containsKey(ClientConfigProperties.CONNECTION_REUSE_STRATEGY.getKey())) { |
1131 | | - setConnectionReuseStrategy(ConnectionReuseStrategy.FIFO); |
1132 | | - } |
1133 | | - |
1134 | | - if (!configuration.containsKey(ClientConfigProperties.CONNECTION_POOL_ENABLED.getKey())) { |
1135 | | - enableConnectionPool(true); |
1136 | | - } |
1137 | | - |
1138 | | - if (!configuration.containsKey(ClientConfigProperties.CONNECTION_TTL.getKey())) { |
1139 | | - setConnectionTTL(-1, MILLIS); |
1140 | | - } |
1141 | | - |
1142 | | - if (!configuration.containsKey(ClientConfigProperties.CLIENT_RETRY_ON_FAILURE.getKey())) { |
1143 | | - retryOnFailures(ClientFaultCause.NoHttpResponse, ClientFaultCause.ConnectTimeout, |
1144 | | - ClientFaultCause.ConnectionRequestTimeout); |
1145 | | - } |
1146 | | - |
1147 | | - if (!configuration.containsKey(ClientConfigProperties.CLIENT_NETWORK_BUFFER_SIZE.getKey())) { |
1148 | | - setClientNetworkBufferSize(DEFAULT_NETWORK_BUFFER_SIZE); |
1149 | | - } |
1150 | | - |
1151 | | - if (!configuration.containsKey(ClientConfigProperties.RETRY_ON_FAILURE.getKey())) { |
1152 | | - setMaxRetries(3); |
1153 | | - } |
1154 | | - |
1155 | | - if (!configuration.containsKey("client_allow_binary_reader_to_reuse_buffers")) { |
1156 | | - allowBinaryReaderToReuseBuffers(false); |
1157 | | - } |
1158 | | - |
1159 | | - if (columnToMethodMatchingStrategy == null) { |
1160 | | - columnToMethodMatchingStrategy = DefaultColumnToMethodMatchingStrategy.INSTANCE; |
1161 | | - } |
1162 | | - |
1163 | | - if (!configuration.containsKey(ClientConfigProperties.HTTP_USE_BASIC_AUTH.getKey())) { |
1164 | | - useHTTPBasicAuth(true); |
1165 | | - } |
1166 | | - |
1167 | | - if (!configuration.containsKey(ClientConfigProperties.COMPRESS_CLIENT_REQUEST.getKey())) { |
1168 | | - compressClientRequest(false); |
1169 | | - } |
1170 | | - |
1171 | | - if (!configuration.containsKey(ClientConfigProperties.COMPRESS_SERVER_RESPONSE.getKey())) { |
1172 | | - compressServerResponse(true); |
1173 | | - } |
1174 | | - |
1175 | | - if (!configuration.containsKey(ClientConfigProperties.USE_HTTP_COMPRESSION.getKey())) { |
1176 | | - useHttpCompression(false); |
1177 | | - } |
1178 | | - |
1179 | | - if (!configuration.containsKey(ClientConfigProperties.APP_COMPRESSED_DATA.getKey())) { |
1180 | | - appCompressedData(false); |
1181 | | - } |
1182 | | - |
1183 | | - if (!configuration.containsKey(ClientConfigProperties.SOCKET_OPERATION_TIMEOUT.getKey())) { |
1184 | | - setSocketTimeout(0, SECONDS); |
1185 | | - } |
1186 | | - |
1187 | | - if (!configuration.containsKey(ClientConfigProperties.SOCKET_RCVBUF_OPT.getKey())) { |
1188 | | - setSocketRcvbuf(DEFAULT_SOCKET_BUFFER_SIZE); |
1189 | | - } |
1190 | | - |
1191 | | - if (!configuration.containsKey(ClientConfigProperties.SOCKET_SNDBUF_OPT.getKey())) { |
1192 | | - setSocketSndbuf(DEFAULT_SOCKET_BUFFER_SIZE); |
1193 | | - } |
1194 | | - } |
1195 | 1065 | } |
1196 | 1066 |
|
1197 | 1067 | /** |
|
0 commit comments