Skip to content
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

Refine cancel for read thread stream #8511

Merged
merged 5 commits into from
Dec 13, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions dbms/src/Storages/DeltaMerge/ReadThread/UnorderedInputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,9 @@ class UnorderedInputStream : public IProfilingBlockInputStream
LOG_DEBUG(log, "Created, pool_id={} ref_no={}", task_pool->pool_id, ref_no);
}

~UnorderedInputStream() override
{
task_pool->decreaseUnorderedInputStreamRefCount();
LOG_DEBUG(log, "Destroy, pool_id={} ref_no={}", task_pool->pool_id, ref_no);
}
void cancel(bool /*kill*/) override { decreaseRefCount(); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did you call cancel?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

called here

void MPPTask::abortQueryExecutor()
{
if (auto query_executor = query_executor_holder.tryGet(); query_executor)
{
assert(query_executor.value());
(*query_executor)->cancel();
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

void DataStreamExecutor::cancel()
{
if (auto * p_stream = dynamic_cast<IProfilingBlockInputStream *>(data_stream.get()); p_stream)
p_stream->cancel(/*kill=*/false);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

void cancel(bool kill) override
{
if (kill)
is_killed = true;
bool old_val = false;
if (!is_cancelled.compare_exchange_strong(old_val, true, std::memory_order_seq_cst, std::memory_order_relaxed))
return;
if (cur_stream)
{
if (auto * child = dynamic_cast<IProfilingBlockInputStream *>(&*cur_stream))
{
child->cancel(kill);
}
}
}

It seems that cancel will not be called for UnorderedInputStream in shared_pool.


~UnorderedInputStream() override { decreaseRefCount(); }

String getName() const override { return NAME; }

Expand All @@ -67,6 +65,16 @@ class UnorderedInputStream : public IProfilingBlockInputStream
}

protected:
void decreaseRefCount()
{
bool ori = false;
if (is_stopped.compare_exchange_strong(ori, true))
{
task_pool->decreaseUnorderedInputStreamRefCount();
LOG_DEBUG(log, "Destroy, pool_id={} ref_no={}", task_pool->pool_id, ref_no);
}
}

Block readImpl() override
{
FilterPtr filter_ignored;
Expand Down Expand Up @@ -146,5 +154,7 @@ class UnorderedInputStream : public IProfilingBlockInputStream
// runtime filter
std::vector<RuntimeFilterPtr> runtime_filter_list;
int max_wait_time_ms;

std::atomic_bool is_stopped = false;
};
} // namespace DB::DM