| 624 | } |
| 625 | |
| 626 | void DatabaseAtomic::tryCreateSymlink(const StoragePtr & table, bool if_data_path_exist) |
| 627 | { |
| 628 | auto db_disk = getDisk(); |
| 629 | |
| 630 | if (!db_disk->isSymlinkSupported()) |
| 631 | return; |
| 632 | |
| 633 | if (table->getDataPaths().empty()) |
| 634 | return; |
| 635 | |
| 636 | const auto table_data_path = fs::path(table->getDataPaths().front()).lexically_normal(); |
| 637 | |
| 638 | try |
| 639 | { |
| 640 | String table_name = table->getStorageID().getTableName(); |
| 641 | |
| 642 | if (!table->storesDataOnDisk()) |
| 643 | throw Exception(ErrorCodes::LOGICAL_ERROR, "Table {} doesn't have data path to create symlink", table_name); |
| 644 | |
| 645 | String link = path_to_table_symlinks / escapeForFileName(table_name); |
| 646 | |
| 647 | LOG_DEBUG( |
| 648 | log, |
| 649 | "Trying to create a symlink for table {}, data_path {}, link {}", |
| 650 | table->getStorageID().getNameForLogs(), |
| 651 | table_data_path, |
| 652 | link); |
| 653 | |
| 654 | /// If it already points where needed. |
| 655 | if (db_disk->equivalentNoThrow(table_data_path, link)) |
| 656 | return; |
| 657 | |
| 658 | if (if_data_path_exist && !db_disk->existsFileOrDirectory(data_path)) |
| 659 | return; |
| 660 | |
| 661 | db_disk->createDirectorySymlink(table_data_path, link); |
| 662 | } |
| 663 | catch (...) |
| 664 | { |
| 665 | LOG_WARNING(log, getCurrentExceptionMessageAndPattern(/* with_stacktrace */ true)); |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | void DatabaseAtomic::tryRemoveSymlink(const String & table_name) |
| 670 | { |
no test coverage detected