Skip to content

Commit 48a6281

Browse files
authored
Merge pull request #777 from zhicwu/enhance-jdbc
The build failure is irrelevant, merge to release `0.3.2-test3`.
2 parents 30bda80 + 7ddc6e0 commit 48a6281

81 files changed

Lines changed: 2397 additions & 868 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6464
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
6565
run: |
66-
find . -type f -name "log4j.*" -exec rm -fv '{}' \;
66+
find . -type f -name "simplelogger.*" -exec rm -fv '{}' \;
6767
mvn -q --batch-mode --global-toolchains .github/toolchains.xml -Drelease \
6868
-Panalysis verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
6969
continue-on-error: true

.github/workflows/benchmark.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
find . -type f -name "pom.xml" -exec sed -i -e 's|${revision}|${{ steps.version.outputs.value }}|g' \
5757
-e 's|^\( <version>\).*\(</version>\)$|\1${{ steps.version.outputs.value }}\2|' \
5858
-e 's|${parent.groupId}|com.clickhouse|g' '{}' \;
59-
find . -type f -name "log4j.*" -exec rm -fv '{}' \;
59+
find . -type f -name "simplelogger.*" -exec rm -fv '{}' \;
6060
- name: Build project
6161
run: |
6262
mvn --batch-mode --update-snapshots -q -DskipTests install
@@ -100,7 +100,7 @@ jobs:
100100
find . -type f -name "pom.xml" -exec sed -i -e 's|${revision}|${{ github.event.inputs.driver }}|g' \
101101
-e 's|^\( <version>\).*\(</version>\)$|\1${{ github.event.inputs.driver }}\2|' \
102102
-e 's|${parent.groupId}|com.clickhouse|g' -e 's|${project.parent.groupId}|com.clickhouse|g' '{}' \;
103-
find . -type f -name "log4j.*" -exec rm -fv '{}' \;
103+
find . -type f -name "simplelogger.*" -exec rm -fv '{}' \;
104104
continue-on-error: true
105105
- name: Install driver as needed
106106
run: mvn --batch-mode --update-snapshots -q -DskipTests install

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
find . -type f -name "pom.xml" -exec sed -i -e 's|${revision}|${{ github.event.inputs.version }}|g' \
5050
-e 's|^\( <version>\).*\(</version>\)$|\1${{ github.event.inputs.version }}\2|' \
5151
-e 's|${parent.groupId}|com.clickhouse|g' -e 's|${project.parent.groupId}|com.clickhouse|g' '{}' \;
52-
find . -type f -name "log4j.*" -exec rm -fv '{}' \;
52+
find . -type f -name "simplelogger.*" -exec rm -fv '{}' \;
5353
- name: Release Maven package
5454
uses: samuelmeuli/action-maven-publish@v1
5555
with:

.github/workflows/third_party_libs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
find . -type f -name "pom.xml" -exec sed -i -e 's|${revision}|${{ github.event.inputs.version }}|g' \
2626
-e 's|^\( <version>\).*\(</version>\)$|\1${{ github.event.inputs.version }}\2|' \
2727
-e 's|${parent.groupId}|com.clickhouse|g' -e 's|${project.parent.groupId}|com.clickhouse|g' '{}' \;
28-
find . -type f -name "log4j.*" -exec rm -fv '{}' \;
28+
find . -type f -name "simplelogger.*" -exec rm -fv '{}' \;
2929
- name: Release Maven package
3030
uses: samuelmeuli/action-maven-publish@v1
3131
with:

clickhouse-benchmark/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<properties>
1919
<clickhouse4j-driver.version>1.4.4</clickhouse4j-driver.version>
20-
<native-driver.version>2.6.1</native-driver.version>
20+
<native-driver.version>2.6.3</native-driver.version>
2121
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2222
<jmh.version>1.33</jmh.version>
2323
<shade.name>benchmarks</shade.name>

