diff --git a/src/Databases/DatabaseOrdinary.cpp b/src/Databases/DatabaseOrdinary.cpp index 613a3bee66a..8ff06f04f91 100644 --- a/src/Databases/DatabaseOrdinary.cpp +++ b/src/Databases/DatabaseOrdinary.cpp @@ -142,7 +142,6 @@ void DatabaseOrdinary::loadStoredObjects(Context & context, bool has_force_resto } }; - iterateMetadataFiles(context, process_metadata); size_t total_tables = file_names.size() - total_dictionaries; diff --git a/src/Interpreters/InterpreterCreateQuery.cpp b/src/Interpreters/InterpreterCreateQuery.cpp index a0b5c51f323..6cd9eddbf56 100644 --- a/src/Interpreters/InterpreterCreateQuery.cpp +++ b/src/Interpreters/InterpreterCreateQuery.cpp @@ -100,7 +100,6 @@ BlockIO InterpreterCreateQuery::createDatabase(ASTCreateQuery & create) throw Exception("Database " + database_name + " already exists.", ErrorCodes::DATABASE_ALREADY_EXISTS); } - /// Will write file with database metadata, if needed. String database_name_escaped = escapeForFileName(database_name); fs::path metadata_path = fs::canonical(context.getPath()); diff --git a/src/Interpreters/loadMetadata.cpp b/src/Interpreters/loadMetadata.cpp index 0bd97252090..779a3d21ffc 100644 --- a/src/Interpreters/loadMetadata.cpp +++ b/src/Interpreters/loadMetadata.cpp @@ -70,8 +70,16 @@ static void loadDatabase( database_attach_query = "CREATE DATABASE " + backQuoteIfNeed(database); } - executeCreateQuery(database_attach_query, context, database, - database_metadata_file, force_restore_data); + try + { + executeCreateQuery(database_attach_query, context, database, + database_metadata_file, force_restore_data); + } + catch (Exception & e) + { + e.addMessage(fmt::format("while loading database {} from path {}", backQuote(database), database_path)); + throw; + } } @@ -80,6 +88,8 @@ static void loadDatabase( void loadMetadata(Context & context, const String & default_database_name) { + Poco::Logger * log = &Poco::Logger::get("loadMetadata"); + String path = context.getPath() + "metadata"; /** There may exist 'force_restore_data' file, that means, @@ -106,6 +116,22 @@ void loadMetadata(Context & context, const String & default_database_name) if (db_name != SYSTEM_DATABASE) databases.emplace(unescapeForFileName(db_name), path + "/" + db_name); } + + /// Temporary fails may be left from previous server runs. + if (endsWith(it.name(), ".tmp")) + { + LOG_WARNING(log, "Removing temporary file {}", it->path()); + try + { + it->remove(); + } + catch (...) + { + /// It does not prevent server to startup. + tryLogCurrentException(log); + } + } + continue; }