MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / dropTableImpl

Method dropTableImpl

src/Databases/DatabaseAtomic.cpp:207–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

205}
206
207void 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
244void DatabaseAtomic::renameTable(ContextPtr local_context, const String & table_name, IDatabase & to_database,
245 const String & to_table_name, bool exchange, bool dictionary)

Callers

nothing calls this directly

Calls 11

parent_pathMethod · 0.80
isInternalSubqueryMethod · 0.80
getStorageIDMethod · 0.45
createDirectoriesMethod · 0.45
commitMethod · 0.45
replaceFileMethod · 0.45
eraseMethod · 0.45
storesDataOnDiskMethod · 0.45

Tested by

no test coverage detected