clickhouse-benchmark/src/main/java/com/clickhouse/benchmark/jdbc/JdbcDriver.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ public enum JdbcDriver {
88
"jdbc:clickhouse://%s:%s/%s?ssl=false&user=%s&password=%s&use_server_time_zone=false&use_time_zone=UTC&compress=%s",
99
Constants.HTTP_PORT),
1010
// ClickHouse JDBC Driver
11-
ClickhouseHttpJdbc("com.clickhouse.jdbc.ClickHouseDriver",
12-
"jdbc:ch://%s:%s/%s?ssl=false&user=%s&password=%s&use_server_time_zone=false&use_time_zone=UTC&compress=%s",
11+
ClickhouseHttpJdbc1("com.clickhouse.jdbc.ClickHouseDriver",
12+
"jdbc:ch://%s:%s/%s?http_connection_provider=HTTP_URL_CONNECTION&ssl=false&user=%s&password=%s&use_server_time_zone=false&use_time_zone=UTC&compress=%s",
13+
Constants.HTTP_PORT),
14+
ClickhouseHttpJdbc2("com.clickhouse.jdbc.ClickHouseDriver",
15+
"jdbc:ch://%s:%s/%s?http_connection_provider=HTTP_CLIENT&ssl=false&user=%s&password=%s&use_server_time_zone=false&use_time_zone=UTC&compress=%s",
1316
Constants.HTTP_PORT),
1417
ClickhouseGrpcJdbc("com.clickhouse.jdbc.ClickHouseDriver",
1518
"jdbc:ch:grpc://%s:%s/%s?ssl=false&user=%s&password=%s&use_server_time_zone=false&use_time_zone=UTC&max_inbound_message_size=2147483647&compress=%s",

clickhouse-benchmark/src/main/java/com/clickhouse/benchmark/misc/FactoryBenchmark.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.openjdk.jmh.annotations.Warmup;
2929
import org.openjdk.jmh.infra.Blackhole;
3030
import com.clickhouse.benchmark.BaseState;
31+
import com.clickhouse.client.ClickHouseEnum;
3132
import com.clickhouse.client.ClickHouseValue;
3233
import com.clickhouse.client.data.ClickHouseBigDecimalValue;
3334
import com.clickhouse.client.data.ClickHouseBigIntegerValue;
@@ -82,7 +83,7 @@ public void setupSamples() {
8283
add(map, list, Double.class, () -> ClickHouseDoubleValue.ofNull());
8384
add(map, list, BigInteger.class, () -> ClickHouseBigIntegerValue.ofNull());
8485
add(map, list, BigDecimal.class, () -> ClickHouseBigDecimalValue.ofNull());
85-
add(map, list, Enum.class, () -> ClickHouseEnumValue.ofNull());
86+
add(map, list, Enum.class, () -> ClickHouseEnumValue.ofNull(ClickHouseEnum.EMPTY));
8687
add(map, list, Inet4Address.class, () -> ClickHouseIpv4Value.ofNull());
8788
add(map, list, Inet6Address.class, () -> ClickHouseIpv6Value.ofNull());
8889

@@ -121,7 +122,7 @@ ClickHouseValue newValue(Class<?> clazz) {
121122
} else if (BigDecimal.class.equals(clazz)) {
122123
return ClickHouseBigDecimalValue.ofNull();
123124
} else if (Enum.class.equals(clazz)) {
124-
return ClickHouseEnumValue.ofNull();
125+
return ClickHouseEnumValue.ofNull(ClickHouseEnum.EMPTY);
125126
} else if (Inet4Address.class.equals(clazz)) {
126127
return ClickHouseIpv4Value.ofNull();
127128
} else if (Inet6Address.class.equals(clazz)) {

clickhouse-client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
<dependency>
5858
<groupId>org.slf4j</groupId>
59-
<artifactId>slf4j-log4j12</artifactId>
59+
<artifactId>slf4j-simple</artifactId>
6060
<scope>test</scope>
6161
</dependency>
6262
<dependency>

clickhouse-client/src/main/java/com/clickhouse/client/AbstractClient.java

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,8 @@ public void init(ClickHouseConfig config) {
170170
this.config = config;
171171
if (this.executor == null) { // only initialize once
172172
int threads = config.getMaxThreadsPerClient();
173-
this.executor = threads <= 0 ? ClickHouseClient.getExecutorService()
174-
: ClickHouseUtils.newThreadPool(getClass().getSimpleName(), threads,
175-
config.getMaxQueuedRequests());
173+
this.executor = threads < 1 ? ClickHouseClient.getExecutorService()
174+
: ClickHouseUtils.newThreadPool(this, threads, config.getMaxQueuedRequests());
176175
}
177176

178177
initialized = true;
@@ -196,27 +195,16 @@ public final void close() {
196195
try {
197196
server = null;
198197

199-
if (executor != null) {
200-
executor.shutdown();
201-
}
202-
203198
if (connection != null) {
204199
closeConnection(connection, false);
200+
connection = null;
205201
}
206202

207-
// shutdown* won't shutdown commonPool, so awaitTermination will always time out
208-
// on the other hand, for a client-specific thread pool, we'd better shut it
209-
// down for real
210-
if (executor != null && config.getMaxThreadsPerClient() > 0
211-
&& !executor.awaitTermination(config.getConnectionTimeout(), TimeUnit.MILLISECONDS)) {
212-
executor.shutdownNow();
203+
// avoid shutting down shared thread pool
204+
if (executor != null && config.getMaxThreadsPerClient() > 0 && !executor.isTerminated()) {
205+
executor.shutdown();
213206
}
214-
215207
executor = null;
216-
connection = null;
217-
} catch (InterruptedException e) {
218-
log.warn("Got interrupted when closing client", e);
219-
Thread.currentThread().interrupt();
220208
} catch (Exception e) {
221209
log.warn("Exception occurred when closing client", e);
222210
} finally {
@@ -226,7 +214,7 @@ public final void close() {
226214
closeConnection(connection, true);
227215
}
228216

229-
if (executor != null) {
217+
if (executor != null && config.getMaxThreadsPerClient() > 0) {
230218
executor.shutdownNow();
231219
}
232220
} finally {

clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseClientBuilder.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.util.Objects;
77
import java.util.ServiceLoader;
88
import java.util.concurrent.ExecutorService;
9-
import java.util.concurrent.ForkJoinPool;
109

1110
import com.clickhouse.client.config.ClickHouseOption;
1211
import com.clickhouse.client.config.ClickHouseDefaults;
@@ -23,23 +22,17 @@ public class ClickHouseClientBuilder {
2322
static {
2423
int maxThreads = (int) ClickHouseDefaults.MAX_THREADS.getEffectiveDefaultValue();
2524
int maxRequests = (int) ClickHouseDefaults.MAX_REQUESTS.getEffectiveDefaultValue();
25+
long keepAliveTimeoutMs = (long) ClickHouseDefaults.THREAD_KEEPALIVE_TIMEOUT.getEffectiveDefaultValue();
2626

27-
if (maxThreads <= 0 && maxRequests <= 0) {
28-
// java -XX:+UnlockDiagnosticVMOptions -XX:NativeMemoryTracking=summary
29-
// -XX:+PrintNMTStatistics -version
30-
defaultExecutor = ForkJoinPool.commonPool();
31-
} else {
32-
if (maxThreads <= 0) {
33-
maxThreads = Runtime.getRuntime().availableProcessors();
34-
}
35-
36-
if (maxRequests <= 0) {
37-
maxRequests = 0;
38-
}
39-
40-
defaultExecutor = ClickHouseUtils.newThreadPool(ClickHouseClient.class.getSimpleName(), maxThreads,
41-
maxRequests);
27+
if (maxThreads <= 0) {
28+
maxThreads = Runtime.getRuntime().availableProcessors();
29+
}
30+
if (maxRequests <= 0) {
31+
maxRequests = 0;
4232
}
33+
34+
defaultExecutor = ClickHouseUtils.newThreadPool(ClickHouseClient.class.getSimpleName(), maxThreads,
35+
maxThreads * 2, maxRequests, keepAliveTimeoutMs, false);
4336
}
4437

4538
protected ClickHouseConfig config;

0 commit comments

Comments
 (0)