Removed forceful drop cache command, fix detached status state#36825
Removed forceful drop cache command, fix detached status state#36825alesapin merged 26 commits intoClickHouse:masterfrom
Conversation
761147d to
2491514
Compare
src/Common/FileCache.cpp
Outdated
| throw Exception( | ||
| ErrorCodes::REMOTE_FS_OBJECT_CACHE_ERROR, | ||
| "Cache cell already exists for key `{}` and offset {}", | ||
| keyToStr(key), offset); |
src/Common/FileSegment.cpp
Outdated
| throw Exception(ErrorCodes::REMOTE_FS_OBJECT_CACHE_ERROR, "Zero space reservation is not allowed"); | ||
|
|
||
| assertNotDetached(); | ||
| std::lock_guard cache_lock(cache->mutex); |
There was a problem hiding this comment.
Comment, why we need both locks here.
src/Common/FileSegment.cpp
Outdated
|
|
||
| assertNotDetached(); | ||
| std::lock_guard cache_lock(cache->mutex); | ||
| std::lock_guard detach_lock(detach_mutex); |
There was a problem hiding this comment.
Very complex, taking three mutexes at once. Need detailed explanation.
src/Common/FileSegment.cpp
Outdated
| } | ||
|
|
||
| void FileSegment::assertNotDetached() const | ||
| void FileSegment::throwDetached() const |
src/Common/FileSegment.h
Outdated
| 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( |
There was a problem hiding this comment.
| void detach( | |
| void detach( |
src/Common/FileSegment.cpp
Outdated
| size, offset_, download_offset); | ||
|
|
||
| assertNotDetached(); | ||
| std::lock_guard detach_lock(detach_mutex); |
There was a problem hiding this comment.
Why we need it here? Add a comment.
src/Common/FileSegment.cpp
Outdated
| std::lock_guard segment_lock(mutex); | ||
|
|
||
| if (is_forcefully_detached) | ||
| throwDetachedUnlocked(segment_lock); |
There was a problem hiding this comment.
it's unexpected that method with is prefix can throw an exception.
src/Common/FileSegment.cpp
Outdated
| /// needed, downloader is set on file segment creation). | ||
| case (State::DOWNLOADING): | ||
| { | ||
| /// On write-through cache we do not check downloader id. |
There was a problem hiding this comment.
What does it mean? Where we don't check it?
| { | ||
| UploadPartTask task; | ||
| fillUploadRequest(task.req, part_tags.size() + 1); | ||
| if (file_segments_holder) |
|
will delete the forceful drop cache command instead |
|
Some changes still make sense, will remove only what is not needed with removal of forced detach |
| download_state = State::PARTIALLY_DOWNLOADED_NO_CONTINUATION; | ||
| downloader_id.clear(); |
There was a problem hiding this comment.
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:
- 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
- in
read_from_cache_if_exists_otherwise_bypass_cachecase (getmethod 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.
src/Common/FileSegment.h
Outdated
| /// In general case, all file segments are owned by cache. | ||
| bool detached = false; | ||
| bool is_detached = false; | ||
| bool is_forcefully_detached = false; |
|
|
||
| markAsDetached(segment_lock); | ||
| download_state = State::PARTIALLY_DOWNLOADED_NO_CONTINUATION; | ||
| downloader_id.clear(); |
src/Common/FileSegment.cpp
Outdated
| 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"); |
|
Failure unrelated. |
Changelog category (leave one):
Closes #36789 (comment)