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

Function cckMetadataPathForOrdinary

src/Databases/DatabaseFactory.cpp:37–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35}
36
37static 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
75void DatabaseFactory::validate(const ASTCreateQuery & create_query) const
76{

Callers 1

getMethod · 0.85

Calls 10

getDatabaseDiskMethod · 0.80
parent_pathMethod · 0.80
ExceptionClass · 0.50
quoteStringFunction · 0.50
isSymlinkSupportedMethod · 0.45
getDatabaseMethod · 0.45
isSymlinkMethod · 0.45
readSymlinkMethod · 0.45
emptyMethod · 0.45
stringMethod · 0.45

Tested by

no test coverage detected