Repository navigation
Conversation
|
Yes, the parts should not be marked as broken, but I would like to keep the exception visible and refuse server startup. |
There was a problem hiding this comment.
Pull request overview
This PR addresses an issue where ClickHouse parts using S3 storage with filesystem cache could be incorrectly marked as broken during server startup if the local cache disk encounters errors. The fix ensures that filesystem cache errors bypass the cache rather than failing the entire read/write operation.
Key Changes:
- Added error handling to gracefully handle filesystem errors in cache operations, allowing reads/writes to continue without caching
- Introduced a failpoint (
cache_filesystem_failure) to simulate cache disk failures for testing - Added integration test to verify that parts are not detached when cache disk fails
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/Interpreters/Cache/FileSegment.cpp |
Added failpoint and filesystem_error exception handling to prevent cache failures from propagating |
src/Disks/IO/CachedOnDiskWriteBufferFromFile.cpp |
Added failpoint and catch block for filesystem_error to log and skip cache on errors |
src/Disks/IO/CachedOnDiskReadBufferFromFile.cpp |
Added filesystem_error catch block to gracefully handle cache write failures during reads |
src/Common/FailPoint.cpp |
Registered new cache_filesystem_failure failpoint |
tests/integration/test_cache_bypass_on_disk_fail/test.py |
Integration test verifying parts aren't detached when cache disk fails |
tests/integration/test_cache_bypass_on_disk_fail/configs/s3_cache.xml |
Test configuration for S3 with filesystem cache |
| catch (const fs::filesystem_error &) | ||
| { | ||
| setDownloadFailed(); | ||
| throw; |
There was a problem hiding this comment.
This catch block rethrows filesystem_error exceptions, which contradicts the PR's goal of bypassing cache failures. The exception will still propagate and potentially cause parts to be marked as broken. The handler should consume the exception like in the other files, not rethrow it.
| catch (const fs::filesystem_error &) | |
| { | |
| setDownloadFailed(); | |
| throw; | |
| catch (const fs::filesystem_error & e) | |
| { | |
| setDownloadFailed(); | |
| LOG_WARNING(log, "Filesystem cache failure ignored: {}", e.what()); |
| { | ||
| file_segment.write(data, size, offset); | ||
| } | ||
| catch (std::filesystem::filesystem_error & e) |
There was a problem hiding this comment.
Exception should be caught by const reference (const std::filesystem::filesystem_error & e) to prevent unnecessary copying and follow C++ best practices. This is inconsistent with line 797 which catches ErrnoException correctly.
| catch (std::filesystem::filesystem_error & e) | |
| catch (const std::filesystem::filesystem_error & e) |
| #endif | ||
| fiu_do_on(FailPoints::cache_filesystem_failure, | ||
| { | ||
| throw std::filesystem::filesystem_error("FailPoint while caching data", std::error_code()); |
There was a problem hiding this comment.
Corrected capitalization: 'FailPoint' should be 'Failpoint' to match the error message in CachedOnDiskWriteBufferFromFile.cpp line 333.
| throw std::filesystem::filesystem_error("FailPoint while caching data", std::error_code()); | |
| throw std::filesystem::filesystem_error("Failpoint while caching data", std::error_code()); |
| SELECT * FROM t0 | ||
| """ | ||
| ) | ||
| assert node.query("SELECT count(*) FROM system.detached_parts WHERE table = 't0'") == '0\n' |
There was a problem hiding this comment.
The test should verify that data can still be read correctly after bypass, not just that parts aren't detached. Add an assertion to validate the actual query results match the inserted data to ensure correctness when cache is bypassed.
agree |
tiandiwonder
left a comment
There was a problem hiding this comment.
Add a new parameter to skip disk cache failure at startup, and print error includes something like "you can set --skip-cache-on-disk-failure-at-startup to restart clickhouse server".
|
|
||
| namespace FailPoints | ||
| { | ||
| extern const char cache_filesystem_failure[]; |
There was a problem hiding this comment.
cache_on_disk_failure is better?
| tryLogCurrentException(__PRETTY_FUNCTION__); | ||
| return; | ||
| } | ||
| catch (const std::filesystem::filesystem_error & e) |
There was a problem hiding this comment.
insert(write) failure is different from failure at startup? we cannot skip it.
| node.query("DROP TABLE IF EXISTS t0") | ||
|
|
||
| node.query( | ||
| """ |
There was a problem hiding this comment.
Would you please add a test case for startup?
|
Master already has a fix for this exact issue (commit ff7f9ff): it adds the skip_cache_on_disk_failure setting, CACHE_CANNOT_WRITE_TO_CACHE_DISK error code, proper error handling in the read path, and comprehensive tests in test_cache_bypass_on_disk_failure/. The PR's changes are largely superseded. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
On ClickHouse start, which read data from S3, the parts may be marked as broken-on-start in case of filesystem cache disk failure. I think the problem with local disk should not affect the parts(should not detach it). So, I've added bypass filesystem cache in case of filesystem error.
Documentation entry for user-facing changes