| 205 | } |
| 206 | |
| 207 | void DatabaseAtomic::dropTableImpl(ContextPtr local_context, const String & table_name, bool sync) |
| 208 | { |
| 209 | String table_metadata_path = getObjectMetadataPath(table_name); |
| 210 | String table_metadata_path_drop; |
| 211 | StoragePtr table; |
| 212 | auto db_disk = getDisk(); |
| 213 | { |
| 214 | std::lock_guard lock(mutex); |
| 215 | table = getTableUnlocked(table_name); |
| 216 | table_metadata_path_drop = DatabaseCatalog::instance().getPathForDroppedMetadata(table->getStorageID()); |
| 217 | |
| 218 | db_disk->createDirectories(fs::path(table_metadata_path_drop).parent_path()); |
| 219 | |
| 220 | auto txn = local_context->getZooKeeperMetadataTransaction(); |
| 221 | if (txn && !local_context->isInternalSubquery()) |
| 222 | txn->commit(); /// Commit point (a sort of) for Replicated database |
| 223 | |
| 224 | /// NOTE: replica will be lost if server crashes before the following rename |
| 225 | /// We apply changes in ZooKeeper before applying changes in local metadata file |
| 226 | /// to reduce probability of failures between these operations |
| 227 | /// (it's more likely to lost connection, than to fail before applying local changes). |
| 228 | /// TODO better detection and recovery |
| 229 | |
| 230 | db_disk->replaceFile(table_metadata_path, table_metadata_path_drop); /// Mark table as dropped |
| 231 | DatabaseOrdinary::detachTableUnlocked(table_name); /// Should never throw |
| 232 | table_name_to_path.erase(table_name); |
| 233 | snapshot_detached_tables.erase(table_name); |
| 234 | } |
| 235 | |
| 236 | if (table->storesDataOnDisk()) |
| 237 | tryRemoveSymlink(table_name); |
| 238 | |
| 239 | /// Notify DatabaseCatalog that table was dropped. It will remove table data in background. |
| 240 | /// Cleanup is performed outside of database to allow easily DROP DATABASE without waiting for cleanup to complete. |
| 241 | DatabaseCatalog::instance().enqueueDroppedTableCleanup(table->getStorageID(), table, db_disk, table_metadata_path_drop, sync); |
| 242 | } |
| 243 | |
| 244 | void DatabaseAtomic::renameTable(ContextPtr local_context, const String & table_name, IDatabase & to_database, |
| 245 | const String & to_table_name, bool exchange, bool dictionary) |
nothing calls this directly
no test coverage detected