ClickHouse/clickhouse-java

Creating a DataSource using 0.6.1 takes over 1 minute to complete

NRaf opened this issue · 1 comments

NRaf commented

Describe the bug

When creating a DataSource using the ClickHouse driver with version 0.6.1 it takes over 1 minute to connect. I've tested this against a local version of ClickHouse Server as well as ClickHouse Server running in Docker (through TestContainers).

If I downgrade to 0.6.0, it completes almost instantaneously.

Steps to reproduce

  1. Add Clickhouse JDBC Driver with version 0.6.1 to pom.xml
  2. Create a DataSource with the URL, username and passwod

Code example

import com.clickhouse.jdbc.ClickHouseDataSource;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.jdbc.core.JdbcTemplate;

import java.sql.SQLException;
import java.util.Properties;

import static org.junit.jupiter.api.Assertions.*;

@Slf4j
public class ClickhouseConnectionTest {
  @Test
  void test() {
    try {
      Properties properties = new Properties();
      properties.setProperty("user", "default");
      properties.setProperty("password", "");
      log.info("Connecting to database");
      ClickHouseDataSource dataSource = new ClickHouseDataSource("jdbc:clickhouse://localhost:8123/default", properties);
      log.info("Connected to database");

      log.info("Executing query");
      JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
      assertEquals(1, jdbcTemplate.queryForObject("SELECT 1", Integer.class).intValue());
      log.info("Executed query");
    } catch (SQLException e) {
      fail("Failed to connect to database");
    }
  }
}

Error log

** Running 0.6.1 **

2024-06-19T10:38:25.710+10:00  INFO   --- [           main] i.s.i.i.d.r.a.a.ClickhouseConnectionTest : Connecting to database
2024-06-19T10:38:25.735+10:00 DEBUG   --- [           main] com.clickhouse.jdbc.ClickHouseDriver     : ClickHouse Driver 0.6.1.0(JDBC: 4.2.0.0) registered
2024-06-19T10:39:26.965+10:00  INFO   --- [           main] i.s.i.i.d.r.a.a.ClickhouseConnectionTest : Connected to database
2024-06-19T10:39:26.965+10:00  INFO   --- [           main] i.s.i.i.d.r.a.a.ClickhouseConnectionTest : Executing query
2024-06-19T10:39:27.022+10:00 DEBUG   --- [           main] c.c.client.ClickHouseNodeSelector        : Checking [com.clickhouse.client.cli.ClickHouseCommandLineClient@1cdc4c27] against [HTTP]...
2024-06-19T10:39:27.028+10:00 DEBUG   --- [           main] c.c.client.ClickHouseNodeSelector        : Checking [com.clickhouse.client.http.ClickHouseHttpClient@30b19518] against [HTTP]...
2024-06-19T10:39:27.031+10:00 DEBUG   --- [           main] c.c.j.internal.ClickHouseConnectionImpl  : Connecting to: ClickHouseNode [uri=http://localhost:8123/default]@-1670582483
2024-06-19T10:39:27.032+10:00 DEBUG   --- [           main] com.clickhouse.client.AbstractClient     : Connecting to: ClickHouseNode [uri=http://localhost:8123/default]@-1670582483
2024-06-19T10:39:27.062+10:00 DEBUG   --- [           main] c.c.c.http.ClickHouseHttpConnection      : url [http://localhost:8123/?extremes=0]
2024-06-19T10:39:27.201+10:00 DEBUG   --- [           main] com.clickhouse.client.AbstractClient     : Connection established: com.clickhouse.client.http.ApacheHttpConnectionImpl@19ae6bb
2024-06-19T10:39:27.202+10:00 DEBUG   --- [           main] c.c.client.http.ClickHouseHttpClient     : Query: select currentUser() user, timezone() timezone, version() version, toUInt8(ifnull((select value from system.settings where name = 'readonly'), '0')) as readonly, toInt8(ifnull((select value from system.settings where name = 'throw_on_unsupported_query_inside_transaction'), '-1')) as throw_on_unsupported_query_inside_transaction, (ifnull((select value from system.settings where name = 'wait_changes_become_visible_after_commit_mode'), '')) as wait_changes_become_visible_after_commit_mode,toInt8(ifnull((select value from system.settings where name = 'implicit_transaction'), '-1')) as implicit_transaction, toUInt64(ifnull((select value from system.settings where name = 'max_insert_block_size'), '0')) as max_insert_block_size, toInt8(ifnull((select value from system.settings where name = 'allow_experimental_lightweight_delete'), '-1')) as allow_experimental_lightweight_delete, (ifnull((select value from system.settings where name = 'custom_jdbc_config'), '')) as custom_jdbc_config FORMAT RowBinaryWithNamesAndTypes
2024-06-19T10:39:27.384+10:00 DEBUG   --- [           main] c.c.client.http.ClickHouseHttpClient     : Query: SELECT 1
2024-06-19T10:39:27.718+10:00  INFO   --- [           main] i.s.i.i.d.r.a.a.ClickhouseConnectionTest : Executed query

** Running 0.6.0**

2024-06-19T10:31:17.198+10:00  INFO   --- [           main] i.s.i.i.d.r.a.a.ClickhouseConnectionTest : Connecting to database
2024-06-19T10:31:17.219+10:00 DEBUG   --- [           main] com.clickhouse.jdbc.ClickHouseDriver     : ClickHouse Driver 0.6.0.0(JDBC: 4.2.0.0) registered
2024-06-19T10:31:17.296+10:00  INFO   --- [           main] i.s.i.i.d.r.a.a.ClickhouseConnectionTest : Connected to database
2024-06-19T10:31:17.296+10:00  INFO   --- [           main] i.s.i.i.d.r.a.a.ClickhouseConnectionTest : Executing query
2024-06-19T10:31:17.369+10:00 DEBUG   --- [           main] c.c.client.ClickHouseNodeSelector        : Checking [com.clickhouse.client.cli.ClickHouseCommandLineClient@f80945f] against [HTTP]...
2024-06-19T10:31:17.379+10:00 DEBUG   --- [           main] c.c.client.ClickHouseNodeSelector        : Checking [com.clickhouse.client.http.ClickHouseHttpClient@1e8ce150] against [HTTP]...
2024-06-19T10:31:17.383+10:00 DEBUG   --- [           main] c.c.j.internal.ClickHouseConnectionImpl  : Connecting to: ClickHouseNode [uri=http://localhost:8123/default]@-1080871143
2024-06-19T10:31:17.383+10:00 DEBUG   --- [           main] com.clickhouse.client.AbstractClient     : Connecting to: ClickHouseNode [uri=http://localhost:8123/default]@-1080871143
2024-06-19T10:31:17.426+10:00 DEBUG   --- [           main] c.c.c.http.ClickHouseHttpConnection      : url [http://localhost:8123/?extremes=0]
2024-06-19T10:31:17.578+10:00 DEBUG   --- [           main] com.clickhouse.client.AbstractClient     : Connection established: com.clickhouse.client.http.ApacheHttpConnectionImpl@4c4d27c8
2024-06-19T10:31:17.579+10:00 DEBUG   --- [           main] c.c.client.http.ClickHouseHttpClient     : Query: select currentUser() user, timezone() timezone, version() version, toUInt8(ifnull((select value from system.settings where name = 'readonly'), '0')) as readonly, toInt8(ifnull((select value from system.settings where name = 'throw_on_unsupported_query_inside_transaction'), '-1')) as throw_on_unsupported_query_inside_transaction, (ifnull((select value from system.settings where name = 'wait_changes_become_visible_after_commit_mode'), '')) as wait_changes_become_visible_after_commit_mode,toInt8(ifnull((select value from system.settings where name = 'implicit_transaction'), '-1')) as implicit_transaction, toUInt64(ifnull((select value from system.settings where name = 'max_insert_block_size'), '0')) as max_insert_block_size, toInt8(ifnull((select value from system.settings where name = 'allow_experimental_lightweight_delete'), '-1')) as allow_experimental_lightweight_delete, (ifnull((select value from system.settings where name = 'custom_jdbc_config'), '')) as custom_jdbc_config FORMAT RowBinaryWithNamesAndTypes
2024-06-19T10:31:17.828+10:00 DEBUG   --- [           main] c.c.client.http.ClickHouseHttpClient     : Query: SELECT 1
2024-06-19T10:31:18.328+10:00  INFO   --- [           main] i.s.i.i.d.r.a.a.ClickhouseConnectionTest : Executed query

Configuration

Environment

  • Client version: 0.6.1
  • Language version: Java 21
  • OS: Mac Sonoma, Macbook M3 Pro Max

ClickHouse server

  • ClickHouse Server version: 24.6.1.3899 (local), also tested against the latest and latest-alpine Docker images

seem too