Skip to content

Commit 493858b

Browse files
Backport #94892 to 25.11: Fix crash in clearDirectory on concurrent removal of delete_tmp_ directory
1 parent 7b5264c commit 493858b

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
@@ -727,6 +727,15 @@ void DataPartStorageOnDiskBase::remove(
727727
disk->removeSharedRecursive(
728728
fs::path(to) / "", !can_remove_description->can_remove_anything, can_remove_description->files_not_to_remove);
729729
}
730+
catch (const fs::filesystem_error & e)
731+
{
732+
if (e.code() == std::errc::no_such_file_or_directory)
733+
{
734+
/// If the directory was already removed (e.g. by clearOldTemporaryDirectories), nothing to do.
735+
}
736+
else
737+
throw;
738+
}
730739
catch (...)
731740
{
732741
LOG_ERROR(
@@ -860,7 +869,19 @@ void DataPartStorageOnDiskBase::clearDirectory(
860869
if (checksums.empty() || incomplete_temporary_part)
861870
{
862871
/// If the part is not completely written, we cannot use fast path by listing files.
863-
disk->removeSharedRecursive(fs::path(dir) / "", !can_remove_shared_data, names_not_to_remove);
872+
try
873+
{
874+
disk->removeSharedRecursive(fs::path(dir) / "", !can_remove_shared_data, names_not_to_remove);
875+
}
876+
catch (const fs::filesystem_error & e)
877+
{
878+
if (e.code() == std::errc::no_such_file_or_directory)
879+
{
880+
/// If the directory was already removed (e.g. by clearOldTemporaryDirectories), nothing to do.
881+
}
882+
else
883+
throw;
884+
}
864885
return;
865886
}
866887

@@ -891,7 +912,19 @@ void DataPartStorageOnDiskBase::clearDirectory(
891912
/// Recursive directory removal does many excessive "stat" syscalls under the hood.
892913

893914
LOG_ERROR(log, "Cannot quickly remove directory {} by removing files; fallback to recursive removal. Reason: {}", fullPath(disk, dir), getCurrentExceptionMessage(false));
894-
disk->removeSharedRecursive(fs::path(dir) / "", !can_remove_shared_data, names_not_to_remove);
915+
try
916+
{
917+
disk->removeSharedRecursive(fs::path(dir) / "", !can_remove_shared_data, names_not_to_remove);
918+
}
919+
catch (const fs::filesystem_error & e)
920+
{
921+
if (e.code() == std::errc::no_such_file_or_directory)
922+
{
923+
/// If the directory was already removed (e.g. by clearOldTemporaryDirectories), nothing to do.
924+
}
925+
else
926+
throw;
927+
}
895928
}
896929
}
897930

0 commit comments

Comments
 (0)