| 35 | } |
| 36 | |
| 37 | static void cckMetadataPathForOrdinary(const ASTCreateQuery & create, const String & metadata_path) |
| 38 | { |
| 39 | auto default_db_disk = Context::getGlobalContextInstance()->getDatabaseDisk(); |
| 40 | |
| 41 | if (!default_db_disk->isSymlinkSupported()) |
| 42 | return; |
| 43 | |
| 44 | const String & engine_name = create.storage->engine->name; |
| 45 | const String & database_name = create.getDatabase(); |
| 46 | |
| 47 | if (engine_name != "Ordinary") |
| 48 | return; |
| 49 | |
| 50 | if (!default_db_disk->isSymlink(metadata_path)) |
| 51 | return; |
| 52 | |
| 53 | String target_path = default_db_disk->readSymlink(metadata_path); |
| 54 | fs::path path_to_remove = metadata_path; |
| 55 | if (path_to_remove.filename().empty()) |
| 56 | path_to_remove = path_to_remove.parent_path(); |
| 57 | |
| 58 | /// Before 20.7 metadata/db_name.sql file might absent and Ordinary database was attached if there's metadata/db_name/ dir. |
| 59 | /// Between 20.7 and 22.7 metadata/db_name.sql was created in this case as well. |
| 60 | /// Since 20.7 `default` database is created with Atomic engine on the very first server run. |
| 61 | /// The problem is that if server crashed during the very first run and metadata/db_name/ -> store/whatever symlink was created |
| 62 | /// then it's considered as Ordinary database. And it even works somehow |
| 63 | /// until background task tries to remove unused dir from store/... |
| 64 | throw Exception(ErrorCodes::CANNOT_CREATE_DATABASE, |
| 65 | "Metadata directory {} for Ordinary database {} is a symbolic link to {}. " |
| 66 | "It may be a result of manual intervention, crash on very first server start or a bug. " |
| 67 | "Database cannot be attached (it's kind of protection from potential data loss). " |
| 68 | "Metadata directory must not be a symlink and must contain tables metadata files itself. " |
| 69 | "You have to resolve this manually. It can be done like this: rm {}; sudo -u clickhouse mv {} {};", |
| 70 | metadata_path, database_name, target_path, |
| 71 | quoteString(path_to_remove.string()), quoteString(target_path), quoteString(path_to_remove.string())); |
| 72 | |
| 73 | } |
| 74 | |
| 75 | void DatabaseFactory::validate(const ASTCreateQuery & create_query) const |
| 76 | { |
no test coverage detected