Skip to content

Fix incorrect fallback to skip cache in case of very high concurrency level#40420

Merged
kssenii merged 3 commits intoClickHouse:masterfrom
kssenii:fix-cache-bug
Aug 23, 2022
Merged

Fix incorrect fallback to skip cache in case of very high concurrency level#40420
kssenii merged 3 commits intoClickHouse:masterfrom
kssenii:fix-cache-bug

Conversation

@kssenii
Copy link
Copy Markdown
Member

@kssenii kssenii commented Aug 19, 2022

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in official stable or prestable release)

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Fix incorrect fallback to skip cache which happened on very high concurrency level

@robot-clickhouse robot-clickhouse added the pr-bugfix Pull request with bugfix, not backported by default label Aug 19, 2022
assert(is_downloaded);
break;
}
case State::DOWNLOADING:
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.

And what does it mean? DOWNLOADING state doesn't look like something "completed".

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.

Yes, so in this case nothing is actually done as you can see, only one assertion and then we return. This case is here for the case when completeWithoutState -> completeBasedOnCurrentState is used - which is called from FileSegmentHolder's destructor which is called always in destructor of read buffers. We see that state is DOWNLOADING and is_last_holder == false && is_downloader == false and do nothing. For completeWithState it will throw exception that it is not possible to complete with DOWNLOADING state.

case State::PARTIALLY_DOWNLOADED:
case State::PARTIALLY_DOWNLOADED_NO_CONTINUATION:
{
if (is_last_holder)
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.

I don't understand this if. So if we are not the last holder than last holder will do it?

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.

I'm asking because it's unclear that eventually this code will be called.

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.

So if we are not the last holder than last holder will do it?

Yes, because completeWithoutState is always called for any user of the file segment - from destructor of FileSegmentsHolder -- file segments are always put in a special holder which calls complete() for the in destructor. E.g. eventually is_last_holder will be true.

download_state = FileSegment::State::SKIP_CACHE;
}

download_state = file_segment->wait();
Copy link
Copy Markdown
Member Author

@kssenii kssenii Aug 22, 2022

Choose a reason for hiding this comment

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

The main point is here. In complete() method we always called notify, but complete() could be called when the state did not change, so we returned from wait() for no reason. E.g. the problem was in calling cv.notify regardless which is called from file segment holder destructor, e.g. from destructor of each read buffer which tries to hold this file segment.

Copy link
Copy Markdown
Member

@alesapin alesapin left a comment

Choose a reason for hiding this comment

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

Ok, only last owner now call notify.

@kssenii kssenii merged commit d814a56 into ClickHouse:master Aug 23, 2022
@kssenii kssenii mentioned this pull request Aug 24, 2022
kssenii added a commit that referenced this pull request Aug 24, 2022
kssenii added a commit that referenced this pull request Aug 26, 2022
KochetovNicolai added a commit that referenced this pull request Sep 28, 2022
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.

3 participants