From 84584659b68d5c0b26df8926bcdbdce24a8dac29 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Mon, 10 Aug 2020 04:06:06 +0300 Subject: [PATCH 1/2] Better error messages --- src/Interpreters/loadMetadata.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Interpreters/loadMetadata.cpp b/src/Interpreters/loadMetadata.cpp index 0bd97252090..712e98a4692 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 file {}", backQuote(database), database_path)); + throw; + } } From 0c15f3b6c8a50f5bdac8e9cad1d112a5aff96d9b Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Mon, 10 Aug 2020 05:58:08 +0300 Subject: [PATCH 2/2] Allow server to startup if there are leftovers from unsuccessfull database creations --- src/Databases/DatabaseOrdinary.cpp | 1 - src/Interpreters/InterpreterCreateQuery.cpp | 1 - src/Interpreters/loadMetadata.cpp | 20 +++++++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) 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 712e98a4692..779a3d21ffc 100644 --- a/src/Interpreters/loadMetadata.cpp +++ b/src/Interpreters/loadMetadata.cpp @@ -77,7 +77,7 @@ static void loadDatabase( } catch (Exception & e) { - e.addMessage(fmt::format("while loading database {} from file {}", backQuote(database), database_path)); + e.addMessage(fmt::format("while loading database {} from path {}", backQuote(database), database_path)); throw; } } @@ -88,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, @@ -114,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; }