| 434 | } |
| 435 | |
| 436 | void 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 | |
| 465 | void DatabaseAtomic::assertDetachedTableNotInUse(const UUID & uuid) |
| 466 | { |
nothing calls this directly
no test coverage detected