mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-30 11:32:03 +00:00
Add debug logging
This commit is contained in:
parent
8cdbe6333b
commit
07c4a072fe
@ -645,8 +645,9 @@ void CachedOnDiskReadBufferFromFile::predownload(FileSegment & file_segment)
|
|||||||
|
|
||||||
ProfileEvents::increment(ProfileEvents::CachedReadBufferReadFromSourceBytes, current_impl_buffer_size);
|
ProfileEvents::increment(ProfileEvents::CachedReadBufferReadFromSourceBytes, current_impl_buffer_size);
|
||||||
|
|
||||||
|
std::string failure_reason;
|
||||||
bool continue_predownload = file_segment.reserve(
|
bool continue_predownload = file_segment.reserve(
|
||||||
current_predownload_size, settings.filesystem_cache_reserve_space_wait_lock_timeout_milliseconds);
|
current_predownload_size, settings.filesystem_cache_reserve_space_wait_lock_timeout_milliseconds, failure_reason);
|
||||||
if (continue_predownload)
|
if (continue_predownload)
|
||||||
{
|
{
|
||||||
LOG_TEST(log, "Left to predownload: {}, buffer size: {}", bytes_to_predownload, current_impl_buffer_size);
|
LOG_TEST(log, "Left to predownload: {}, buffer size: {}", bytes_to_predownload, current_impl_buffer_size);
|
||||||
@ -1002,7 +1003,8 @@ bool CachedOnDiskReadBufferFromFile::nextImplStep()
|
|||||||
{
|
{
|
||||||
chassert(file_offset_of_buffer_end + size - 1 <= file_segment.range().right);
|
chassert(file_offset_of_buffer_end + size - 1 <= file_segment.range().right);
|
||||||
|
|
||||||
bool success = file_segment.reserve(size, settings.filesystem_cache_reserve_space_wait_lock_timeout_milliseconds);
|
std::string failure_reason;
|
||||||
|
bool success = file_segment.reserve(size, settings.filesystem_cache_reserve_space_wait_lock_timeout_milliseconds, failure_reason);
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
chassert(file_segment.getCurrentWriteOffset() == static_cast<size_t>(implementation_buffer->getPosition()));
|
chassert(file_segment.getCurrentWriteOffset() == static_cast<size_t>(implementation_buffer->getPosition()));
|
||||||
@ -1028,7 +1030,8 @@ bool CachedOnDiskReadBufferFromFile::nextImplStep()
|
|||||||
LOG_TRACE(log, "Bypassing cache because writeCache method failed");
|
LOG_TRACE(log, "Bypassing cache because writeCache method failed");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
LOG_TRACE(log, "No space left in cache to reserve {} bytes, will continue without cache download", size);
|
LOG_TRACE(log, "No space left in cache to reserve {} bytes, reason: {}, "
|
||||||
|
"will continue without cache download", failure_reason, size);
|
||||||
|
|
||||||
if (!success)
|
if (!success)
|
||||||
{
|
{
|
||||||
|
@ -91,7 +91,8 @@ bool FileSegmentRangeWriter::write(char * data, size_t size, size_t offset, File
|
|||||||
|
|
||||||
size_t size_to_write = std::min(available_size, size);
|
size_t size_to_write = std::min(available_size, size);
|
||||||
|
|
||||||
bool reserved = file_segment->reserve(size_to_write, reserve_space_lock_wait_timeout_milliseconds);
|
std::string failure_reason;
|
||||||
|
bool reserved = file_segment->reserve(size_to_write, reserve_space_lock_wait_timeout_milliseconds, failure_reason);
|
||||||
if (!reserved)
|
if (!reserved)
|
||||||
{
|
{
|
||||||
appendFilesystemCacheLog(*file_segment);
|
appendFilesystemCacheLog(*file_segment);
|
||||||
|
@ -804,7 +804,8 @@ bool FileCache::tryReserve(
|
|||||||
const size_t size,
|
const size_t size,
|
||||||
FileCacheReserveStat & reserve_stat,
|
FileCacheReserveStat & reserve_stat,
|
||||||
const UserInfo & user,
|
const UserInfo & user,
|
||||||
size_t lock_wait_timeout_milliseconds)
|
size_t lock_wait_timeout_milliseconds,
|
||||||
|
std::string & failure_reason)
|
||||||
{
|
{
|
||||||
ProfileEventTimeIncrement<Microseconds> watch(ProfileEvents::FilesystemCacheReserveMicroseconds);
|
ProfileEventTimeIncrement<Microseconds> watch(ProfileEvents::FilesystemCacheReserveMicroseconds);
|
||||||
|
|
||||||
@ -817,6 +818,7 @@ bool FileCache::tryReserve(
|
|||||||
if (cache_is_being_resized.load(std::memory_order_relaxed))
|
if (cache_is_being_resized.load(std::memory_order_relaxed))
|
||||||
{
|
{
|
||||||
ProfileEvents::increment(ProfileEvents::FilesystemCacheFailToReserveSpaceBecauseOfCacheResize);
|
ProfileEvents::increment(ProfileEvents::FilesystemCacheFailToReserveSpaceBecauseOfCacheResize);
|
||||||
|
failure_reason = "cache is being resized";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -824,6 +826,7 @@ bool FileCache::tryReserve(
|
|||||||
if (!cache_lock)
|
if (!cache_lock)
|
||||||
{
|
{
|
||||||
ProfileEvents::increment(ProfileEvents::FilesystemCacheFailToReserveSpaceBecauseOfLockContention);
|
ProfileEvents::increment(ProfileEvents::FilesystemCacheFailToReserveSpaceBecauseOfLockContention);
|
||||||
|
failure_reason = "cache contention";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -847,6 +850,7 @@ bool FileCache::tryReserve(
|
|||||||
LOG_TEST(log, "Query limit exceeded, space reservation failed, "
|
LOG_TEST(log, "Query limit exceeded, space reservation failed, "
|
||||||
"recache_on_query_limit_exceeded is disabled (while reserving for {}:{})",
|
"recache_on_query_limit_exceeded is disabled (while reserving for {}:{})",
|
||||||
file_segment.key(), file_segment.offset());
|
file_segment.key(), file_segment.offset());
|
||||||
|
failure_reason = "query limit exceeded";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -877,6 +881,7 @@ bool FileCache::tryReserve(
|
|||||||
if (!query_priority->collectCandidatesForEviction(
|
if (!query_priority->collectCandidatesForEviction(
|
||||||
size, required_elements_num, reserve_stat, eviction_candidates, {}, user.user_id, cache_lock))
|
size, required_elements_num, reserve_stat, eviction_candidates, {}, user.user_id, cache_lock))
|
||||||
{
|
{
|
||||||
|
failure_reason = "cannot evict enough space for query limit";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -891,11 +896,15 @@ bool FileCache::tryReserve(
|
|||||||
if (!main_priority->collectCandidatesForEviction(
|
if (!main_priority->collectCandidatesForEviction(
|
||||||
size, required_elements_num, reserve_stat, eviction_candidates, queue_iterator, user.user_id, cache_lock))
|
size, required_elements_num, reserve_stat, eviction_candidates, queue_iterator, user.user_id, cache_lock))
|
||||||
{
|
{
|
||||||
|
failure_reason = "cannot evict enough space";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file_segment.getKeyMetadata()->createBaseDirectory())
|
if (!file_segment.getKeyMetadata()->createBaseDirectory())
|
||||||
|
{
|
||||||
|
failure_reason = "not enough space on device";
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (eviction_candidates.size() > 0)
|
if (eviction_candidates.size() > 0)
|
||||||
{
|
{
|
||||||
|
@ -165,7 +165,8 @@ public:
|
|||||||
size_t size,
|
size_t size,
|
||||||
FileCacheReserveStat & stat,
|
FileCacheReserveStat & stat,
|
||||||
const UserInfo & user,
|
const UserInfo & user,
|
||||||
size_t lock_wait_timeout_milliseconds);
|
size_t lock_wait_timeout_milliseconds,
|
||||||
|
std::string & failure_reason);
|
||||||
|
|
||||||
std::vector<FileSegment::Info> getFileSegmentInfos(const UserID & user_id);
|
std::vector<FileSegment::Info> getFileSegmentInfos(const UserID & user_id);
|
||||||
|
|
||||||
|
@ -502,7 +502,11 @@ LockedKeyPtr FileSegment::lockKeyMetadata(bool assert_exists) const
|
|||||||
return metadata->tryLock();
|
return metadata->tryLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileSegment::reserve(size_t size_to_reserve, size_t lock_wait_timeout_milliseconds, FileCacheReserveStat * reserve_stat)
|
bool FileSegment::reserve(
|
||||||
|
size_t size_to_reserve,
|
||||||
|
size_t lock_wait_timeout_milliseconds,
|
||||||
|
std::string & failure_reason,
|
||||||
|
FileCacheReserveStat * reserve_stat)
|
||||||
{
|
{
|
||||||
if (!size_to_reserve)
|
if (!size_to_reserve)
|
||||||
throw Exception(ErrorCodes::LOGICAL_ERROR, "Zero space reservation is not allowed");
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "Zero space reservation is not allowed");
|
||||||
@ -554,7 +558,7 @@ bool FileSegment::reserve(size_t size_to_reserve, size_t lock_wait_timeout_milli
|
|||||||
if (!reserve_stat)
|
if (!reserve_stat)
|
||||||
reserve_stat = &dummy_stat;
|
reserve_stat = &dummy_stat;
|
||||||
|
|
||||||
bool reserved = cache->tryReserve(*this, size_to_reserve, *reserve_stat, getKeyMetadata()->user, lock_wait_timeout_milliseconds);
|
bool reserved = cache->tryReserve(*this, size_to_reserve, *reserve_stat, getKeyMetadata()->user, lock_wait_timeout_milliseconds, failure_reason);
|
||||||
|
|
||||||
if (!reserved)
|
if (!reserved)
|
||||||
setDownloadFailedUnlocked(lock());
|
setDownloadFailedUnlocked(lock());
|
||||||
|
@ -201,7 +201,11 @@ public:
|
|||||||
|
|
||||||
/// Try to reserve exactly `size` bytes (in addition to the getDownloadedSize() bytes already downloaded).
|
/// Try to reserve exactly `size` bytes (in addition to the getDownloadedSize() bytes already downloaded).
|
||||||
/// Returns true if reservation was successful, false otherwise.
|
/// Returns true if reservation was successful, false otherwise.
|
||||||
bool reserve(size_t size_to_reserve, size_t lock_wait_timeout_milliseconds, FileCacheReserveStat * reserve_stat = nullptr);
|
bool reserve(
|
||||||
|
size_t size_to_reserve,
|
||||||
|
size_t lock_wait_timeout_milliseconds,
|
||||||
|
std::string & failure_reason,
|
||||||
|
FileCacheReserveStat * reserve_stat = nullptr);
|
||||||
|
|
||||||
/// Write data into reserved space.
|
/// Write data into reserved space.
|
||||||
void write(char * from, size_t size, size_t offset_in_file);
|
void write(char * from, size_t size, size_t offset_in_file);
|
||||||
|
@ -75,7 +75,8 @@ void WriteBufferToFileSegment::nextImpl()
|
|||||||
FileCacheReserveStat reserve_stat;
|
FileCacheReserveStat reserve_stat;
|
||||||
/// In case of an error, we don't need to finalize the file segment
|
/// In case of an error, we don't need to finalize the file segment
|
||||||
/// because it will be deleted soon and completed in the holder's destructor.
|
/// because it will be deleted soon and completed in the holder's destructor.
|
||||||
bool ok = file_segment->reserve(bytes_to_write, reserve_space_lock_wait_timeout_milliseconds, &reserve_stat);
|
std::string failure_reason;
|
||||||
|
bool ok = file_segment->reserve(bytes_to_write, reserve_space_lock_wait_timeout_milliseconds, failure_reason, &reserve_stat);
|
||||||
|
|
||||||
if (!ok)
|
if (!ok)
|
||||||
{
|
{
|
||||||
@ -84,9 +85,10 @@ void WriteBufferToFileSegment::nextImpl()
|
|||||||
reserve_stat_msg += fmt::format("{} hold {}, can release {}; ",
|
reserve_stat_msg += fmt::format("{} hold {}, can release {}; ",
|
||||||
toString(kind), ReadableSize(stat.non_releasable_size), ReadableSize(stat.releasable_size));
|
toString(kind), ReadableSize(stat.non_releasable_size), ReadableSize(stat.releasable_size));
|
||||||
|
|
||||||
throw Exception(ErrorCodes::NOT_ENOUGH_SPACE, "Failed to reserve {} bytes for {}: {}(segment info: {})",
|
throw Exception(ErrorCodes::NOT_ENOUGH_SPACE, "Failed to reserve {} bytes for {}: reason {}, {}(segment info: {})",
|
||||||
bytes_to_write,
|
bytes_to_write,
|
||||||
file_segment->getKind() == FileSegmentKind::Temporary ? "temporary file" : "the file in cache",
|
file_segment->getKind() == FileSegmentKind::Temporary ? "temporary file" : "the file in cache",
|
||||||
|
failure_reason,
|
||||||
reserve_stat_msg,
|
reserve_stat_msg,
|
||||||
file_segment->getInfoForLog()
|
file_segment->getInfoForLog()
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user