Skip to content

Commit afd15ee

Browse files
authored
Merge pull request #1278 from zhicwu/main
Fix transaction failure since 0.4.0 and enable more tests
2 parents 480c091 + 533c660 commit afd15ee

File tree

16 files changed

+405
-171
lines changed

16 files changed

+405
-171
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ jobs:
176176
matrix:
177177
# most recent LTS releases as well as latest stable builds
178178
# https://github.com/ClickHouse/ClickHouse/pulls?q=is%3Aopen+is%3Apr+label%3Arelease
179-
clickhouse: ["21.8", "22.3", "22.8", "latest"]
179+
clickhouse: ["22.3", "22.8", "latest"]
180180
fail-fast: false
181181
timeout-minutes: 15
182182
name: Java client + CH ${{ matrix.clickhouse }}
@@ -231,12 +231,9 @@ jobs:
231231
needs: compile
232232
strategy:
233233
matrix:
234-
clickhouse: ["21.8", "22.3", "22.8", "latest"]
234+
clickhouse: ["22.3", "22.8", "latest"]
235235
# here http, http_client and apache_http_client represent different value of http_connection_provider
236236
protocol: ["http", "http_client", "apache_http_client", "grpc"]
237-
exclude:
238-
- clickhouse: "21.8"
239-
protocol: grpc
240237
fail-fast: false
241238
timeout-minutes: 15
242239
name: JDBC driver + CH ${{ matrix.clickhouse }} (${{ matrix.protocol }})
@@ -293,7 +290,7 @@ jobs:
293290
needs: compile
294291
strategy:
295292
matrix:
296-
clickhouse: ["21.8", "22.3", "22.8", "latest"]
293+
clickhouse: ["22.3", "22.8", "latest"]
297294
# grpc is not fully supported, and http_client and apache_http_client do not work in CI environment(due to limited threads?)
298295
protocol: ["http"]
299296
r2dbc: ["1.0.0.RELEASE", "0.9.1.RELEASE"]

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### Bug Fixes
44
* error while converting Nested values to Java maps.
55
* incorrect algorithm extracted from PEM. [#1274](https://github.com/ClickHouse/clickhouse-java/issues/1274)
6+
* transaction failure introduced 0.4.0.
67

78
## 0.4.1, 2023-02-19
89
### Breaking Changes

clickhouse-cli-client/src/test/java/com/clickhouse/client/cli/ClickHouseCommandLineClientTest.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,52 @@ public void testSessionLock() {
135135
public void testTempTable() {
136136
throw new SkipException("Skip due to session is not supported");
137137
}
138+
139+
@Test(groups = { "integration" })
140+
@Override
141+
public void testAbortTransaction() throws ClickHouseException {
142+
throw new SkipException("Skip due to session is not supported");
143+
}
144+
145+
@Test(groups = { "integration" })
146+
@Override
147+
public void testCommitTransaction() throws ClickHouseException {
148+
throw new SkipException("Skip due to session is not supported");
149+
}
150+
151+
@Test(groups = { "integration" })
152+
@Override
153+
public void testImplicitTransaction() throws ClickHouseException {
154+
throw new SkipException("Skip due to session is not supported");
155+
}
156+
157+
@Test(groups = { "integration" })
158+
@Override
159+
public void testJoinTransaction() throws ClickHouseException {
160+
throw new SkipException("Skip due to session is not supported");
161+
}
162+
163+
@Test(groups = { "integration" })
164+
@Override
165+
public void testNewTransaction() throws ClickHouseException {
166+
throw new SkipException("Skip due to session is not supported");
167+
}
168+
169+
@Test(groups = { "integration" })
170+
@Override
171+
public void testRollbackTransaction() throws ClickHouseException {
172+
throw new SkipException("Skip due to session is not supported");
173+
}
174+
175+
@Test(groups = { "integration" })
176+
@Override
177+
public void testTransactionSnapshot() throws ClickHouseException {
178+
throw new SkipException("Skip due to session is not supported");
179+
}
180+
181+
@Test(groups = { "integration" })
182+
@Override
183+
public void testTransactionTimeout() throws ClickHouseException {
184+
throw new SkipException("Skip due to session is not supported");
185+
}
138186
}

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

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.clickhouse.client;
22

33
import java.io.IOException;
4+
import java.io.Serializable;
45
import java.util.Collection;
6+
import java.util.Map;
57
import java.util.concurrent.CompletableFuture;
68
import java.util.concurrent.CompletionException;
79
import java.util.concurrent.ExecutorService;
@@ -11,6 +13,7 @@
1113

1214
import com.clickhouse.client.config.ClickHouseClientOption;
1315
import com.clickhouse.client.config.ClickHouseHealthCheckMethod;
16+
import com.clickhouse.config.ClickHouseOption;
1417
import com.clickhouse.data.ClickHouseChecker;
1518
import com.clickhouse.data.ClickHouseUtils;
1619
import com.clickhouse.logging.Logger;
@@ -212,33 +215,12 @@ public boolean accept(ClickHouseProtocol protocol) {
212215
}
213216

214217
@Override
215-
public ClickHouseRequest<?> connect(ClickHouseNode node) {
218+
public ClickHouseRequest<?> read(Function<ClickHouseNodeSelector, ClickHouseNode> nodeFunc,
219+
Map<ClickHouseOption, Serializable> options) {
216220
lock.readLock().lock();
217221
try {
218222
ensureInitialized();
219-
return ClickHouseClient.super.connect(node);
220-
} finally {
221-
lock.readLock().unlock();
222-
}
223-
}
224-
225-
@Override
226-
public ClickHouseRequest<?> connect(ClickHouseNodes nodes) {
227-
lock.readLock().lock();
228-
try {
229-
ensureInitialized();
230-
return ClickHouseClient.super.connect(nodes);
231-
} finally {
232-
lock.readLock().unlock();
233-
}
234-
}
235-
236-
@Override
237-
public ClickHouseRequest<?> connect(Function<ClickHouseNodeSelector, ClickHouseNode> nodeFunc) {
238-
lock.readLock().lock();
239-
try {
240-
ensureInitialized();
241-
return ClickHouseClient.super.connect(nodeFunc);
223+
return ClickHouseClient.super.read(nodeFunc, options);
242224
} finally {
243225
lock.readLock().unlock();
244226
}

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

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.IOException;
44
import java.io.InputStream;
55
import java.io.OutputStream;
6+
import java.io.Serializable;
67
import java.io.UncheckedIOException;
78
import java.util.ArrayList;
89
import java.util.List;
@@ -658,11 +659,13 @@ static ClickHouseClient newInstance(ClickHouseProtocol... preferredProtocols) {
658659
}
659660

660661
/**
661-
* Creates a new instance with default credentials compatible with any of the given protocols.
662+
* Creates a new instance with default credentials compatible with any of the
663+
* given protocols.
662664
*
663665
* @param defaultCredentials default credentials
664666
* @param preferredProtocols preferred protocols
665-
* @return new instance compatible with any of the given protocols using default credentials
667+
* @return new instance compatible with any of the given protocols using default
668+
* credentials
666669
*/
667670
static ClickHouseClient newInstance(ClickHouseCredentials defaultCredentials,
668671
ClickHouseProtocol... preferredProtocols) {
@@ -946,7 +949,29 @@ default ClickHouseRequest<?> connect(ClickHouseNode node) {
946949
}
947950

948951
/**
949-
* Reads from one or more ClickHouse servers. Same as
952+
* Connects to a ClickHouse server defined by the given
953+
* {@link java.util.function.Function}. You can pass either
954+
* {@link ClickHouseCluster}, {@link ClickHouseNodes} or {@link ClickHouseNode}
955+
* here, as all of them implemented the same interface.
956+
*
957+
* <p>
958+
* Please be aware that this is nothing but an intention, so no network
959+
* communication happens until {@link #execute(ClickHouseRequest)} is
960+
* invoked(usually triggered by {@code request.execute()}).
961+
*
962+
* @param nodeFunc function to get a {@link ClickHouseNode} to connect to
963+
* @return non-null request object holding references to this client and node
964+
* provider
965+
* @deprecated will be dropped in 0.5, please use {@link #read(Function, Map)}
966+
* instead
967+
*/
968+
@Deprecated
969+
default ClickHouseRequest<?> connect(Function<ClickHouseNodeSelector, ClickHouseNode> nodeFunc) {
970+
return read(nodeFunc, null);
971+
}
972+
973+
/**
974+
* Connects to one or more ClickHouse servers to read. Same as
950975
* {@code read(ClickHouseNodes.of(uri))}.
951976
*
952977
* @param endpoints non-empty connection string separated by comma
@@ -958,55 +983,46 @@ default ClickHouseRequest<?> read(String endpoints) {
958983
}
959984

960985
/**
961-
* Reads from a list of managed ClickHouse servers.
986+
* Connects to a list of managed ClickHouse servers to read.
962987
*
963988
* @param nodes non-null list of servers for read
964989
* @return non-null request object holding references to this client and node
965990
* provider
966991
*/
967992
default ClickHouseRequest<?> read(ClickHouseNodes nodes) {
968-
return new ClickHouseRequest<>(this, ClickHouseChecker.nonNull(nodes, "Nodes"),
969-
null, nodes.template.config.getAllOptions(), false);
993+
return read(nodes, nodes.template.config.getAllOptions());
970994
}
971995

972996
/**
973-
* Reads from a ClickHouse server.
997+
* Connects to a ClickHouse server to read.
974998
*
975999
* @param node non-null server for read
9761000
* @return non-null request object holding references to this client and server
9771001
*/
9781002
default ClickHouseRequest<?> read(ClickHouseNode node) {
979-
return new ClickHouseRequest<>(this, ClickHouseChecker.nonNull(node, "Node"), null, node.config.getAllOptions(),
980-
false);
1003+
return read(node, node.config.getAllOptions());
9811004
}
9821005

9831006
/**
984-
* Writes into a ClickHouse server.
1007+
* Connects to a ClickHouse server to read.
9851008
*
986-
* @param server non-null server for write
1009+
* @param nodeFunc function to get a {@link ClickHouseNode} to connect to
1010+
* @param options optional client options for connecting to the server
9871011
* @return non-null request object holding references to this client and server
9881012
*/
989-
default Mutation write(ClickHouseNode server) {
990-
return read(server).write();
1013+
default ClickHouseRequest<?> read(Function<ClickHouseNodeSelector, ClickHouseNode> nodeFunc,
1014+
Map<ClickHouseOption, Serializable> options) {
1015+
return new ClickHouseRequest<>(this, ClickHouseChecker.nonNull(nodeFunc, "Node"), null, options, false);
9911016
}
9921017

9931018
/**
994-
* Connects to a ClickHouse server defined by the given
995-
* {@link java.util.function.Function}. You can pass either
996-
* {@link ClickHouseCluster}, {@link ClickHouseNodes} or {@link ClickHouseNode}
997-
* here, as all of them implemented the same interface.
998-
*
999-
* <p>
1000-
* Please be aware that this is nothing but an intention, so no network
1001-
* communication happens until {@link #execute(ClickHouseRequest)} is
1002-
* invoked(usually triggered by {@code request.execute()}).
1019+
* Writes into a ClickHouse server.
10031020
*
1004-
* @param nodeFunc function to get a {@link ClickHouseNode} to connect to
1005-
* @return non-null request object holding references to this client and node
1006-
* provider
1021+
* @param node non-null server for write
1022+
* @return non-null request object holding references to this client and server
10071023
*/
1008-
default ClickHouseRequest<?> connect(Function<ClickHouseNodeSelector, ClickHouseNode> nodeFunc) {
1009-
return new ClickHouseRequest<>(this, ClickHouseChecker.nonNull(nodeFunc, "nodeFunc"), null, null, false);
1024+
default Mutation write(ClickHouseNode node) {
1025+
return read(node).write();
10101026
}
10111027

10121028
/**

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.clickhouse.data.ClickHouseFormat;
1313
import com.clickhouse.data.ClickHouseRecord;
1414
import com.clickhouse.data.ClickHouseUtils;
15+
import com.clickhouse.data.value.UnsignedLong;
1516
import com.clickhouse.logging.Logger;
1617
import com.clickhouse.logging.LoggerFactory;
1718

@@ -42,8 +43,8 @@ public static XID of(List<?> list) {
4243
throw new IllegalArgumentException(
4344
"Non-null tuple with 3 elements(long, long, String) is required");
4445
}
45-
long snapshotVersion = (Long) list.get(0);
46-
long localTxCounter = (Long) list.get(1);
46+
long snapshotVersion = ((UnsignedLong) list.get(0)).longValue();
47+
long localTxCounter = ((UnsignedLong) list.get(1)).longValue();
4748
String hostId = String.valueOf(list.get(2));
4849
if (EMPTY.snapshotVersion == snapshotVersion && EMPTY.localTxCounter == localTxCounter
4950
&& EMPTY.hostId.equals(hostId)) {
@@ -278,7 +279,7 @@ protected final ClickHouseRecord issue(String command) throws ClickHouseExceptio
278279
protected ClickHouseRecord issue(String command, boolean sessionCheck, Map<String, Serializable> settings)
279280
throws ClickHouseException {
280281
ClickHouseRecord result = ClickHouseRecord.EMPTY;
281-
try (ClickHouseResponse response = ClickHouseClient.newInstance(server.getProtocol()).connect(server)
282+
try (ClickHouseResponse response = ClickHouseClient.newInstance(server.getProtocol()).read(server)
282283
.format(ClickHouseFormat.RowBinaryWithNamesAndTypes)
283284
.settings(settings).session(sessionId, sessionCheck, timeout > 0 ? timeout : null)
284285
.query(command).executeAndWait()) {

0 commit comments

Comments
 (0)