Merge pull request #30074 from azat/move-partition-race-fix

Fix race between MOVE PARTITION and merges/mutations for MergeTree
This commit is contained in:
Anton Popov 2021-10-13 14:15:23 +03:00 committed by GitHub
commit 108aafcd6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1447,6 +1447,11 @@ void StorageMergeTree::replacePartitionFrom(const StoragePtr & source_table, con
void StorageMergeTree::movePartitionToTable(const StoragePtr & dest_table, const ASTPtr & partition, ContextPtr local_context)
{
/// MOVE PARTITION cannot be run in parallel with merges/mutations,
/// since otherwise there can be some merge/mutation in progress,
/// that will be created in the source table after MOVE PARTITION.
std::unique_lock background_lock(currently_processing_in_background_mutex);
auto lock1 = lockForShare(local_context->getCurrentQueryId(), local_context->getSettingsRef().lock_acquire_timeout);
auto lock2 = dest_table->lockForShare(local_context->getCurrentQueryId(), local_context->getSettingsRef().lock_acquire_timeout);
@ -1509,7 +1514,6 @@ void StorageMergeTree::movePartitionToTable(const StoragePtr & dest_table, const
transaction.commit(&lock);
}
clearOldMutations(true);
clearOldPartsFromFilesystem();
PartLog::addNewParts(getContext(), dst_parts, watch.elapsed());