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

Function loadMetadata

src/Interpreters/loadMetadata.cpp:207–340  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

205}
206
207LoadTaskPtrs loadMetadata(ContextMutablePtr context, const String & default_database_name, bool async_load_databases)
208{
209 auto component_guard = Coordination::setCurrentComponent("loadMetadata");
210 auto default_db_disk = Context::getGlobalContextInstance()->getDatabaseDisk();
211
212 LoggerPtr log = getLogger("loadMetadata");
213
214 /// There may exist 'force_restore_data' file, which means skip safety threshold
215 /// on difference of data parts while initializing tables.
216 /// This file is immediately deleted i.e. "one-shot".
217 auto force_restore_data_flag_file = fs::path(context->getFlagsPath()) / "force_restore_data";
218 bool has_force_restore_data_flag = fs::exists(force_restore_data_flag_file);
219 if (has_force_restore_data_flag)
220 {
221 try
222 {
223 fs::remove(force_restore_data_flag_file);
224 }
225 catch (...)
226 {
227 tryLogCurrentException("Load metadata", "Can't remove force restore file to enable data sanity checks");
228 }
229 }
230
231 auto metadata_dir_path = DatabaseCatalog::getMetadataDirPath();
232
233 /// Loop over databases.
234 std::map<String, fs::path> databases;
235
236 /// Some databases don't have an .sql metadata file.
237 std::map<String, fs::path> orphan_directories_and_symlinks;
238
239 for (const auto it = default_db_disk->iterateDirectory(metadata_dir_path); it->isValid(); it->next())
240 {
241 auto sub_path = fs::path(it->path());
242 if (sub_path.filename().empty())
243 sub_path = sub_path.parent_path();
244
245 if (default_db_disk->isSymlinkSupported() && default_db_disk->isSymlink(sub_path))
246 {
247 String db_name = sub_path.filename().string();
248 if (!isSystemOrInformationSchema(db_name))
249 orphan_directories_and_symlinks.emplace(unescapeForFileName(db_name), fs::path(sub_path.string() + ".sql"));
250 continue;
251 }
252
253 if (default_db_disk->existsDirectory(sub_path))
254 continue;
255
256 if (sub_path.extension() == ".sql")
257 {
258 String db_name = sub_path.stem();
259 orphan_directories_and_symlinks.erase(unescapeForFileName(db_name));
260 if (!isSystemOrInformationSchema(db_name))
261 databases.emplace(unescapeForFileName(db_name), sub_path);
262 }
263
264 /// Temporary fails may be left from previous server runs.

Callers 5

mainMethod · 0.85
processConfigMethod · 0.85
loadAndUpdateMetadataMethod · 0.85
initializeImplMethod · 0.85

Calls 15

setCurrentComponentFunction · 0.85
unescapeForFileNameFunction · 0.85
checkUnsupportedVersionFunction · 0.85
escapeForFileNameFunction · 0.85
loadDatabaseFunction · 0.85
scheduleLoadFunction · 0.85
joinTasksFunction · 0.85
waitLoadFunction · 0.85

Tested by

no test coverage detected