Create table fail on cluster: jdbc executeUpdate return true but table is not yet created
See original GitHub issueJdbc execute/executeUpdate return true even when the execution of create table on cluster
is not yet finished in the whole cluster. Queries that are executed right after the create statement (client.execute() already return true) throw table doesn't exist
. If I sleep the thread after the create statement for an amount of time (like 500 ms for example) then everything works fine.
Environment
- OS version: Ubuntu 20.04
- JDK version: openjdk version “1.8.0_292”
- ClickHouse Server version: 21.9.2
- ClickHouse Native JDBC version: 2.5.6
- (Optional) Spark version: N/A
- (Optional) Other components’ version: N/A
Error logs
com.github.housepower.jdbc.ClickHouseSQLException: DB::ExceptionDB::Exception: Table database_test.table_test doesn't exist. Stack trace:
0. DB::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, bool) @ 0x9366e7a in /usr/bin/clickhouse
1. DB::Exception::Exception<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&&) @ 0x948d0c3 in /usr/bin/clickhouse
2. void std::__1::__optional_storage_base<DB::Exception, false>::__construct<int const&, char const (&) [23], std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(int const&, char const (&) [23], std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&&) @ 0x107748f1 in /usr/bin/clickhouse
3. DB::DatabaseCatalog::getTableImpl(DB::StorageID const&, std::__1::shared_ptr<DB::Context const>, std::__1::optional<DB::Exception>*) const @ 0x10765c0a in /usr/bin/clickhouse
4. DB::DatabaseCatalog::getTable(DB::StorageID const&, std::__1::shared_ptr<DB::Context const>) const @ 0x1076bc48 in /usr/bin/clickhouse
5. DB::JoinedTables::getLeftTableStorage() @ 0x10d2777c in /usr/bin/clickhouse
6. DB::InterpreterSelectQuery::InterpreterSelectQuery(std::__1::shared_ptr<DB::IAST> const&, std::__1::shared_ptr<DB::Context const>, std::__1::shared_ptr<DB::IBlockInputStream> const&, std::__1::optional<DB::Pipe>, std::__1::shared_ptr<DB::IStorage> const&, DB::SelectQueryOptions const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&) @ 0x10b0e067 in /usr/bin/clickhouse
7. DB::InterpreterSelectQuery::InterpreterSelectQuery(std::__1::shared_ptr<DB::IAST> const&, std::__1::shared_ptr<DB::Context const>, DB::SelectQueryOptions const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) @ 0x10b0d63e in /usr/bin/clickhouse
8. DB::InterpreterSelectWithUnionQuery::buildCurrentChildInterpreter(std::__1::shared_ptr<DB::IAST> const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) @ 0x10cec68f in /usr/bin/clickhouse
9. DB::InterpreterSelectWithUnionQuery::InterpreterSelectWithUnionQuery(std::__1::shared_ptr<DB::IAST> const&, std::__1::shared_ptr<DB::Context const>, DB::SelectQueryOptions const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) @ 0x10ceaf00 in /usr/bin/clickhouse
10. DB::InterpreterFactory::get(std::__1::shared_ptr<DB::IAST>&, std::__1::shared_ptr<DB::Context>, DB::SelectQueryOptions const&) @ 0x108d4ce7 in /usr/bin/clickhouse
11. ? @ 0x10ee1faf in /usr/bin/clickhouse
12. DB::executeQuery(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::shared_ptr<DB::Context>, bool, DB::QueryProcessingStage::Enum, bool) @ 0x10ee02e3 in /usr/bin/clickhouse
13. DB::TCPHandler::runImpl() @ 0x117a03d0 in /usr/bin/clickhouse
14. DB::TCPHandler::run() @ 0x117b2cb9 in /usr/bin/clickhouse
15. Poco::Net::TCPServerConnection::start() @ 0x143720af in /usr/bin/clickhouse
16. Poco::Net::TCPServerDispatcher::run() @ 0x14373b3a in /usr/bin/clickhouse
17. Poco::PooledThread::run() @ 0x144a69b9 in /usr/bin/clickhouse
18. Poco::ThreadImpl::runnableEntry(void*) @ 0x144a2c4a in /usr/bin/clickhouse
19. start_thread @ 0x9609 in /usr/lib/x86_64-linux-gnu/libpthread-2.31.so
20. clone @ 0x122293 in /usr/lib/x86_64-linux-gnu/libc-2.31.so
at com.github.housepower.jdbc.protocol.ExceptionResponse.readExceptionFrom(ExceptionResponse.java:36)
at com.github.housepower.jdbc.protocol.Response.readFrom(Response.java:35)
at com.github.housepower.jdbc.connect.NativeClient.receiveResponse(NativeClient.java:178)
at com.github.housepower.jdbc.connect.NativeClient.lambda$receiveQuery$0(NativeClient.java:135)
at com.github.housepower.jdbc.stream.ClickHouseQueryResult.consumeDataResponse(ClickHouseQueryResult.java:89)
at com.github.housepower.jdbc.stream.ClickHouseQueryResult.ensureHeaderConsumed(ClickHouseQueryResult.java:82)
at com.github.housepower.jdbc.stream.ClickHouseQueryResult.header(ClickHouseQueryResult.java:43)
at com.github.housepower.jdbc.statement.ClickHouseStatement.executeUpdate(ClickHouseStatement.java:93)
at com.github.housepower.jdbc.statement.ClickHouseStatement.executeQuery(ClickHouseStatement.java:100)
at com.github.housepower.jdbc.statement.ClickHousePreparedQueryStatement.executeQuery(ClickHousePreparedQueryStatement.java:74)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
Steps to reproduce
- create database on cluster:
client.execute("CREATE DATABASE IF NOT EXISTS database_test ON CLUSTER company_cluster")
- create shard table and distributed table on cluster in given database:
client.execute("CREATE TABLE IF NOT EXISTS database_test.table_test_shard ON CLUSTER database_test (
`id` UInt32,
`name` String
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{cluster}/{shard}/database_test/table_test', '{replica}')
ORDER BY tuple()")
client.execute("CREATE TABLE IF NOT EXISTS database_test.table_test ON CLUSTER company_cluster AS database_test.table_test_shard
ENGINE = Distributed('company_cluster', database_test, table_test_shard, rand());")
- run a query on created table:
client.executeQuery(“SELECT * FROM database_test.table_test”)
–> throw exception
com.github.housepower.jdbc.ClickHouseSQLException: DB::ExceptionDB::Exception: Table database_test.table_test doesn't exist.
Other descriptions
It’s also happens with other ddl statement like alter table, rename table, drop table…
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
why does executeUpdate return 1 even if no new row has ...
However if I want to insert a String through JDBC, nothing gets inserted, although preparedStatement.executeUpdate() always returns 1. Below is my method that ......
Read more >java.sql.Statement.executeUpdate java code examples
executeUpdate ("ALTER TABLE STAGES ADD COLUMN `ARTIFACTSDELETED` Boolean DEFAULT FALSE NOT NULL") ... MySQL & Java - Get id of the last inserted...
Read more >Executing SQL commands with executeUpdate() or through ...
executeQuery() was designed to execute query statements so it returns a ResultSet ... shows using the executeUpdate() method to add a row to...
Read more >Java JDBC CRUD Tutorial: SQL Insert, Select, Update, and ...
This JDBC tutorial is going to help you learning how to do basic database operations (CRUD - Create, Retrieve, Update and Delete) using...
Read more >Using the Spark Connector - Snowflake Documentation
The runQuery method returns only TRUE or FALSE. It is intended for statements that do not return a result set, for example DDL...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If you are using
ReplicatedMergeTree
on cluster DDL, 1s-2s is the expected delay.I suggest you loop 4 nodes to create this table to ensure that all nodes have been created.
Okay thanks for your replies. I guess I’ll go with that way then!