Add assertion

This commit is contained in:
kssenii 2023-06-02 15:08:04 +02:00
parent 8884be2439
commit 21e9877098

View File

@ -932,18 +932,23 @@ bool CachedOnDiskReadBufferFromFile::nextImplStep()
ProfileEvents::increment(ProfileEvents::CachedReadBufferReadFromCacheBytes, size); ProfileEvents::increment(ProfileEvents::CachedReadBufferReadFromCacheBytes, size);
ProfileEvents::increment(ProfileEvents::CachedReadBufferReadFromCacheMicroseconds, elapsed); ProfileEvents::increment(ProfileEvents::CachedReadBufferReadFromCacheMicroseconds, elapsed);
#ifdef ABORT_ON_LOGICAL_ERROR
const size_t new_file_offset = file_offset_of_buffer_end + size; const size_t new_file_offset = file_offset_of_buffer_end + size;
chassert(new_file_offset - 1 <= file_segment.range().right);
const size_t file_segment_write_offset = file_segment.getCurrentWriteOffset(true); const size_t file_segment_write_offset = file_segment.getCurrentWriteOffset(true);
if (new_file_offset > file_segment.range().right + 1)
{
auto file_segment_path = file_segment.getPathInLocalCache();
throw Exception(
ErrorCodes::LOGICAL_ERROR,
"Read unexpected size. File size: {}, file path: {}, file segment info: {}",
fs::file_size(file_segment_path), file_segment_path, file_segment.getInfoForLog());
}
if (new_file_offset > file_segment_write_offset) if (new_file_offset > file_segment_write_offset)
{ {
LOG_TRACE( throw Exception(
log, "Read {} bytes, file offset: {}, segment: {}, segment write offset: {}", ErrorCodes::LOGICAL_ERROR,
"Read unexpected size. Read {} bytes, file offset: {}, segment: {}, segment write offset: {}",
size, file_offset_of_buffer_end, file_segment.range().toString(), file_segment_write_offset); size, file_offset_of_buffer_end, file_segment.range().toString(), file_segment_write_offset);
chassert(false);
} }
#endif
} }
else else
{ {