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

Function loadDatabase

src/Interpreters/loadMetadata.cpp:102–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100}
101
102static void loadDatabase(
103 ContextMutablePtr context,
104 const String & database,
105 const fs::path & metadata_file_path,
106 bool force_restore_data)
107{
108 /// If it is already loaded.
109 if (DatabaseCatalog::instance().isDatabaseExist(database))
110 return;
111
112 String database_attach_query;
113
114 auto default_db_disk = Context::getGlobalContextInstance()->getDatabaseDisk();
115 if (default_db_disk->existsFile(metadata_file_path))
116 {
117 /// There is .sql file with database creation statement.
118 database_attach_query = readMetadataFile(default_db_disk, metadata_file_path);
119 }
120 else
121 {
122 /// It's first server run and we need create default and system databases.
123 /// .sql file with database engine will be written for CREATE query.
124 database_attach_query = "CREATE DATABASE " + backQuoteIfNeed(database);
125 }
126
127 try
128 {
129 executeCreateQuery(database_attach_query, context, database, metadata_file_path, /* create */ true, force_restore_data);
130 }
131 catch (Exception & e)
132 {
133 e.addMessage(fmt::format("while loading database {} from file {}", backQuote(database), metadata_file_path));
134 throw;
135 }
136}
137
138static void checkUnsupportedVersion(ContextMutablePtr, const String & database_name)
139{

Callers 3

loadMetadataFunction · 0.85
loadSystemDatabaseImplFunction · 0.85

Calls 9

readMetadataFileFunction · 0.85
backQuoteIfNeedFunction · 0.85
executeCreateQueryFunction · 0.85
backQuoteFunction · 0.85
isDatabaseExistMethod · 0.80
getDatabaseDiskMethod · 0.80
formatFunction · 0.70
existsFileMethod · 0.45
addMessageMethod · 0.45

Tested by

no test coverage detected