| 2800 | } |
| 2801 | |
| 2802 | void InterpreterCreateQuery::clearTransactionMetadata(const String & table_data_path, ContextPtr local_context) |
| 2803 | { |
| 2804 | LOG_INFO(getLogger("InterpreterCreateQuery"), "Clearing transaction metadata for table, relative path: {} when ATTACH AS REPLICATED.", table_data_path); |
| 2805 | |
| 2806 | /// Use disk API to remove transaction metadata files from all disks |
| 2807 | auto disks = local_context->getDisksMap(); |
| 2808 | size_t total_removed = 0; |
| 2809 | |
| 2810 | for (const auto & [disk_name, disk] : disks) |
| 2811 | { |
| 2812 | try |
| 2813 | { |
| 2814 | /// Skip if the table data path doesn't exist on this disk |
| 2815 | if (!disk->existsDirectory(table_data_path)) |
| 2816 | continue; |
| 2817 | |
| 2818 | /// Iterate through all parts in the table data directory |
| 2819 | for (auto it = disk->iterateDirectory(table_data_path); it->isValid(); it->next()) |
| 2820 | { |
| 2821 | String part_name = it->name(); |
| 2822 | String part_path = fs::path(table_data_path) / part_name; |
| 2823 | |
| 2824 | /// Check if it's a directory (part directory) |
| 2825 | if (!disk->existsDirectory(part_path)) |
| 2826 | continue; |
| 2827 | |
| 2828 | /// Try to remove txn_version.txt file |
| 2829 | String txn_file = fs::path(part_path) / VersionMetadata::TXN_VERSION_METADATA_FILE_NAME; |
| 2830 | if (disk->existsFile(txn_file)) |
| 2831 | { |
| 2832 | disk->removeFile(txn_file); |
| 2833 | total_removed++; |
| 2834 | } |
| 2835 | } |
| 2836 | } |
| 2837 | catch (...) |
| 2838 | { |
| 2839 | throw Exception(ErrorCodes::CANNOT_RESTORE_TABLE, |
| 2840 | "Cannot ATTACH AS REPLICATED: failed to clear transaction metadata on disk {}, due to {}", |
| 2841 | disk_name, getCurrentExceptionMessage(false)); |
| 2842 | } |
| 2843 | } |
| 2844 | |
| 2845 | LOG_INFO(getLogger("InterpreterCreateQuery"), "Removed {} transaction metadata files for table, relative path: {}.", total_removed, table_data_path); |
| 2846 | } |
| 2847 | |
| 2848 | void registerInterpreterCreateQuery(InterpreterFactory & factory); |
| 2849 | void registerInterpreterCreateQuery(InterpreterFactory & factory) |
nothing calls this directly
no test coverage detected