Make the error message about broken parts more useful.

This commit is contained in:
Vitaly Baranov 2024-07-19 19:11:07 +02:00
parent 38126bb436
commit 5bea6751e0
2 changed files with 19 additions and 2 deletions

View File

@ -739,10 +739,25 @@ void IMergeTreeDataPart::loadColumnsChecksumsIndexes(bool require_columns_checks
}
catch (...)
{
/// Don't scare people with broken part error
/// Don't scare people with broken part error if it's retryable.
if (!isRetryableException(std::current_exception()))
{
LOG_ERROR(storage.log, "Part {} is broken and needs manual correction", getDataPartStorage().getFullPath());
if (Exception * e = exception_cast<Exception *>(std::current_exception()))
{
/// Probably there is something wrong with files of this part.
/// So it can be helpful to add to the error message some information about those files.
String files_in_part;
for (auto it = getDataPartStorage().iterate(); it->isValid(); it->next())
files_in_part += fmt::format("{}{} ({} bytes)", (files_in_part.empty() ? "" : ", "), it->name(), getDataPartStorage().getFileSize(it->name()));
if (!files_in_part.empty())
e->addMessage("Part contains files: {}", files_in_part);
if (isEmpty())
e->addMessage("Part is empty");
}
}
// There could be conditions that data part to be loaded is broken, but some of meta infos are already written
// into metadata before exception, need to clean them all.
metadata_manager->deleteAll(/*include_projection*/ true);

View File

@ -5634,9 +5634,11 @@ void MergeTreeData::restorePartFromBackup(std::shared_ptr<RestoredPartsHolder> r
String part_name = part_info.getPartNameAndCheckFormat(format_version);
auto backup = restored_parts_holder->getBackup();
/// Find all files of this part in the backup.
Strings filenames = backup->listFiles(part_path_in_backup, /* recursive= */ true);
/// Calculate the total size of the part.
UInt64 total_size_of_part = 0;
Strings filenames = backup->listFiles(part_path_in_backup, /* recursive= */ true);
fs::path part_path_in_backup_fs = part_path_in_backup;
for (const String & filename : filenames)
total_size_of_part += backup->getFileSize(part_path_in_backup_fs / filename);