Skip to content

Commit ff72c30

Browse files
Backport #94892 to 25.8: Fix crash in clearDirectory on concurrent removal of delete_tmp_ directory
1 parent cfacd52 commit ff72c30

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

src/Storages/MergeTree/DataPartStorageOnDiskBase.cpp

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,15 @@ void DataPartStorageOnDiskBase::remove(
728728
disk->removeSharedRecursive(
729729
fs::path(to) / "", !can_remove_description->can_remove_anything, can_remove_description->files_not_to_remove);
730730
}
731+
catch (const fs::filesystem_error & e)
732+
{
733+
if (e.code() == std::errc::no_such_file_or_directory)
734+
{
735+
/// If the directory was already removed (e.g. by clearOldTemporaryDirectories), nothing to do.
736+
}
737+
else
738+
throw;
739+
}
731740
catch (...)
732741
{
733742
LOG_ERROR(
@@ -861,7 +870,19 @@ void DataPartStorageOnDiskBase::clearDirectory(
861870
if (checksums.empty() || incomplete_temporary_part)
862871
{
863872
/// If the part is not completely written, we cannot use fast path by listing files.
864-
disk->removeSharedRecursive(fs::path(dir) / "", !can_remove_shared_data, names_not_to_remove);
873+
try
874+
{
875+
disk->removeSharedRecursive(fs::path(dir) / "", !can_remove_shared_data, names_not_to_remove);
876+
}
877+
catch (const fs::filesystem_error & e)
878+
{
879+
if (e.code() == std::errc::no_such_file_or_directory)
880+
{
881+
/// If the directory was already removed (e.g. by clearOldTemporaryDirectories), nothing to do.
882+
}
883+
else
884+
throw;
885+
}
865886
return;
866887
}
867888

@@ -897,7 +918,19 @@ void DataPartStorageOnDiskBase::clearDirectory(
897918
/// Recursive directory removal does many excessive "stat" syscalls under the hood.
898919

899920
LOG_ERROR(log, "Cannot quickly remove directory {} by removing files; fallback to recursive removal. Reason: {}", fullPath(disk, dir), getCurrentExceptionMessage(false));
900-
disk->removeSharedRecursive(fs::path(dir) / "", !can_remove_shared_data, names_not_to_remove);
921+
try
922+
{
923+
disk->removeSharedRecursive(fs::path(dir) / "", !can_remove_shared_data, names_not_to_remove);
924+
}
925+
catch (const fs::filesystem_error & e)
926+
{
927+
if (e.code() == std::errc::no_such_file_or_directory)
928+
{
929+
/// If the directory was already removed (e.g. by clearOldTemporaryDirectories), nothing to do.
930+
}
931+
else
932+
throw;
933+
}
901934
}
902935
}
903936

0 commit comments

Comments
 (0)