Skip to content

Fix debug assertion in quantileDeterministic function.#16410

Merged
alexey-milovidov merged 5 commits intomasterfrom
fix-quantile-deterministic
Oct 28, 2020
Merged

Fix debug assertion in quantileDeterministic function.#16410
alexey-milovidov merged 5 commits intomasterfrom
fix-quantile-deterministic

Conversation

@alexey-milovidov
Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix debug assertion in quantileDeterministic function. In previous version it may also transfer up to two times more data over the network. Although no bug existed. This fixes #15683

@robot-clickhouse robot-clickhouse added the pr-improvement Pull request with some product improvements label Oct 26, 2020
@KochetovNicolai KochetovNicolai self-assigned this Oct 27, 2020
Copy link
Copy Markdown
Member

@KochetovNicolai KochetovNicolai left a comment

Choose a reason for hiding this comment

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

So, that's how I understand what was fixed here:

When sample.size() < sample_count < total_values, we serialized sample_count values instead of sample.size() in write method. So, we got some garbage serialized.

Now we always write sample.size(), and it's ok now.

However, I don't understand why it could have caused crash. It may be caught by msan somehow, but I don't see that it was used in crash reports.

Also, what about the case when reader has different max_sample_size then writer? We serialized this value before and changed it for reader. Now we don't and it is possible that sample.size() > max_sample_size after read.

@alexey-milovidov
Copy link
Copy Markdown
Member Author

alexey-milovidov commented Oct 27, 2020

I don't understand why it could have caused crash.

It doesn't cause crash in release and even in MSan, UBSan builds - because the "trash" is actually the memory containing recently filtered out values. That's why it even works correctly when this trash is sent over network and taken into account. But it triggers debug assertion in PODArray::operator[], because we access elements past the end of array (but not past the capacity).

That brings a nice idea - we can poison memory region for asan and ubsan after PODArray shrink to lower size.

@alexey-milovidov
Copy link
Copy Markdown
Member Author

Also, what about the case when reader has different max_sample_size then writer?

I assume that there is no such case. The code is written in a way that it allows different sizes. But:

  • it will be logical error if different max sizes are used at the different ends of distributed query;
  • max size is not tunable by user.

@KochetovNicolai
Copy link
Copy Markdown
Member

Fast test fails because of changes in quantile. Need to update reference.

@alexey-milovidov
Copy link
Copy Markdown
Member Author

Fuzzer: #16081

@alexey-milovidov
Copy link
Copy Markdown
Member Author

alexey-milovidov commented Oct 27, 2020

01150_ddl_guard_rwr

- known issue, @tavplubix

@alexey-milovidov alexey-milovidov merged commit df828a6 into master Oct 28, 2020
@alexey-milovidov alexey-milovidov deleted the fix-quantile-deterministic branch October 28, 2020 06:24
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.

Assert in quantilesDeterministic

3 participants