Skip to content

Fixing ThreadSanitizer data race error in the LIVE VIEW when accessing no_users_thread variable#7353

Merged
akuzm merged 1 commit intoClickHouse:masterfrom
vzakaznikov:live_view_fix_no_users_thread_data_race
Oct 17, 2019
Merged

Fixing ThreadSanitizer data race error in the LIVE VIEW when accessing no_users_thread variable#7353
akuzm merged 1 commit intoClickHouse:masterfrom
vzakaznikov:live_view_fix_no_users_thread_data_race

Conversation

@vzakaznikov
Copy link
Copy Markdown
Contributor

I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en

Category (leave one):

  • Bug Fix

Fixing ThreadSanitizer data race error in the LIVE VIEW when accessing no_users_thread variable.

Copy link
Copy Markdown
Contributor

@akuzm akuzm left a comment

Choose a reason for hiding this comment

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

I have a hunch that a proper fix would involve rethinking the architecture, not adding more mutexes, but have no resources for an in-depth review now. Will merge as is.

@akuzm akuzm merged commit 66675ed into ClickHouse:master Oct 17, 2019
@vzakaznikov
Copy link
Copy Markdown
Contributor Author

I have a hunch that a proper fix would involve rethinking the architecture, not adding more mutexes, but have no resources for an in-depth review now. Will merge as is.

I totally agree. Adding mutexes right now is a just quick fix. The implementation has to be revisited. Maybe the support for live views that are automatically dropped should be removed as this feature added the usage of an anti-pattern where we are dropping a table in a thread that later can't be joined properly.

@akuzm akuzm added the pr-improvement Pull request with some product improvements label Oct 29, 2019
{
std::lock_guard lock(no_users_thread_mutex);
if (no_users_thread.joinable())
no_users_thread.detach();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think it is totally incorrect but I fully agree that calling and using std::thread::detach is bad. So what would be a better way to asynchronously drop table? The use case here is that if TIMEOUT is specified during the creation of LIVE VIEW we want to drop it automatically if there are no users that are watching this view after some N number of seconds.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe just remove the TIMEOUT feature?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So you think that there is nothing in ClickHouse where we could schedule a callback?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe we should do something like this?

streaming_task = global_context.getSchedulePool().createTask("RabbitMQStreamingTask", [this]{ threadFunc(); });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, it can be Ok.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, perfect. I will try it out and create a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants