Skip to content

Commit fb6cb19

Browse files
Backport #94892 to 25.3: Fix crash in clearDirectory on concurrent removal of delete_tmp_ directory
1 parent e4e296b commit fb6cb19

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
@@ -738,6 +738,15 @@ void DataPartStorageOnDiskBase::remove(
738738
disk->removeSharedRecursive(
739739
fs::path(to) / "", !can_remove_description->can_remove_anything, can_remove_description->files_not_to_remove);
740740
}
741+
catch (const fs::filesystem_error & e)
742+
{
743+
if (e.code() == std::errc::no_such_file_or_directory)
744+
{
745+
/// If the directory was already removed (e.g. by clearOldTemporaryDirectories), nothing to do.
746+
}
747+
else
748+
throw;
749+
}
741750
catch (...)
742751
{
743752
LOG_ERROR(
@@ -869,7 +878,19 @@ void DataPartStorageOnDiskBase::clearDirectory(
869878
if (checksums.empty() || incomplete_temporary_part)
870879
{
871880
/// If the part is not completely written, we cannot use fast path by listing files.
872-
disk->removeSharedRecursive(fs::path(dir) / "", !can_remove_shared_data, names_not_to_remove);
881+
try
882+
{
883+
disk->removeSharedRecursive(fs::path(dir) / "", !can_remove_shared_data, names_not_to_remove);
884+
}
885+
catch (const fs::filesystem_error & e)
886+
{
887+
if (e.code() == std::errc::no_such_file_or_directory)
888+
{
889+
/// If the directory was already removed (e.g. by clearOldTemporaryDirectories), nothing to do.
890+
}
891+
else
892+
throw;
893+
}
873894
return;
874895
}
875896

@@ -904,7 +925,19 @@ void DataPartStorageOnDiskBase::clearDirectory(
904925
/// Recursive directory removal does many excessive "stat" syscalls under the hood.
905926

906927
LOG_ERROR(log, "Cannot quickly remove directory {} by removing files; fallback to recursive removal. Reason: {}", fullPath(disk, dir), getCurrentExceptionMessage(false));
907-
disk->removeSharedRecursive(fs::path(dir) / "", !can_remove_shared_data, names_not_to_remove);
928+
try
929+
{
930+
disk->removeSharedRecursive(fs::path(dir) / "", !can_remove_shared_data, names_not_to_remove);
931+
}
932+
catch (const fs::filesystem_error & e)
933+
{
934+
if (e.code() == std::errc::no_such_file_or_directory)
935+
{
936+
/// If the directory was already removed (e.g. by clearOldTemporaryDirectories), nothing to do.
937+
}
938+
else
939+
throw;
940+
}
908941
}
909942
}
910943

0 commit comments

Comments
 (0)