2018-03-11 00:15:26 +00:00
|
|
|
#include <DataStreams/SizeLimits.h>
|
|
|
|
#include <Common/formatReadable.h>
|
|
|
|
#include <Common/Exception.h>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2019-10-03 18:27:11 +00:00
|
|
|
bool SizeLimits::check(UInt64 rows, UInt64 bytes, const char * what, int too_many_rows_exception_code, int too_many_bytes_exception_code) const
|
2018-03-11 00:15:26 +00:00
|
|
|
{
|
2019-10-15 16:31:49 +00:00
|
|
|
if (overflow_mode == OverflowMode::THROW)
|
2018-03-11 00:15:26 +00:00
|
|
|
{
|
2019-10-15 16:31:49 +00:00
|
|
|
if (max_rows && rows > max_rows)
|
2018-03-11 00:15:26 +00:00
|
|
|
throw Exception("Limit for " + std::string(what) + " exceeded, max rows: " + formatReadableQuantity(max_rows)
|
2019-10-03 18:27:11 +00:00
|
|
|
+ ", current rows: " + formatReadableQuantity(rows), too_many_rows_exception_code);
|
2018-03-11 00:15:26 +00:00
|
|
|
|
2019-10-15 16:31:49 +00:00
|
|
|
if (max_bytes && bytes > max_bytes)
|
2020-05-30 21:35:52 +00:00
|
|
|
throw Exception(fmt::format("Limit for {} exceeded, max bytes: {}, current bytes: {}",
|
|
|
|
std::string(what), ReadableSize(max_bytes), ReadableSize(bytes)), too_many_bytes_exception_code);
|
2019-10-15 16:31:49 +00:00
|
|
|
|
|
|
|
return true;
|
2018-03-11 00:15:26 +00:00
|
|
|
}
|
|
|
|
|
2019-10-15 16:31:49 +00:00
|
|
|
return softCheck(rows, bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SizeLimits::softCheck(UInt64 rows, UInt64 bytes) const
|
|
|
|
{
|
|
|
|
if (max_rows && rows > max_rows)
|
|
|
|
return false;
|
|
|
|
if (max_bytes && bytes > max_bytes)
|
|
|
|
return false;
|
2018-03-11 00:15:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-10-03 18:27:11 +00:00
|
|
|
bool SizeLimits::check(UInt64 rows, UInt64 bytes, const char * what, int exception_code) const
|
|
|
|
{
|
|
|
|
return check(rows, bytes, what, exception_code, exception_code);
|
|
|
|
}
|
|
|
|
|
2018-03-11 00:15:26 +00:00
|
|
|
}
|