Skip to content

Removed forceful drop cache command, fix detached status state#36825

Merged
alesapin merged 26 commits intoClickHouse:masterfrom
kssenii:cache-fix-1
May 12, 2022
Merged

Removed forceful drop cache command, fix detached status state#36825
alesapin merged 26 commits intoClickHouse:masterfrom
kssenii:cache-fix-1

Conversation

@kssenii
Copy link
Copy Markdown
Member

@kssenii kssenii commented Apr 30, 2022

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Closes #36789 (comment)

@robot-clickhouse robot-clickhouse added the pr-not-for-changelog This PR should not be mentioned in the changelog label Apr 30, 2022
@kssenii kssenii changed the title Fix hung check Reimplement write-through cache May 2, 2022
@kssenii kssenii force-pushed the cache-fix-1 branch 2 times, most recently from 761147d to 2491514 Compare May 2, 2022 16:53
@kssenii kssenii marked this pull request as ready for review May 2, 2022 16:54
Comment on lines +791 to +794
throw Exception(
ErrorCodes::REMOTE_FS_OBJECT_CACHE_ERROR,
"Cache cell already exists for key `{}` and offset {}",
keyToStr(key), offset);
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.

Looks like LOGICAL_ERROR

@kssenii kssenii changed the title Reimplement write-through cache Fix stress test May 3, 2022
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.

Need clarification.

throw Exception(ErrorCodes::REMOTE_FS_OBJECT_CACHE_ERROR, "Zero space reservation is not allowed");

assertNotDetached();
std::lock_guard cache_lock(cache->mutex);
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.

Comment, why we need both locks here.


assertNotDetached();
std::lock_guard cache_lock(cache->mutex);
std::lock_guard detach_lock(detach_mutex);
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.

Very complex, taking three mutexes at once. Need detailed explanation.

}

void FileSegment::assertNotDetached() const
void FileSegment::throwDetached() const
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.

throwIfDetached?

static FileSegmentPtr getSnapshot(const FileSegmentPtr & file_segment, std::lock_guard<std::mutex> & cache_lock);

void detach(std::lock_guard<std::mutex> & cache_lock, std::lock_guard<std::mutex> & segment_lock);
void 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.

Suggested change
void detach(
void detach(

size, offset_, download_offset);

assertNotDetached();
std::lock_guard detach_lock(detach_mutex);
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.

Why we need it here? Add a comment.

std::lock_guard segment_lock(mutex);

if (is_forcefully_detached)
throwDetachedUnlocked(segment_lock);
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.

it's unexpected that method with is prefix can throw an exception.

/// needed, downloader is set on file segment creation).
case (State::DOWNLOADING):
{
/// On write-through cache we do not check downloader id.
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.

What does it mean? Where we don't check it?

{
UploadPartTask task;
fillUploadRequest(task.req, part_tags.size() + 1);
if (file_segments_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.

Unclear changes to me.

@kssenii
Copy link
Copy Markdown
Member Author

kssenii commented May 10, 2022

will delete the forceful drop cache command instead

@kssenii kssenii closed this May 10, 2022
@kssenii kssenii reopened this May 11, 2022
@kssenii
Copy link
Copy Markdown
Member Author

kssenii commented May 11, 2022

Some changes still make sense, will remove only what is not needed with removal of forced detach

@kssenii kssenii changed the title Fix stress test Removed forceful drop cache command, fix detached status state May 11, 2022
Comment on lines +741 to +742
download_state = State::PARTIALLY_DOWNLOADED_NO_CONTINUATION;
downloader_id.clear();
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.

the most important change here, though its absence should not affect anything because now detached status can be in 2 cases, which do not do any complex logic and check exactly for detached status:

  1. there is only 1 remaining file segment holder && it does not need this segment anymore && this file segment was in cache and needs to be removed
  2. in read_from_cache_if_exists_otherwise_bypass_cache case (get method can create them)

So this change not required, but it is more correct to have it (so the file segment state becomes consistent). Other remaining changes in this pr are just assertions and adding logical errors in some places.

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.

Small comments.

/// In general case, all file segments are owned by cache.
bool detached = false;
bool is_detached = false;
bool is_forcefully_detached = false;
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.

redundant?


markAsDetached(segment_lock);
download_state = State::PARTIALLY_DOWNLOADED_NO_CONTINUATION;
downloader_id.clear();
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.

Add this comment to the code

throw Exception(
ErrorCodes::LOGICAL_ERROR,
"Cache file segment is in detached state, operation not allowed. "
"It can happen when cache was concurrently dropped with SYSTEM DROP FILESYSTEM CACHE FORCE");
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.

Is it still required?

@alesapin
Copy link
Copy Markdown
Member

Failure unrelated.

@alesapin alesapin merged commit e7296a2 into ClickHouse:master May 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assertion failed in destructor of FileSegmentsHolder

4 participants