Skip to content

Cannot startup when named collection dropped #77366

Closed

Description

@caoyang10

Company or project name

No response

Describe the unexpected behaviour

If I drop a named collection, all the external tables(MySQL) which use this collection are invalid. And it cause the server cannot startup.
I think the check is so strict. Just throw exception when table used.

How to reproduce

Reproduce:

CREATE NAMED COLLECTION test_collection AS host = '', port = 3306, database = '', user = '', password = '';
CREATE TABLE test_mysql
(
    `a` String
)
ENGINE = MySQL(test_collection, `table` = 'test_table');
DROP NAMED COLLECTION test_collection;

Then restart clickhouse server and it can't startup.

Application: Code: 722. DB::Exception: Waited job failed: Code: 695. DB::Exception: Load job 'load table default.test_mysql' failed: Code: 669. DB::Exception: There is no named collection test_collection: Cannot attach table default.test_mysql from metadata file /Users/caoyang/tmp/store/f62/f62c3530-b3c6-4493-8285-17653441e612/test_mysql.sql from query ATTACH TABLE default.test_mysql UUID '3e2371ec-48f6-4aed-9be9-8ffac527e93a' (a String) ENGINE = MySQL(test_collection, table = 'test_table'). (NAMED_COLLECTION_DOESNT_EXIST), Stack trace (when copying this message, always include the lines below):

  1. Poco::Exception::Exception(String const&, int) @ 0x000000010f491b80

  2. DB::Exception::Exception(DB::Exception::MessageMasked&&, int, bool) @ 0x0000000109566b64

  3. DB::Exception::Exception(PreformattedMessage&&, int) @ 0x0000000104dfeffc

  4. DB::Exception::Exception<String const&>(int, FormatStringHelperImpl<std::type_identity<String const&>::type>, String const&) @ 0x0000000104e0e59c

  5. DB::NamedCollectionFactory::get(String const&) const @ 0x000000010bf82c38

  6. DB::tryGetNamedCollectionWithOverrides(absl::InlinedVector<std::shared_ptrDB::IAST, 7ul, std::allocator<std::shared_ptrDB::IAST>>, std::shared_ptr<DB::Context const>, bool, std::vector<std::pair<String, std::shared_ptrDB::IAST>, std::allocator<std::pair<String, std::shared_ptrDB::IAST>>>*) @ 0x000000010d66b400

  7. DB::StorageMySQL::getConfiguration(absl::InlinedVector<std::shared_ptrDB::IAST, 7ul, std::allocator<std::shared_ptrDB::IAST>>, std::shared_ptr<DB::Context const>, DB::MySQLSettings&) @ 0x000000010d7fc688

  8. std::shared_ptrDB::IStorage std::__function::__policy_invoker<std::shared_ptrDB::IStorage (DB::StorageFactory::Arguments const&)>::__call_impl<std::__function::__default_alloc_func<DB::registerStorageMySQL(DB::StorageFactory&)::$_0, std::shared_ptrDB::IStorage (DB::StorageFactory::Arguments const&)>>(std::__function::__policy_storage const*, DB::StorageFactory::Arguments const&) @ 0x000000010d7ff210

  9. DB::StorageFactory::get(DB::ASTCreateQuery const&, String const&, std::shared_ptrDB::Context, std::shared_ptrDB::Context, DB::ColumnsDescription const&, DB::ConstraintsDescription const&, DB::LoadingStrictnessLevel) const @ 0x000000010d700dcc

  10. DB::createTableFromAST(DB::ASTCreateQuery, String const&, String const&, std::shared_ptrDB::Context, DB::LoadingStrictnessLevel) @ 0x000000010c680cfc

  11. DB::DatabaseOrdinary::loadTableFromMetadata(std::shared_ptrDB::Context, String const&, DB::QualifiedTableName const&, std::shared_ptrDB::IAST const&, DB::LoadingStrictnessLevel) @ 0x000000010c692784

  12. DB::AsyncLoader::worker(DB::AsyncLoader::Pool&) @ 0x0000000109542194

  13. ThreadPoolImpl<ThreadFromGlobalPoolImpl<false, true>>::worker(std::__list_iterator<ThreadFromGlobalPoolImpl<false, true>, void*>) @ 0x0000000109638694

  14. ThreadFromGlobalPoolImpl<false, true>::ThreadFromGlobalPoolImpl<void ThreadPoolImpl<ThreadFromGlobalPoolImpl<false, true>>::scheduleImpl(std::function<void ()>, Priority, std::optional, bool)::'lambda0'()>(void&&)::'lambda'()::operator()() @ 0x000000010963e880

  15. ThreadPoolImplstd::thread::worker(std::__list_iterator<std::thread, void*>) @ 0x0000000109636230

  16. void* std::__thread_proxy[abi:v15007]<std::tuple<std::unique_ptr<std::__thread_struct, std::default_deletestd::__thread_struct>, void ThreadPoolImplstd::thread::scheduleImpl(std::function<void ()>, Priority, std::optional, bool)::'lambda0'()>>(void*) @ 0x000000010963d0f4

  17. _pthread_start @ 0x000000019f46ffa8

  18. thread_start @ 0x000000019f46ada0
    (version 24.8.1.157 (official build)). (ASYNC_LOAD_FAILED) (version 24.8.1.157 (official build)). (ASYNC_LOAD_WAIT_FAILED), Stack trace (when copying this message, always include the lines below):

  19. Poco::Exception::Exception(String const&, int) @ 0x000000010f491b80

  20. DB::Exception::Exception(DB::Exception::MessageMasked&&, int, bool) @ 0x0000000109566b64

  21. DB::Exception::Exception(PreformattedMessage&&, int) @ 0x0000000104dfeffc

  22. DB::Exception::Exception(int, FormatStringHelperImpl<std::type_identity::type>, String&&) @ 0x0000000104dfebdc

  23. DB::AsyncLoader::wait(std::shared_ptrDB::LoadJob const&, bool) @ 0x000000010953fb3c

  24. DB::waitLoad(unsigned long, std::vector<std::shared_ptrDB::LoadTask, std::allocator<std::shared_ptrDB::LoadTask>> const&, bool) @ 0x0000000109814e30

  25. DB::loadMetadata(std::shared_ptrDB::Context, String const&, bool) @ 0x000000010d014b9c

  26. DB::Server::main(std::vector<String, std::allocator> const&) @ 0x00000001097d03d8

  27. Poco::Util::Application::run() @ 0x000000010f5685fc

  28. DB::Server::run() @ 0x00000001097c58c0

  29. Poco::Util::ServerApplication::run(int, char**) @ 0x000000010f57a8f0

  30. mainEntryClickHouseServer(int, char**) @ 0x00000001097c34e4

  31. main @ 0x0000000104dfbff8

  32. start @ 0x000000019f117f28
    (version 24.8.1.157 (official build))

Expected behavior

No response

Error message and/or stacktrace

No response

Additional context

No response

Activity

  1. added
    unexpected behaviour
    on Mar 10, 2025
  2. caoyang10 commented on Mar 12, 2025

    @caoyang10
    Author

    Anyone can reply?

  3. caoyang10 commented on Aug 11, 2025

    @caoyang10
    Author

    Also, if you create an S3 engine table and then make AK/SK/bucket invalid, the server can't startup

  4. self-assigned this
    on Jan 30, 2026
  5. pamarcos commented on Feb 3, 2026

    @pamarcos
    Member

    @caoyang10 sorry it took us so long to take a look at this.

    What you reported is the expected behavior for the version you used if you had an existing config file. The underlying issue is that tables were loaded synchronously at that version unless async_load_databases is set to true in the configuration.

    In 23.12 #57695 the default value was changed in the config.
    In 25.2 #74772 the default value was changed to true.

  6. pamarcos commented on Feb 5, 2026

    @pamarcos
    Member

    After discussing with @nikitamikhaylov we decided to implement a safe-mechanism to ensure that whenever someone tries to DROP a named collection, we traverse all its tables using it and if any, we'll throw an exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

unexpected behaviour

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions