Compare commits

...

3 Commits

Author SHA1 Message Date
Julia Kartseva
5e1d39d0e6
Merge 7dc0747355 into 4d269bd944 2024-11-13 21:22:35 +08:00
Julia Kartseva
7dc0747355 address feedback
Introduce removePathIfExists method.
2024-11-08 06:33:27 +00:00
Julia Kartseva
de18a667df fix transaction rollback when file write finalize fails 2024-11-04 23:36:21 +00:00
2 changed files with 22 additions and 19 deletions

View File

@ -57,6 +57,12 @@ struct InMemoryDirectoryPathMap
return it->second;
}
bool removePathIfExists(const std::filesystem::path & path)
{
std::lock_guard lock(mutex);
return map.erase(path) != 0;
}
mutable SharedMutex mutex;
#ifdef OS_LINUX

View File

@ -97,20 +97,20 @@ 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();
if (path_map.removePathIfExists(base_path))
{
std::lock_guard lock(path_map.mutex);
path_map.map.erase(base_path);
auto metric = object_storage->getMetadataStorageMetrics().directory_map_size;
CurrentMetrics::sub(metric, 1);
}
auto metric = object_storage->getMetadataStorageMetrics().directory_map_size;
CurrentMetrics::sub(metric, 1);
object_storage->removeObject(StoredObject(metadata_object_key.serialize(), path / PREFIX_PATH_FILE_NAME));
if (write_finalized)
object_storage->removeObject(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));
}
else if (write_created)
object_storage->removeObjectIfExists(StoredObject(metadata_object_key.serialize(), path / PREFIX_PATH_FILE_NAME));
}
MetadataStorageFromPlainObjectStorageMoveDirectoryOperation::MetadataStorageFromPlainObjectStorageMoveDirectoryOperation(
@ -249,19 +249,16 @@ void MetadataStorageFromPlainObjectStorageRemoveDirectoryOperation::execute(std:
auto metadata_object = StoredObject(/*remote_path*/ metadata_object_key.serialize(), /*local_path*/ path / PREFIX_PATH_FILE_NAME);
object_storage->removeObject(metadata_object);
if (path_map.removePathIfExists(base_path))
{
std::lock_guard lock(path_map.mutex);
auto & map = path_map.map;
map.erase(base_path);
removed = true;
auto metric = object_storage->getMetadataStorageMetrics().directory_map_size;
CurrentMetrics::sub(metric, 1);
auto event = object_storage->getMetadataStorageMetrics().directory_removed;
ProfileEvents::increment(event);
}
auto metric = object_storage->getMetadataStorageMetrics().directory_map_size;
CurrentMetrics::sub(metric, 1);
removed = true;
auto event = object_storage->getMetadataStorageMetrics().directory_removed;
ProfileEvents::increment(event);
}
void MetadataStorageFromPlainObjectStorageRemoveDirectoryOperation::undo(std::unique_lock<SharedMutex> &)