mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Merge pull request #71856 from ClickHouse/add-check-fs-cache
Add check and assertion
This commit is contained in:
commit
3300d124d3
@ -361,11 +361,14 @@ void FileSegment::write(char * from, size_t size, size_t offset_in_file)
|
||||
"Expected DOWNLOADING state, got {}", stateToString(download_state));
|
||||
|
||||
const size_t first_non_downloaded_offset = getCurrentWriteOffset();
|
||||
|
||||
if (offset_in_file != first_non_downloaded_offset)
|
||||
{
|
||||
throw Exception(
|
||||
ErrorCodes::LOGICAL_ERROR,
|
||||
"Attempt to write {} bytes to offset: {}, but current write offset is {}",
|
||||
size, offset_in_file, first_non_downloaded_offset);
|
||||
}
|
||||
|
||||
const size_t current_downloaded_size = getDownloadedSize();
|
||||
chassert(reserved_size >= current_downloaded_size);
|
||||
@ -376,8 +379,19 @@ void FileSegment::write(char * from, size_t size, size_t offset_in_file)
|
||||
ErrorCodes::LOGICAL_ERROR,
|
||||
"Not enough space is reserved. Available: {}, expected: {}", free_reserved_size, size);
|
||||
|
||||
if (!is_unbound && current_downloaded_size == range().size())
|
||||
throw Exception(ErrorCodes::LOGICAL_ERROR, "File segment is already fully downloaded");
|
||||
if (!is_unbound)
|
||||
{
|
||||
if (current_downloaded_size == range().size())
|
||||
throw Exception(ErrorCodes::LOGICAL_ERROR, "File segment is already fully downloaded");
|
||||
|
||||
if (current_downloaded_size + size > range().size())
|
||||
{
|
||||
throw Exception(
|
||||
ErrorCodes::LOGICAL_ERROR,
|
||||
"Cannot download beyond file segment boundaries: {}. Write offset: {}, size: {}, downloaded size: {}",
|
||||
range().size(), first_non_downloaded_offset, size, current_downloaded_size);
|
||||
}
|
||||
}
|
||||
|
||||
if (!cache_writer && current_downloaded_size > 0)
|
||||
throw Exception(
|
||||
@ -894,7 +908,12 @@ bool FileSegment::assertCorrectnessUnlocked(const FileSegmentGuard::Lock & lock)
|
||||
chassert(downloaded_size == reserved_size);
|
||||
chassert(downloaded_size == range().size());
|
||||
chassert(downloaded_size > 0);
|
||||
chassert(fs::file_size(getPath()) > 0);
|
||||
|
||||
auto file_size = fs::file_size(getPath());
|
||||
UNUSED(file_size);
|
||||
|
||||
chassert(file_size == range().size());
|
||||
chassert(downloaded_size == range().size());
|
||||
|
||||
chassert(queue_iterator || on_delayed_removal);
|
||||
check_iterator(queue_iterator);
|
||||
@ -916,7 +935,13 @@ bool FileSegment::assertCorrectnessUnlocked(const FileSegmentGuard::Lock & lock)
|
||||
|
||||
chassert(reserved_size >= downloaded_size);
|
||||
chassert(downloaded_size > 0);
|
||||
chassert(fs::file_size(getPath()) > 0);
|
||||
|
||||
auto file_size = fs::file_size(getPath());
|
||||
UNUSED(file_size);
|
||||
|
||||
chassert(file_size > 0);
|
||||
chassert(file_size <= range().size());
|
||||
chassert(downloaded_size <= range().size());
|
||||
|
||||
chassert(queue_iterator);
|
||||
check_iterator(queue_iterator);
|
||||
|
@ -1165,7 +1165,7 @@ std::vector<FileSegment::Info> LockedKey::sync()
|
||||
actual_size, expected_size, file_segment->getInfoForLog());
|
||||
|
||||
broken.push_back(FileSegment::getInfo(file_segment));
|
||||
it = removeFileSegment(file_segment->offset(), file_segment->lock(), /* can_be_broken */false);
|
||||
it = removeFileSegment(file_segment->offset(), file_segment->lock(), /* can_be_broken */true);
|
||||
}
|
||||
return broken;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user