Merge pull request #13557 from ClickHouse/load-metadata-better-error-messages

Better error messages in loadMetadata
This commit is contained in:
alexey-milovidov 2020-08-10 16:06:15 +03:00 committed by GitHub
commit dbccea1d92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 4 deletions

View File

@ -142,7 +142,6 @@ void DatabaseOrdinary::loadStoredObjects(Context & context, bool has_force_resto
} }
}; };
iterateMetadataFiles(context, process_metadata); iterateMetadataFiles(context, process_metadata);
size_t total_tables = file_names.size() - total_dictionaries; size_t total_tables = file_names.size() - total_dictionaries;

View File

@ -100,7 +100,6 @@ BlockIO InterpreterCreateQuery::createDatabase(ASTCreateQuery & create)
throw Exception("Database " + database_name + " already exists.", ErrorCodes::DATABASE_ALREADY_EXISTS); throw Exception("Database " + database_name + " already exists.", ErrorCodes::DATABASE_ALREADY_EXISTS);
} }
/// Will write file with database metadata, if needed. /// Will write file with database metadata, if needed.
String database_name_escaped = escapeForFileName(database_name); String database_name_escaped = escapeForFileName(database_name);
fs::path metadata_path = fs::canonical(context.getPath()); fs::path metadata_path = fs::canonical(context.getPath());

View File

@ -70,8 +70,16 @@ static void loadDatabase(
database_attach_query = "CREATE DATABASE " + backQuoteIfNeed(database); database_attach_query = "CREATE DATABASE " + backQuoteIfNeed(database);
} }
executeCreateQuery(database_attach_query, context, database, try
database_metadata_file, force_restore_data); {
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) void loadMetadata(Context & context, const String & default_database_name)
{ {
Poco::Logger * log = &Poco::Logger::get("loadMetadata");
String path = context.getPath() + "metadata"; String path = context.getPath() + "metadata";
/** There may exist 'force_restore_data' file, that means, /** 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) if (db_name != SYSTEM_DATABASE)
databases.emplace(unescapeForFileName(db_name), path + "/" + db_name); 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; continue;
} }