diff --git a/src/Databases/DatabaseAtomic.cpp b/src/Databases/DatabaseAtomic.cpp index 5c75f6f1036..26f694cb5dd 100644 --- a/src/Databases/DatabaseAtomic.cpp +++ b/src/Databases/DatabaseAtomic.cpp @@ -140,6 +140,11 @@ void DatabaseAtomic::dropTable(ContextPtr local_context, const String & table_na if (table->storesDataOnDisk()) tryRemoveSymlink(table_name); + if (table->dropTableImmediately()) + { + table->drop(); + } + /// Notify DatabaseCatalog that table was dropped. It will remove table data in background. /// Cleanup is performed outside of database to allow easily DROP DATABASE without waiting for cleanup to complete. DatabaseCatalog::instance().enqueueDroppedTableCleanup(table->getStorageID(), table, table_metadata_path_drop, no_delay); diff --git a/src/Interpreters/DatabaseCatalog.cpp b/src/Interpreters/DatabaseCatalog.cpp index f273f8a165d..c87a9b91640 100644 --- a/src/Interpreters/DatabaseCatalog.cpp +++ b/src/Interpreters/DatabaseCatalog.cpp @@ -898,7 +898,7 @@ void DatabaseCatalog::dropTableDataTask() void DatabaseCatalog::dropTableFinally(const TableMarkedAsDropped & table) { - if (table.table) + if (table.table && !table.table->dropTableImmediately()) { table.table->drop(); } diff --git a/src/Storages/FileLog/FileLogSource.cpp b/src/Storages/FileLog/FileLogSource.cpp index c272df1c2b2..a03ad1a4c51 100644 --- a/src/Storages/FileLog/FileLogSource.cpp +++ b/src/Storages/FileLog/FileLogSource.cpp @@ -11,12 +11,7 @@ namespace DB { -namespace ErrorCodes -{ - extern const int LOGICAL_ERROR; -} - -const auto MAX_FAILED_POLL_ATTEMPTS = 10; +static constexpr auto MAX_FAILED_POLL_ATTEMPTS = 10; FileLogSource::FileLogSource( StorageFileLog & storage_, diff --git a/src/Storages/FileLog/StorageFileLog.cpp b/src/Storages/FileLog/StorageFileLog.cpp index ebc8bb9ba8a..ca7df3c5e4b 100644 --- a/src/Storages/FileLog/StorageFileLog.cpp +++ b/src/Storages/FileLog/StorageFileLog.cpp @@ -39,7 +39,8 @@ namespace ErrorCodes extern const int CANNOT_GET_FILE_STAT; extern const int NOT_REGULAR_FILE; extern const int READ_META_FILE_FAILED; - extern const int FILE_STREAM_ERROR; + extern const int FILE_STREAM_ERROR; + extern const int LOGICAL_ERROR; } namespace diff --git a/src/Storages/FileLog/StorageFileLog.h b/src/Storages/FileLog/StorageFileLog.h index d715fbbfefc..4daf2bd175a 100644 --- a/src/Storages/FileLog/StorageFileLog.h +++ b/src/Storages/FileLog/StorageFileLog.h @@ -44,6 +44,8 @@ public: void drop() override; + bool dropTableImmediately() const override { return true; } + const auto & getFormatName() const { return format_name; } enum class FileStatus diff --git a/src/Storages/IStorage.h b/src/Storages/IStorage.h index 90cb963e064..baf57c40185 100644 --- a/src/Storages/IStorage.h +++ b/src/Storages/IStorage.h @@ -578,6 +578,8 @@ public: /// Does not takes underlying Storage (if any) into account. virtual std::optional lifetimeBytes() const { return {}; } + virtual bool dropTableImmediately() const { return false; } + private: /// Lock required for alter queries (lockForAlter). Always taken for write /// (actually can be replaced with std::mutex, but for consistency we use diff --git a/tests/queries/0_stateless/02025_storage_filelog_virtual_col.sh b/tests/queries/0_stateless/02025_storage_filelog_virtual_col.sh index 8e9769d060d..c5e1553c41a 100755 --- a/tests/queries/0_stateless/02025_storage_filelog_virtual_col.sh +++ b/tests/queries/0_stateless/02025_storage_filelog_virtual_col.sh @@ -46,8 +46,8 @@ rm ${user_files_path}/logs/d.txt ${CLICKHOUSE_CLIENT} --query "select *, _file_name, _offset from file_log order by _file_name, _offset;" -${CLICKHOUSE_CLIENT} --query "detach table t;" -${CLICKHOUSE_CLIENT} --query "attach table t;" +${CLICKHOUSE_CLIENT} --query "detach table file_log;" +${CLICKHOUSE_CLIENT} --query "attach table file_log;" # should no records return ${CLICKHOUSE_CLIENT} --query "select *, _file_name, _offset from file_log order by _file_name, _offset;"