ClickHouse / clickhouse-java

ClickHouse Java Clients & JDBC Driver
https://clickhouse.com
Apache License 2.0
1.45k stars 537 forks source link

Ability to KILL query via JDBC in clustered environment #1981

Open devozerov opened 4 days ago

devozerov commented 4 days ago

When JDBC Statement.cancel method is invoked, a KILL QUERY query is executed. If ClickHouse is started in a clustered environment, sometimes this may fail to kill the query on all nodes because the proper command is KILL QUERY ON CLUSTER. Currently, there is no way to do this.

The proposal is to add a client configuration property with a cluster name. When specified, the JDBC driver should call KILL QUERY ON CLUSTER instead of KILL QUERY.

If this is difficult to achieve, at the very least lets expose the query_id from the Statement (https://github.com/ClickHouse/clickhouse-java/issues/392). In this case, the user will be able to invoke the command manually:

ClickHouseStatement chStatement = statement.unwrap(ClickHouseStatement.class);
Optional<String> queryId = chStatement.getQueryId();
if (queryId.isPresent()) {
    try (Statement killStatement = connection.createStatement()) {
        killStatement.executeUpdate("KILL QUERY ON CLUSTER ... WHERE query_id = " + queryId.get());
    }
}
YuriyGavrilov commented 4 days ago

Hi, maybe you guys @mzitnik, @den-crane help to link this issue to proper place or assign to someone? thx 🙏

chernser commented 4 days ago

Good day, @devozerov ! Thank you for reporting - will look into it.