Skip to content

Commit ec5380b

Browse files
authored
Remove the test of Local transactions for ClickHouse integration module in nativeTest (#34530)
1 parent ba0d5f7 commit ec5380b

File tree

22 files changed

+158
-591
lines changed

22 files changed

+158
-591
lines changed

docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.cn.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,11 @@ Reachability Metadata 位于 `shardingsphere-infra-reachability-metadata` 子模
389389
```bash
390390
git clone [email protected]:apache/shardingsphere.git
391391
cd ./shardingsphere/
392-
./mvnw -PgenerateMetadata -DskipNativeTests -e -T 1C clean test native:metadata-copy
392+
./mvnw -PgenerateMetadata -e -T 1C clean test native:metadata-copy
393393
```
394394

395395
受 https://github.com/apache/shardingsphere/issues/33206 影响,
396-
贡献者执行 `./mvnw -PgenerateMetadata -DskipNativeTests -T 1C -e clean test native:metadata-copy` 后,
396+
贡献者执行 `./mvnw -PgenerateMetadata -T 1C -e clean test native:metadata-copy` 后,
397397
`infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/resource-config.json` 会生成不必要的包含绝对路径的 JSON 条目,
398398
类似如下,
399399

docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.en.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,11 +405,11 @@ contributors should place it on the classpath of the `shardingsphere-test-native
405405
```bash
406406
git clone [email protected]:apache/shardingsphere.git
407407
cd ./shardingsphere/
408-
./mvnw -PgenerateMetadata -DskipNativeTests -e -T 1C clean test native:metadata-copy
408+
./mvnw -PgenerateMetadata -e -T 1C clean test native:metadata-copy
409409
```
410410

411411
Affected by https://github.com/apache/shardingsphere/issues/33206 ,
412-
After the contributor executes `./mvnw -PgenerateMetadata -DskipNativeTests -T 1C -e clean test native:metadata-copy`,
412+
After the contributor executes `./mvnw -PgenerateMetadata -T 1C -e clean test native:metadata-copy`,
413413
`infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/resource-config.json` will generate unnecessary JSON entries containing absolute paths,
414414
similar to the following.
415415

docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/clickhouse/_index.cn.md

Lines changed: 4 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -213,182 +213,12 @@ public class ExampleTest {
213213

214214
### 事务限制
215215

216-
ClickHouse 不支持 ShardingSphere 集成级别的 XA 事务,
217-
因为 https://github.com/ClickHouse/clickhouse-java 未实现 `javax.sql.XADataSource` 的相关 Java 接口。
218-
219-
ClickHouse 不支持 ShardingSphere 集成级别的 Seata AT 模式事务,
220-
因为 https://github.com/apache/incubator-seata 未实现 ClickHouse 的 SQL 方言解析。
221-
222-
ClickHouse 支持 ShardingSphere 集成级别的本地事务,但需要对 ClickHouse 进行额外配置,
216+
ClickHouse 不支持 ShardingSphere 集成级别的本地事务,XA 事务或 Seata 的 AT 模式事务,
223217
更多讨论位于 https://github.com/ClickHouse/clickhouse-docs/issues/2300
224218

225-
引入讨论,编写 Docker Compose 文件来启动 ClickHouse 和 ClickHouse Keeper。
226-
227-
```yaml
228-
services:
229-
clickhouse-keeper-01:
230-
image: clickhouse/clickhouse-keeper:24.11.1.2557
231-
volumes:
232-
- ./keeper_config.xml:/etc/clickhouse-keeper/keeper_config.xml
233-
clickhouse-server:
234-
image: clickhouse/clickhouse-server:24.11.1.2557
235-
depends_on:
236-
- clickhouse-keeper-01
237-
ports:
238-
- "8123:8123"
239-
volumes:
240-
- ./transactions.xml:/etc/clickhouse-server/config.d/transactions.xml
241-
```
242-
243-
`./keeper_config.xml` 的内容如下,
244-
245-
```xml
246-
<clickhouse replace="true">
247-
<listen_host>0.0.0.0</listen_host>
248-
<keeper_server>
249-
<tcp_port>9181</tcp_port>
250-
<server_id>1</server_id>
251-
<snapshot_storage_path>/var/lib/clickhouse/coordination/snapshots</snapshot_storage_path>
252-
<raft_configuration>
253-
<server>
254-
<id>1</id>
255-
<hostname>clickhouse-keeper-01</hostname>
256-
<port>9234</port>
257-
</server>
258-
</raft_configuration>
259-
</keeper_server>
260-
</clickhouse>
261-
```
262-
263-
`./transactions.xml` 的内容如下,
264-
265-
```xml
266-
<clickhouse>
267-
<allow_experimental_transactions>1</allow_experimental_transactions>
268-
<zookeeper>
269-
<node index="1">
270-
<host>clickhouse-keeper-01</host>
271-
<port>9181</port>
272-
</node>
273-
</zookeeper>
274-
</clickhouse>
275-
```
276-
277-
在 DBeaver Community 内,使用 `jdbc:ch://localhost:8123/default` 的 `jdbcUrl`,`default` 的`username` 连接至 ClickHouse,
278-
`password` 留空。
279-
执行如下 SQL,
280-
281-
```sql
282-
-- noinspection SqlNoDataSourceInspectionForFile
283-
CREATE DATABASE demo_ds_0;
284-
CREATE DATABASE demo_ds_1;
285-
CREATE DATABASE demo_ds_2;
286-
```
287-
288-
分别使用 `jdbc:ch://localhost:8123/demo_ds_0` ,
289-
`jdbc:ch://localhost:8123/demo_ds_1` 和 `jdbc:ch://localhost:8123/demo_ds_2` 的 `jdbcUrl` 连接至 ClickHouse 来执行如下 SQL,
290-
291-
```sql
292-
-- noinspection SqlNoDataSourceInspectionForFile
293-
create table IF NOT EXISTS t_order (
294-
order_id Int64 NOT NULL,
295-
order_type Int32,
296-
user_id Int32 NOT NULL,
297-
address_id Int64 NOT NULL,
298-
status VARCHAR(50)
299-
) engine = MergeTree
300-
primary key (order_id)
301-
order by (order_id);
302-
303-
TRUNCATE TABLE t_order;
304-
```
305-
306-
在业务项目引入`前提条件`涉及的依赖后,在业务项目的 classpath 上编写 ShardingSphere 数据源的配置文件`demo.yaml`,
307-
308-
```yaml
309-
dataSources:
310-
ds_0:
311-
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
312-
driverClassName: com.clickhouse.jdbc.ClickHouseDriver
313-
jdbcUrl: jdbc:ch://localhost:8123/demo_ds_0?transactionSupport=true
314-
username: default
315-
password:
316-
ds_1:
317-
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
318-
driverClassName: com.clickhouse.jdbc.ClickHouseDriver
319-
jdbcUrl: jdbc:ch://localhost:8123/demo_ds_1?transactionSupport=true
320-
username: default
321-
password:
322-
ds_2:
323-
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
324-
driverClassName: com.clickhouse.jdbc.ClickHouseDriver
325-
jdbcUrl: jdbc:ch://localhost:8123/demo_ds_2?transactionSupport=true
326-
username: default
327-
password:
328-
rules:
329-
- !SHARDING
330-
tables:
331-
t_order:
332-
actualDataNodes:
333-
keyGenerateStrategy:
334-
column: order_id
335-
keyGeneratorName: snowflake
336-
defaultDatabaseStrategy:
337-
standard:
338-
shardingColumn: user_id
339-
shardingAlgorithmName: inline
340-
shardingAlgorithms:
341-
inline:
342-
type: INLINE
343-
props:
344-
algorithm-expression: ds_${user_id % 2}
345-
keyGenerators:
346-
snowflake:
347-
type: SNOWFLAKE
348-
```
349-
350-
创建 ShardingSphere 的数据源后可正常使用本地事务,
351-
352-
```java
353-
import com.zaxxer.hikari.HikariConfig;
354-
import com.zaxxer.hikari.HikariDataSource;
355-
import java.sql.Connection;
356-
import java.sql.SQLException;
357-
@SuppressWarnings({"SqlNoDataSourceInspection", "AssertWithSideEffects"})
358-
public class ExampleUtils {
359-
void test() throws SQLException {
360-
HikariConfig config = new HikariConfig();
361-
config.setJdbcUrl("jdbc:shardingsphere:classpath:demo.yaml");
362-
config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver");
363-
try (HikariDataSource dataSource = new HikariDataSource(config); Connection connection = dataSource.getConnection()) {
364-
try {
365-
connection.setAutoCommit(false);
366-
connection.createStatement().executeUpdate("INSERT INTO t_order (user_id, order_type, address_id, status) VALUES (2024, 0, 2024, 'INSERT_TEST')");
367-
connection.createStatement().executeUpdate("INSERT INTO t_order_does_not_exist (test_id_does_not_exist) VALUES (2024)");
368-
connection.commit();
369-
} catch (final SQLException ignored) {
370-
connection.rollback();
371-
} finally {
372-
connection.setAutoCommit(true);
373-
}
374-
try (Connection conn = dataSource.getConnection()) {
375-
assert !conn.createStatement().executeQuery("SELECT * FROM t_order WHERE user_id = 2024").next();
376-
}
377-
}
378-
}
379-
}
380-
```
381-
382-
一旦在 ShardingSphere 的配置文件为 ClickHouse JDBC Driver 的 jdbcUrl 设置 `transactionSupport=true`,
383-
用户在执行 `alter table` 语句前应确保没有尚未完成执行的 `insert` 语句,以避免如下 Error 的发生,
384-
385-
```shell
386-
java.sql.BatchUpdateException: Code: 341. DB::Exception: Exception happened during execution of mutation 'mutation_6.txt' with part 'all_1_1_0' reason: 'Serialization error: part all_1_1_0 is locked by transaction 5672402456378293316'. This error maybe retryable or not. In case of unretryable error, mutation can be killed with KILL MUTATION query. (UNFINISHED) (version 24.10.2.80 (official build))
387-
at com.clickhouse.jdbc.SqlExceptionUtils.batchUpdateError(SqlExceptionUtils.java:107)
388-
at com.clickhouse.jdbc.internal.SqlBasedPreparedStatement.executeAny(SqlBasedPreparedStatement.java:223)
389-
at com.clickhouse.jdbc.internal.SqlBasedPreparedStatement.executeLargeUpdate(SqlBasedPreparedStatement.java:302)
390-
at com.clickhouse.jdbc.internal.AbstractPreparedStatement.executeUpdate(AbstractPreparedStatement.java:135)
391-
```
219+
这与 https://clickhouse.com/docs/en/guides/developer/transactional 为 ClickHouse 提供的 `Transactions, Commit, and Rollback` 功能无关,
220+
仅与 `com.clickhouse.jdbc.ConnectionImpl` 未实现 `java.sql.Connection#rollback()` 有关。
221+
参考 https://github.com/ClickHouse/clickhouse-java/issues/2023
392222

393223
### 嵌入式 ClickHouse 限制
394224

0 commit comments

Comments
 (0)