From dcb7667808373cf760c2eed6ddba58e119e9d846 Mon Sep 17 00:00:00 2001 From: Anton Popov Date: Mon, 24 Oct 2022 15:08:51 +0000 Subject: [PATCH] share transaction for projections --- src/Storages/MergeTree/DataPartStorageOnDisk.cpp | 16 ++++++++++++++-- src/Storages/MergeTree/DataPartStorageOnDisk.h | 3 +++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Storages/MergeTree/DataPartStorageOnDisk.cpp b/src/Storages/MergeTree/DataPartStorageOnDisk.cpp index a3df17c57de..f1690a2cc59 100644 --- a/src/Storages/MergeTree/DataPartStorageOnDisk.cpp +++ b/src/Storages/MergeTree/DataPartStorageOnDisk.cpp @@ -1,4 +1,3 @@ -#include "Storages/MergeTree/IDataPartStorage.h" #include #include #include @@ -31,6 +30,16 @@ DataPartStorageOnDisk::DataPartStorageOnDisk(VolumePtr volume_, std::string root { } +DataPartStorageOnDisk::DataPartStorageOnDisk( + VolumePtr volume_, std::string root_path_, std::string part_dir_, DiskTransactionPtr transaction_) + : volume(std::move(volume_)) + , root_path(std::move(root_path_)) + , part_dir(std::move(part_dir_)) + , transaction(std::move(transaction_)) + , has_shared_transaction(transaction != nullptr) +{ +} + std::string DataPartStorageOnDisk::getFullPath() const { return fs::path(volume->getDisk()->getPath()) / root_path / part_dir / ""; @@ -53,7 +62,7 @@ std::string DataPartStorageOnDisk::getFullRootPath() const MutableDataPartStoragePtr DataPartStorageOnDisk::getProjection(const std::string & name) { - return std::make_shared(volume, std::string(fs::path(root_path) / part_dir), name); + return std::shared_ptr(new DataPartStorageOnDisk(volume, std::string(fs::path(root_path) / part_dir), name, transaction)); } DataPartStoragePtr DataPartStorageOnDisk::getProjection(const std::string & name) const @@ -822,6 +831,9 @@ void DataPartStorageOnDisk::commitTransaction() if (!transaction) throw Exception(ErrorCodes::LOGICAL_ERROR, "There is no uncommitted transaction"); + if (has_shared_transaction) + throw Exception(ErrorCodes::LOGICAL_ERROR, "Cannot commit shared transaction"); + transaction->commit(); transaction.reset(); } diff --git a/src/Storages/MergeTree/DataPartStorageOnDisk.h b/src/Storages/MergeTree/DataPartStorageOnDisk.h index f93c6a235d6..b5030f484ae 100644 --- a/src/Storages/MergeTree/DataPartStorageOnDisk.h +++ b/src/Storages/MergeTree/DataPartStorageOnDisk.h @@ -145,6 +145,9 @@ private: std::string root_path; std::string part_dir; DiskTransactionPtr transaction; + bool has_shared_transaction = false; + + DataPartStorageOnDisk(VolumePtr volume_, std::string root_path_, std::string part_dir_, DiskTransactionPtr transaction_); template void executeOperation(Op && op);