Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.9k
[pipelineX](runtime filter) Fix task timeout caused by runtime filter#33332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
f110be6336c4acf3816a26d263a429f6c81226cee4372072f7f65d65File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -91,14 +91,6 @@ std::string ScanOperator::debug_string() const { | ||
| return; \ | ||
| } | ||
| template <typename Derived> | ||
| ScanLocalState<Derived>::ScanLocalState(RuntimeState* state, OperatorXBase* parent) | ||
| : ScanLocalStateBase(state, parent) { | ||
| _filter_dependency = std::make_shared<RuntimeFilterDependency>( | ||
| parent->operator_id(), parent->node_id(), parent->get_name() + "_FILTER_DEPENDENCY", | ||
| state->get_query_ctx()); | ||
| } | ||
| template <typename Derived> | ||
| bool ScanLocalState<Derived>::ready_to_read() { | ||
| return !_scanner_ctx->empty_in_queue(0); | ||
| @@ -133,7 +125,8 @@ Status ScanLocalState<Derived>::init(RuntimeState* state, LocalStateInfo& info) | ||
| } | ||
| // init profile for runtime filter | ||
| RuntimeFilterConsumer::_init_profile(profile()); | ||
| init_runtime_filter_dependency(_filter_dependency.get()); | ||
| init_runtime_filter_dependency(_filter_dependencies, p.operator_id(), p.node_id(), | ||
| p.get_name() + "_FILTER_DEPENDENCY"); | ||
| // 1: running at not pipeline mode will init profile. | ||
| // 2: the scan node should create scanner at pipeline mode will init profile. | ||
| @@ -156,7 +149,7 @@ Status ScanLocalState<Derived>::open(RuntimeState* state) { | ||
| if (_opened) { | ||
| return Status::OK(); | ||
| } | ||
| RETURN_IF_ERROR(_acquire_runtime_filter()); | ||
| RETURN_IF_ERROR(_acquire_runtime_filter(true)); | ||
| RETURN_IF_ERROR(_process_conjuncts()); | ||
| auto status = _eos ? Status::OK() : _prepare_scanners(); | ||
| @@ -1407,7 +1400,11 @@ Status ScanLocalState<Derived>::close(RuntimeState* state) { | ||
| return Status::OK(); | ||
| } | ||
| COUNTER_UPDATE(exec_time_counter(), _scan_dependency->watcher_elapse_time()); | ||
| COUNTER_UPDATE(exec_time_counter(), _filter_dependency->watcher_elapse_time()); | ||
| int64_t rf_time = 0; | ||
| for (auto& dep : _filter_dependencies) { | ||
| rf_time += dep->watcher_elapse_time(); | ||
| } | ||
| COUNTER_UPDATE(exec_time_counter(), rf_time); | ||
Gabriel39 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| SCOPED_TIMER(_close_timer); | ||
| SCOPED_TIMER(exec_time_counter()); | ||
| @@ -1416,7 +1413,7 @@ Status ScanLocalState<Derived>::close(RuntimeState* state) { | ||
| } | ||
| std::list<std::shared_ptr<vectorized::ScannerDelegate>> {}.swap(_scanners); | ||
| COUNTER_SET(_wait_for_dependency_timer, _scan_dependency->watcher_elapse_time()); | ||
| COUNTER_SET(_wait_for_rf_timer, _filter_dependency->watcher_elapse_time()); | ||
| COUNTER_SET(_wait_for_rf_timer, rf_time); | ||
| return PipelineXLocalState<>::close(state); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -89,20 +89,6 @@ Dependency* FinishDependency::is_blocked_by(PipelineXTask* task) { | ||
| return ready ? nullptr : this; | ||
| } | ||
| Dependency* RuntimeFilterDependency::is_blocked_by(PipelineXTask* task) { | ||
| if (!_blocked_by_rf) { | ||
| return nullptr; | ||
| } | ||
| std::unique_lock<std::mutex> lc(_task_lock); | ||
| if (*_blocked_by_rf && !_is_cancelled()) { | ||
| if (LIKELY(task)) { | ||
| _add_block_task(task); | ||
| } | ||
| return this; | ||
| } | ||
| return nullptr; | ||
| } | ||
| std::string Dependency::debug_string(int indentation_level) { | ||
| fmt::memory_buffer debug_string_buffer; | ||
| fmt::format_to(debug_string_buffer, | ||
| @@ -114,82 +100,60 @@ std::string Dependency::debug_string(int indentation_level) { | ||
| std::string RuntimeFilterDependency::debug_string(int indentation_level) { | ||
| fmt::memory_buffer debug_string_buffer; | ||
| fmt::format_to(debug_string_buffer, | ||
| "{}{}: id={}, block task = {}, ready={}, _filters = {}, _blocked_by_rf = {}", | ||
| std::string(indentation_level * 2, ' '), _name, _node_id, _blocked_task.size(), | ||
| _ready, _filters.load(), _blocked_by_rf ? _blocked_by_rf->load() : false); | ||
| fmt::format_to(debug_string_buffer, "{}, runtime filter: {}", | ||
| Dependency::debug_string(indentation_level), _runtime_filter->formatted_state()); | ||
| return fmt::to_string(debug_string_buffer); | ||
| } | ||
| bool RuntimeFilterTimer::has_ready() { | ||
| std::unique_lock<std::mutex> lc(_lock); | ||
| return _is_ready; | ||
| Dependency* RuntimeFilterDependency::is_blocked_by(PipelineXTask* task) { | ||
| std::unique_lock<std::mutex> lc(_task_lock); | ||
| auto ready = _ready.load() || _is_cancelled(); | ||
| if (!ready && task) { | ||
| _add_block_task(task); | ||
| task->_blocked_dep = this; | ||
| } | ||
| return ready ? nullptr : this; | ||
| } | ||
| void RuntimeFilterTimer::call_timeout() { | ||
| std::unique_lock<std::mutex> lc(_lock); | ||
| if (_call_ready) { | ||
| return; | ||
| } | ||
| _call_timeout = true; | ||
| if (_parent) { | ||
| _parent->sub_filters(_filter_id); | ||
| } | ||
| _parent->set_ready(); | ||
| } | ||
| void RuntimeFilterTimer::call_ready() { | ||
| std::unique_lock<std::mutex> lc(_lock); | ||
| if (_call_timeout) { | ||
| return; | ||
| } | ||
| _call_ready = true; | ||
| if (_parent) { | ||
| _parent->sub_filters(_filter_id); | ||
| } | ||
| _is_ready = true; | ||
| } | ||
| void RuntimeFilterTimer::call_has_ready() { | ||
| std::unique_lock<std::mutex> lc(_lock); | ||
| DCHECK(!_call_timeout); | ||
| if (!_call_ready) { | ||
| _parent->sub_filters(_filter_id); | ||
| } | ||
| _parent->set_ready(); | ||
| } | ||
| void RuntimeFilterDependency::add_filters(IRuntimeFilter* runtime_filter) { | ||
| const auto filter_id = runtime_filter->filter_id(); | ||
| ; | ||
| _filters++; | ||
| _filter_ready_map[filter_id] = false; | ||
| int64_t registration_time = runtime_filter->registration_time(); | ||
| int32 wait_time_ms = runtime_filter->wait_time_ms(); | ||
| auto filter_timer = std::make_shared<RuntimeFilterTimer>( | ||
| filter_id, registration_time, wait_time_ms, | ||
| std::dynamic_pointer_cast<RuntimeFilterDependency>(shared_from_this())); | ||
| runtime_filter->set_filter_timer(filter_timer); | ||
| ExecEnv::GetInstance()->runtime_filter_timer_queue()->push_filter_timer(filter_timer); | ||
| } | ||
| void RuntimeFilterTimerQueue::start() { | ||
yiguolei marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| while (!_stop) { | ||
yiguolei marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| std::unique_lock<std::mutex> lk(cv_m); | ||
| void RuntimeFilterDependency::sub_filters(int id) { | ||
| std::vector<PipelineXTask*> local_block_task {}; | ||
| { | ||
| std::lock_guard<std::mutex> lk(_task_lock); | ||
| if (!_filter_ready_map[id]) { | ||
| _filter_ready_map[id] = true; | ||
| _filters--; | ||
| while (_que.empty() && !_stop) { | ||
| cv.wait_for(lk, std::chrono::seconds(3), [this] { return !_que.empty() || _stop; }); | ||
| } | ||
| if (_stop) { | ||
| break; | ||
| } | ||
| if (_filters == 0) { | ||
| _watcher.stop(); | ||
| { | ||
| *_blocked_by_rf = false; | ||
| local_block_task.swap(_blocked_task); | ||
| { | ||
| std::unique_lock<std::mutex> lc(_que_lock); | ||
| std::list<std::shared_ptr<pipeline::RuntimeFilterTimer>> new_que; | ||
| for (auto& it : _que) { | ||
| if (it.use_count() == 1) { | ||
| // `use_count == 1` means this runtime filter has been released | ||
| } else if (it->_parent->is_blocked_by(nullptr)) { | ||
| // This means runtime filter is not ready, so we call timeout or continue to poll this timer. | ||
| int64_t ms_since_registration = MonotonicMillis() - it->registration_time(); | ||
| if (ms_since_registration > it->wait_time_ms()) { | ||
| it->call_timeout(); | ||
| } else { | ||
| new_que.push_back(std::move(it)); | ||
| } | ||
| } | ||
| } | ||
| new_que.swap(_que); | ||
| } | ||
| std::this_thread::sleep_for(std::chrono::milliseconds(interval)); | ||
| } | ||
| for (auto* task : local_block_task) { | ||
| task->wake_up(); | ||
| } | ||
| _shutdown = true; | ||
| } | ||
| void LocalExchangeSharedState::sub_running_sink_operators() { | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我们为啥要把not_Ready 状态更改为 TIME_OUT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
执行到这里的时候rf状态要么是timeout要么是ready,ready的话状态是已经被更新过的,所以这个地方是timeout。更新状态是因为要在profile显示