MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / waitForProcessingQueue

Method waitForProcessingQueue

src/Storages/StorageReplicatedMergeTree.cpp:9861–9912  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9859}
9860
9861bool StorageReplicatedMergeTree::waitForProcessingQueue(UInt64 max_wait_milliseconds, SyncReplicaMode sync_mode, std::unordered_set<String> source_replicas)
9862{
9863 auto component_guard = Coordination::setCurrentComponent("StorageReplicatedMergeTree::waitForProcessingQueue");
9864 /// Let's fetch new log entries firstly
9865 queue.pullLogsToQueue(getZooKeeperAndAssertNotReadonly(), {}, ReplicatedMergeTreeQueue::SYNC);
9866
9867 if (sync_mode == SyncReplicaMode::PULL)
9868 return true;
9869
9870 /// This is significant, because the execution of this task could be delayed at BackgroundPool.
9871 /// And we force it to be executed.
9872 background_operations_assignee.trigger();
9873
9874 std::unordered_set<String> wait_for_ids;
9875 std::atomic_bool was_interrupted = false;
9876
9877 Poco::Event target_entry_event;
9878 auto callback = [this, &target_entry_event, &wait_for_ids, &was_interrupted, sync_mode]
9879 (size_t new_queue_size, const String * removed_log_entry_id)
9880 {
9881 if (partial_shutdown_called)
9882 {
9883 was_interrupted = true;
9884 target_entry_event.set();
9885 return;
9886 }
9887
9888 if (sync_mode == SyncReplicaMode::STRICT)
9889 {
9890 /// Wait for queue to become empty
9891 if (new_queue_size == 0)
9892 target_entry_event.set();
9893 return;
9894 }
9895
9896 if (removed_log_entry_id)
9897 wait_for_ids.erase(*removed_log_entry_id);
9898
9899 if (wait_for_ids.empty())
9900 target_entry_event.set();
9901 };
9902
9903 const auto handler = queue.addSubscriber(std::move(callback), wait_for_ids, sync_mode, source_replicas);
9904
9905 if (!target_entry_event.tryWait(max_wait_milliseconds))
9906 return false;
9907
9908 if (was_interrupted)
9909 throw Exception(ErrorCodes::ABORTED, "Shutdown is called for table");
9910
9911 return true;
9912}
9913
9914bool StorageReplicatedMergeTree::dropPartImpl(
9915 zkutil::ZooKeeperPtr & zookeeper, String part_name, LogEntry & entry, bool detach, bool throw_if_noop)

Callers 1

trySyncReplicaMethod · 0.80

Calls 9

setCurrentComponentFunction · 0.85
pullLogsToQueueMethod · 0.80
addSubscriberMethod · 0.80
ExceptionClass · 0.50
triggerMethod · 0.45
setMethod · 0.45
eraseMethod · 0.45
emptyMethod · 0.45
tryWaitMethod · 0.45

Tested by

no test coverage detected