From d34a3208f79b2fcf938c830773977e7d8de8a35b Mon Sep 17 00:00:00 2001 From: Julia Kartseva Date: Mon, 4 Nov 2024 23:09:37 +0000 Subject: [PATCH] fix transaction rollback when file write finalize fails --- ...dataStorageFromPlainObjectStorageOperations.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Disks/ObjectStorages/MetadataStorageFromPlainObjectStorageOperations.cpp b/src/Disks/ObjectStorages/MetadataStorageFromPlainObjectStorageOperations.cpp index 62015631aa5..3dac1df2ff8 100644 --- a/src/Disks/ObjectStorages/MetadataStorageFromPlainObjectStorageOperations.cpp +++ b/src/Disks/ObjectStorages/MetadataStorageFromPlainObjectStorageOperations.cpp @@ -97,20 +97,22 @@ void MetadataStorageFromPlainObjectStorageCreateDirectoryOperation::undo(std::un { auto metadata_object_key = createMetadataObjectKey(object_key_prefix, metadata_key_prefix); - if (write_finalized) + if (write_finalized || write_created) { const auto base_path = path.parent_path(); + size_t erase_count = 0; { std::lock_guard lock(path_map.mutex); - path_map.map.erase(base_path); + erase_count = path_map.map.erase(base_path); + } + if (erase_count) + { + auto metric = object_storage->getMetadataStorageMetrics().directory_map_size; + CurrentMetrics::sub(metric, erase_count); } - auto metric = object_storage->getMetadataStorageMetrics().directory_map_size; - CurrentMetrics::sub(metric, 1); object_storage->removeObjectIfExists(StoredObject(metadata_object_key.serialize(), path / PREFIX_PATH_FILE_NAME)); } - else if (write_created) - object_storage->removeObjectIfExists(StoredObject(metadata_object_key.serialize(), path / PREFIX_PATH_FILE_NAME)); } MetadataStorageFromPlainObjectStorageMoveDirectoryOperation::MetadataStorageFromPlainObjectStorageMoveDirectoryOperation(