mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
try executing other mutations immediately after KILL MUTATION [#CLICKHOUSE-3912]
This commit is contained in:
parent
1bf4174ec1
commit
8e437b191e
@ -560,6 +560,7 @@ void ReplicatedMergeTreeQueue::updateMutations(zkutil::ZooKeeperPtr zookeeper, C
|
||||
|
||||
/// Compare with the local state, delete obsolete entries and determine which new entries to load.
|
||||
Strings entries_to_load;
|
||||
bool some_active_mutations_were_killed = false;
|
||||
{
|
||||
std::lock_guard state_lock(state_mutex);
|
||||
|
||||
@ -568,7 +569,14 @@ void ReplicatedMergeTreeQueue::updateMutations(zkutil::ZooKeeperPtr zookeeper, C
|
||||
const ReplicatedMergeTreeMutationEntry & entry = *it->second.entry;
|
||||
if (!entries_in_zk_set.count(entry.znode_name))
|
||||
{
|
||||
LOG_DEBUG(log, "Removing obsolete mutation " + entry.znode_name + " from local state.");
|
||||
if (!it->second.is_done)
|
||||
{
|
||||
LOG_DEBUG(log, "Removing killed mutation " + entry.znode_name + " from local state.");
|
||||
some_active_mutations_were_killed = true;
|
||||
}
|
||||
else
|
||||
LOG_DEBUG(log, "Removing obsolete mutation " + entry.znode_name + " from local state.");
|
||||
|
||||
for (const auto & partition_and_block_num : entry.block_numbers)
|
||||
{
|
||||
auto & in_partition = mutations_by_partition[partition_and_block_num.first];
|
||||
@ -590,6 +598,9 @@ void ReplicatedMergeTreeQueue::updateMutations(zkutil::ZooKeeperPtr zookeeper, C
|
||||
}
|
||||
}
|
||||
|
||||
if (some_active_mutations_were_killed)
|
||||
storage.queue_task_handle->wake();
|
||||
|
||||
if (!entries_to_load.empty())
|
||||
{
|
||||
LOG_INFO(log, "Loading " + toString(entries_to_load.size()) + " mutation entries: "
|
||||
@ -660,23 +671,32 @@ ReplicatedMergeTreeMutationEntryPtr ReplicatedMergeTreeQueue::removeMutation(
|
||||
if (rc == Coordination::ZOK)
|
||||
LOG_DEBUG(log, "Removed mutation " + mutation_id + " from ZooKeeper.");
|
||||
|
||||
std::lock_guard state_lock(state_mutex);
|
||||
|
||||
auto it = mutations_by_znode.find(mutation_id);
|
||||
if (it == mutations_by_znode.end())
|
||||
return nullptr;
|
||||
|
||||
auto entry = it->second.entry;
|
||||
for (const auto & partition_and_block_num : entry->block_numbers)
|
||||
ReplicatedMergeTreeMutationEntryPtr entry;
|
||||
bool mutation_was_active = false;
|
||||
{
|
||||
auto & in_partition = mutations_by_partition[partition_and_block_num.first];
|
||||
in_partition.erase(partition_and_block_num.second);
|
||||
if (in_partition.empty())
|
||||
mutations_by_partition.erase(partition_and_block_num.first);
|
||||
std::lock_guard state_lock(state_mutex);
|
||||
|
||||
auto it = mutations_by_znode.find(mutation_id);
|
||||
if (it == mutations_by_znode.end())
|
||||
return nullptr;
|
||||
|
||||
mutation_was_active = !it->second.is_done;
|
||||
|
||||
entry = it->second.entry;
|
||||
for (const auto & partition_and_block_num : entry->block_numbers)
|
||||
{
|
||||
auto & in_partition = mutations_by_partition[partition_and_block_num.first];
|
||||
in_partition.erase(partition_and_block_num.second);
|
||||
if (in_partition.empty())
|
||||
mutations_by_partition.erase(partition_and_block_num.first);
|
||||
}
|
||||
|
||||
mutations_by_znode.erase(it);
|
||||
LOG_DEBUG(log, "Removed mutation " + entry->znode_name + " from local state.");
|
||||
}
|
||||
|
||||
mutations_by_znode.erase(it);
|
||||
LOG_DEBUG(log, "Removed mutation " + entry->znode_name + " from local state.");
|
||||
if (mutation_was_active)
|
||||
storage.queue_task_handle->wake();
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
@ -410,6 +410,10 @@ CancellationCode StorageMergeTree::killMutation(const String & mutation_id)
|
||||
global_context.getMergeList().cancelPartMutations({}, to_kill->block_number);
|
||||
to_kill->removeFile();
|
||||
LOG_TRACE(log, "Cancelled part mutations and removed mutation file " << mutation_id);
|
||||
|
||||
/// Maybe there is another mutation that was blocked by the killed one. Try to execute it immediately.
|
||||
background_task_handle->wake();
|
||||
|
||||
return CancellationCode::CancelSent;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user