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

Method commitAlterTable

src/Databases/DatabaseAtomic.cpp:436–463  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

434}
435
436void DatabaseAtomic::commitAlterTable(const StorageID & table_id, const String & table_metadata_tmp_path, const String & table_metadata_path,
437 const String & /*statement*/, ContextPtr query_context)
438{
439 auto db_disk = getDisk();
440
441 bool check_file_exists = true;
442 SCOPE_EXIT({
443 if (check_file_exists)
444 db_disk->removeFileIfExists(table_metadata_tmp_path);
445 });
446
447 std::lock_guard lock{mutex};
448 auto actual_table_id = getTableUnlocked(table_id.table_name)->getStorageID();
449
450 if (table_id.uuid != actual_table_id.uuid)
451 throw Exception(ErrorCodes::CANNOT_ASSIGN_ALTER, "Cannot alter table because it was renamed");
452
453 auto txn = query_context->getZooKeeperMetadataTransaction();
454 if (txn && !query_context->isInternalSubquery())
455 txn->commit(); /// Commit point (a sort of) for Replicated database
456
457 /// NOTE: replica will be lost if server crashes before the following rename
458 /// TODO better detection and recovery
459
460 check_file_exists = db_disk->renameExchangeIfSupported(table_metadata_tmp_path, table_metadata_path);
461 if (!check_file_exists)
462 db_disk->replaceFile(table_metadata_tmp_path, table_metadata_path);
463}
464
465void DatabaseAtomic::assertDetachedTableNotInUse(const UUID & uuid)
466{

Callers

nothing calls this directly

Calls 8

isInternalSubqueryMethod · 0.80
ExceptionClass · 0.50
removeFileIfExistsMethod · 0.45
getStorageIDMethod · 0.45
commitMethod · 0.45
replaceFileMethod · 0.45

Tested by

no test coverage detected