Merge pull request #11691 from ClickHouse/fix-race-condition-system-sync-replicas

Fix race condition in SYSTEM SYNC REPLICA
This commit is contained in:
alesapin 2020-06-16 13:29:18 +03:00 committed by GitHub
commit 0cb14c836c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 5 deletions

View File

@ -646,7 +646,7 @@ void ReplicatedMergeTreeQueue::updateMutations(zkutil::ZooKeeperPtr zookeeper, C
}
}
if (some_active_mutations_were_killed)
if (some_active_mutations_were_killed && storage.queue_task_handle)
storage.queue_task_handle->signalReadyToRun();
if (!entries_to_load.empty())
@ -759,7 +759,7 @@ ReplicatedMergeTreeMutationEntryPtr ReplicatedMergeTreeQueue::removeMutation(
LOG_DEBUG(log, "Removed mutation {} from local state.", entry->znode_name);
}
if (mutation_was_active)
if (mutation_was_active && storage.queue_task_handle)
storage.queue_task_handle->signalReadyToRun();
return entry;

View File

@ -5660,9 +5660,16 @@ bool StorageReplicatedMergeTree::waitForShrinkingQueueSize(size_t queue_size, UI
/// Let's fetch new log entries firstly
queue.pullLogsToQueue(getZooKeeper());
/// This is significant, because the execution of this task could be delayed at BackgroundPool.
/// And we force it to be executed.
queue_task_handle->signalReadyToRun();
{
auto lock = queue.lockQueue();
if (!queue_task_handle)
return false;
/// This is significant, because the execution of this task could be delayed at BackgroundPool.
/// And we force it to be executed.
queue_task_handle->signalReadyToRun();
}
Poco::Event target_size_event;
auto callback = [&target_size_event, queue_size] (size_t new_queue_size)

View File

@ -0,0 +1,28 @@
#!/usr/bin/env bash
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
. $CURDIR/../shell_config.sh
set -e
$CLICKHOUSE_CLIENT --query "DROP TABLE IF EXISTS r;"
function thread1()
{
while true; do $CLICKHOUSE_CLIENT -n --query "CREATE TABLE r (x UInt64) ENGINE = ReplicatedMergeTree('/test/table', 'r') ORDER BY x; DROP TABLE r;"; done
}
function thread2()
{
while true; do $CLICKHOUSE_CLIENT --query "SYSTEM SYNC REPLICA r" 2>/dev/null; done
}
export -f thread1
export -f thread2
timeout 10 bash -c thread1 &
timeout 10 bash -c thread2 &
wait
$CLICKHOUSE_CLIENT --query "DROP TABLE IF EXISTS r;"