[Bug](runtimefilter) Fix concurrent bug in runtime filter #14177

For runtime filter, signal will be called by a thread which is different from the await thread. So there will be a potential race for variable is_ready
This commit is contained in:
Gabriel
2022-11-11 14:16:18 +08:00
committed by GitHub
parent 7c48168a53
commit 02a86d2215

View File

@ -1230,13 +1230,13 @@ bool IRuntimeFilter::await() {
DCHECK(is_consumer());
SCOPED_TIMER(_await_time_cost);
int64_t wait_times_ms = _state->runtime_filter_wait_time_ms();
std::unique_lock<std::mutex> lock(_inner_mutex);
if (!_is_ready) {
int64_t ms_since_registration = MonotonicMillis() - registration_time_;
int64_t ms_remaining = wait_times_ms - ms_since_registration;
if (ms_remaining <= 0) {
return _is_ready;
}
std::unique_lock<std::mutex> lock(_inner_mutex);
return _inner_cv.wait_for(lock, std::chrono::milliseconds(ms_remaining),
[this] { return this->_is_ready; });
}
@ -1245,6 +1245,7 @@ bool IRuntimeFilter::await() {
void IRuntimeFilter::signal() {
DCHECK(is_consumer());
std::unique_lock<std::mutex> lock(_inner_mutex);
_is_ready = true;
_inner_cv.notify_all();