Skip to content

Bad assert cause system crash in local cache#36452

Merged
kssenii merged 4 commits intoClickHouse:masterfrom
KinderRiven:master
Apr 20, 2022
Merged

Bad assert cause system crash in local cache#36452
kssenii merged 4 commits intoClickHouse:masterfrom
KinderRiven:master

Conversation

@KinderRiven
Copy link
Contributor

@KinderRiven KinderRiven commented Apr 20, 2022

Changelog category (leave one):

  • Bug Fix

Changelog entry:

In FileSegmentsHolder::~FileSegmentsHolder(), when a segment is set to detach, it will assert its state is empty. However, in FileSegment::completeImpl(), when detach is set to true, its state may be PARTIALLY_DOWNLOADED_NO_CONTINUATION or SKIP_CACHE or PARTIALLY_DOWNLOADED, thus cause error in FileSegmentsHolder::~FileSegmentsHolder().

if (file_segment->detached)
{
    /// This file segment is not owned by cache, so it will be destructed
    /// at this point, therefore no completion required.
    assert(file_segment->state() == FileSegment::State::EMPTY);
    file_segment_it = file_segments.erase(current_file_segment_it);
    continue;
}

@KinderRiven KinderRiven changed the title Bad assert cause system crash Bad assert cause system crash in local cache Apr 20, 2022
@kssenii kssenii self-assigned this Apr 20, 2022
void FileSegment::assertDetachedStatus() const
{
assert(
(download_state == State::EMPTY) || (download_state == State::PARTIALLY_DOWNLOADED)
Copy link
Member

@kssenii kssenii Apr 20, 2022

Choose a reason for hiding this comment

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

State::PARTIALLY_DOWNLOADED should be redundant in this place.
Let's update the file segment state in completeImpl right before this line

cache->reduceSizeToDownloaded(key(), offset(), cache_lock, segment_lock);

to State::PARTIALLY_DOWNLOADED_NO_CONTINUATION if it is not already.

@robot-clickhouse robot-clickhouse added the pr-bugfix Pull request with bugfix, not backported by default label Apr 20, 2022
@kssenii kssenii added the can be tested Allows running workflows for external contributors label Apr 20, 2022
@kssenii kssenii merged commit f9faadc into ClickHouse:master Apr 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors 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