Merge pull request #47310 from ClickHouse/vdimir/fix_transaction_read_only

Fix MergeTreeTransaction::isReadOnly
This commit is contained in:
Alexander Tokmakov 2023-03-08 18:02:19 +03:00 committed by GitHub
commit ecab007486
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -168,6 +168,8 @@ void MergeTreeTransaction::addMutation(const StoragePtr & table, const String &
bool MergeTreeTransaction::isReadOnly() const
{
std::lock_guard lock{mutex};
if (finalized)
return is_read_only;
chassert((creating_parts.empty() && removing_parts.empty() && mutations.empty()) == storages.empty());
return storages.empty();
}
@ -318,6 +320,11 @@ bool MergeTreeTransaction::rollback() noexcept
void MergeTreeTransaction::afterFinalize()
{
std::lock_guard lock{mutex};
chassert((creating_parts.empty() && removing_parts.empty() && mutations.empty()) == storages.empty());
/// Remember if it was read-only transaction before we clear storages
is_read_only = storages.empty();
/// Release shared pointers just in case
storages.clear();
mutations.clear();

View File

@ -78,6 +78,9 @@ private:
bool finalized TSA_GUARDED_BY(mutex) = false;
/// Indicates if transaction was read-only before `afterFinalize`
bool is_read_only TSA_GUARDED_BY(mutex) = false;
/// Lists of changes made by transaction
std::unordered_set<StoragePtr> storages TSA_GUARDED_BY(mutex);
DataPartsVector creating_parts TSA_GUARDED_BY(mutex);