[jdbc] ClickHouseDriver: after one URL with clickhouse.jdbc.v1=true, every later DriverManager connection uses the v1 driver
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Start in clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/ClickHouseDriver.java, especially isV2(url) and getDriver(url), which the issue identifies as the source of the cached selection. Trace how each URL flag affects driver choice, then add or update focused tests for successive DriverManager URLs with and without selector flags. Done means each URL selects its own implementation, including a plain URL after a flagged URL.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
In one JVM, after one DriverManager.getConnection with clickhouse.jdbc.v1=true (or clickhouse.jdbc.v2=false) in the URL, every later DriverManager connection uses the v1 driver: also a URL with no flag, which must get jdbc-v2, and a URL with clickhouse.jdbc.v2=true. These connections then have v1 behavior; on server 26.9+ their reads fail (#3107). The selection stays until the JVM stops. The reverse also occurs: after a URL with clickhouse.jdbc.v1=false, a later clickhouse.jdbc.v1=true URL goes to jdbc-v2.
A new ClickHouseDriver() for each connection selects correctly. ClickHouseDataSource is not affected: it makes its own driver instance.
Root cause. DriverManager holds one ClickHouseDriver instance (clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/ClickHouseDriver.java:31). isV2(url) sets its field urlFlagSent for each URL that contains clickhouse.jdbc.v (:59), and from then on getDriver(url) returns the cached driver and does not read the URL (:78).
The fix is in getDriver: select the driver for each URL. Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.
Related: #3436 — jdbc-v2 rejects the selector keys clickhouse.jdbc.v1 / clickhouse.jdbc.v2 in the URL.
Steps to reproduce
- Put
clickhouse-jdbc(built frommain) and its dependencies on the classpath. Start a server onlocalhost:8123. - Run the program below. It opens three connections through
DriverManager, then two connections with a newClickHouseDrivereach. - Compare the connection classes: v1 is
com.clickhouse.jdbc.internal.ClickHouseConnectionImpl, jdbc-v2 iscom.clickhouse.jdbc.ConnectionImpl.
Error Log or Exception StackTrace
DriverManager (one registered ClickHouseDriver):
jdbc:clickhouse://localhost:8123/default?clickhouse.jdbc.v1=true -> com.clickhouse.jdbc.internal.ClickHouseConnectionImpl
jdbc:clickhouse://localhost:8123/default -> com.clickhouse.jdbc.internal.ClickHouseConnectionImpl
jdbc:clickhouse://localhost:8123/default?clickhouse.jdbc.v2=true -> com.clickhouse.jdbc.internal.ClickHouseConnectionImpl
SELECT 1 on jdbc:clickhouse://localhost:8123/default -> java.sql.SQLException: java.io.IOException: Magic is not correct - expect [-126] but got [-112]
Contrast: new ClickHouseDriver() for each URL:
jdbc:clickhouse://localhost:8123/default?clickhouse.jdbc.v1=true -> com.clickhouse.jdbc.internal.ClickHouseConnectionImpl
jdbc:clickhouse://localhost:8123/default -> com.clickhouse.jdbc.ConnectionImpl
Expected Behaviour
Each URL selects its own driver. A URL with no flag gets jdbc-v2 (ConnectionImpl), as the docs say (docs/clickhouse-docs/jdbc.mdx:51): "com.clickhouse.jdbc.ClickHouseDriver is a facade class for the new and old JDBC implementations. It uses the new JDBC implementation by default." In a JVM with no flagged URL before it, the same plain-URL connection is a ConnectionImpl and SELECT 1 returns 1.
Code Example
Reproduction program (Java, 36 lines)
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;
public class Repro {
static final String URL = "jdbc:clickhouse://localhost:8123/default";
public static void main(String[] args) throws Exception {
Properties p = new Properties();
p.setProperty("user", "default");
p.setProperty("password", System.getenv().getOrDefault("CLICKHOUSE_PASSWORD", ""));
System.out.println("DriverManager (one registered ClickHouseDriver):");
for (String url : new String[] {URL + "?clickhouse.jdbc.v1=true", URL, URL + "?clickhouse.jdbc.v2=true"}) {
try (Connection c = DriverManager.getConnection(url, p)) {
System.out.println(" " + url + " -> " + c.getClass().getName());
}
}
try (Connection c = DriverManager.getConnection(URL, p);
Statement s = c.createStatement(); ResultSet rs = s.executeQuery("SELECT 1")) {
rs.next();
System.out.println(" SELECT 1 on " + URL + " -> " + rs.getInt(1));
} catch (Exception e) {
System.out.println(" SELECT 1 on " + URL + " -> " + e);
}
System.out.println("Contrast: new ClickHouseDriver() for each URL:");
for (String url : new String[] {URL + "?clickhouse.jdbc.v1=true", URL}) {
try (Connection c = new com.clickhouse.jdbc.ClickHouseDriver().connect(url, p)) {
System.out.println(" " + url + " -> " + c.getClass().getName());
}
}
}
}
Configuration
Client Configuration
// only user and password in Properties; the driver is selected by the URL flag
Environment
- Cloud
- Client version:
main@8480ca001(0.12.0-rc1-SNAPSHOT) - Language version: OpenJDK 17.0.21
- OS: Linux
ClickHouse Server
- ClickHouse Server version: 26.11.2.4
- ClickHouse Server non-default settings, if any: none
CREATE TABLEstatements for tables involved: none- Sample data for all these tables: none
Classification: impact: none · area: Configuration (driver selection URL flag)
Found by automated analysis (Polyglot AI) while working on #2839. Verified against a live server.
- Ngôn ngữ chính
- Java
- Star
- 1.6k
- Fork
- 657
- Merge trung bình
- 2 ngày 6 giờ
- Pull request đã merge (30 ngày)
- 36
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của ClickHouse/clickhouse-java
-
api-diagnostics bug jdbc
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
ClickHouse/clickhouse-java#3464 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
tests
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
ClickHouse/clickhouse-java#3452 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug jdbc performance queries sql-parser
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
ClickHouse/clickhouse-java#3451 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug jdbc legacy queries
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
ClickHouse/clickhouse-java#3444 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
api-diagnostics bug client jdbc
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
ClickHouse/clickhouse-java#3439 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của ClickHouse/clickhouse-java
Issue tương tự
-
[BUG] Nightly Build JDK 17: latest-frameworks job red since 2026-11-28 — quarkiverse-langchain4j 2.0.0 pins Quarkus 4.0.0, which requires Java 21Có thể đã có người làm @uhhgxg đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
langchain4j/langchain4j#7344 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
cristianEncarnacion/ferroreport#149 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 60/100
quelea-projection/Quelea#749 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
free_port can hand one port to two callers, so the fixed-port http tests fail in parallel runsCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 92/100
erkamyaman/rust-anything#963 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 76/100