Skip to content

Fix possibly dangling reference to target table of MV#15984

Merged
alesapin merged 4 commits intomasterfrom
fix_insert_mv_dangling_ref
Oct 21, 2020
Merged

Fix possibly dangling reference to target table of MV#15984
alesapin merged 4 commits intomasterfrom
fix_insert_mv_dangling_ref

Conversation

@tavplubix
Copy link
Copy Markdown
Member

@tavplubix tavplubix commented Oct 14, 2020

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

Changelog category (leave one):

  • Bug Fix

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix rare segfaults when inserting into or selecting from MaterializedView and concurrently dropping target table (for Atomic database engine).

Fixes https://clickhouse-test-reports.s3.yandex.net/0/13896cf4c92d6cf0962a2e9bb181dfe42045d39c/stress_test_(thread)/stderr.log and https://clickhouse-test-reports.s3.yandex.net/0/57575a5a12721682f07ff813460c6edb4b85b2c7/stress_test_(thread)/stderr.log

@robot-clickhouse robot-clickhouse added the pr-bugfix Pull request with bugfix, not backported by default label Oct 14, 2020
@tavplubix tavplubix marked this pull request as draft October 14, 2020 21:27
@tavplubix tavplubix mentioned this pull request Oct 15, 2020
73 tasks
@tavplubix tavplubix changed the title Fix possibly dangling reference when inserting into MV Fix possibly dangling reference to target table of MV Oct 15, 2020
@tavplubix tavplubix marked this pull request as ready for review October 15, 2020 10:58
res.out = std::move(out_streams.at(0));

res.pipeline.addStorageHolder(table);
if (const auto * mv = dynamic_cast<const StorageMaterializedView *>(table.get()))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When we add one storage holder, do we always have to add the entire hierarchy?

There is also a similar pipeline construction in QueryPlan/ReadFromStorage.cpp:94, does it need any treatment?

Maybe we have to adopt some simple ownership strategy, like 'a storage holder also holds all nested storages'...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ReadFromStorageStep doesn't know about nested storages, so if some storage calls read or write for another one, then it's responsible for table locks and lifetime of nested storages. However, in write method we cannot add storage holders to pipeline, because IStorage::write(...) returns BlockOutputStreamPtr, so when inserting directly into MV we add it here.

@alesapin alesapin merged commit c53f59d into master Oct 21, 2020
@alesapin alesapin deleted the fix_insert_mv_dangling_ref branch October 21, 2020 09:13
@alesapin alesapin self-assigned this Oct 21, 2020
robot-clickhouse pushed a commit that referenced this pull request Oct 21, 2020
robot-clickhouse pushed a commit that referenced this pull request Oct 21, 2020
robot-clickhouse pushed a commit that referenced this pull request Oct 21, 2020
tavplubix added a commit that referenced this pull request Oct 21, 2020
Backport #15984 to 20.10: Fix possibly dangling reference to target table of MV
tavplubix added a commit that referenced this pull request Oct 21, 2020
Backport #15984 to 20.9: Fix possibly dangling reference to target table of MV
tavplubix added a commit that referenced this pull request Oct 21, 2020
Backport #15984 to 20.8: Fix possibly dangling reference to target table of MV
robot-clickhouse pushed a commit that referenced this pull request Oct 25, 2020
tavplubix added a commit that referenced this pull request Oct 26, 2020
Backport #15984 to 20.7: Fix possibly dangling reference to target table of MV
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants