Improve MEMERY_LIMIT_EXCEEDED exception message

This commit is contained in:
Dmitry Novik 2023-01-29 01:52:37 +00:00
parent 0a829ad187
commit ec1f6bfd37

View File

@ -68,17 +68,17 @@ inline std::string_view toDescription(OvercommitResult result)
switch (result) switch (result)
{ {
case OvercommitResult::NONE: case OvercommitResult::NONE:
return "Memory overcommit isn't used. OvercommitTracker isn't set"; return "";
case OvercommitResult::DISABLED: case OvercommitResult::DISABLED:
return "Memory overcommit isn't used. Waiting time or overcommit denominator are set to zero"; return "Memory overcommit isn't used. Waiting time or overcommit denominator are set to zero.";
case OvercommitResult::MEMORY_FREED: case OvercommitResult::MEMORY_FREED:
throw DB::Exception(DB::ErrorCodes::LOGICAL_ERROR, "OvercommitResult::MEMORY_FREED shouldn't be asked for description"); throw DB::Exception(DB::ErrorCodes::LOGICAL_ERROR, "OvercommitResult::MEMORY_FREED shouldn't be asked for description");
case OvercommitResult::SELECTED: case OvercommitResult::SELECTED:
return "Query was selected to stop by OvercommitTracker"; return "Query was selected to stop by OvercommitTracker.";
case OvercommitResult::TIMEOUTED: case OvercommitResult::TIMEOUTED:
return "Waiting timeout for memory to be freed is reached"; return "Waiting timeout for memory to be freed is reached.";
case OvercommitResult::NOT_ENOUGH_FREED: case OvercommitResult::NOT_ENOUGH_FREED:
return "Memory overcommit has freed not enough memory"; return "Memory overcommit has freed not enough memory.";
} }
} }
@ -264,12 +264,13 @@ void MemoryTracker::allocImpl(Int64 size, bool throw_if_memory_exceeded, MemoryT
DB::ErrorCodes::MEMORY_LIMIT_EXCEEDED, DB::ErrorCodes::MEMORY_LIMIT_EXCEEDED,
"Memory limit{}{} exceeded: " "Memory limit{}{} exceeded: "
"would use {} (attempt to allocate chunk of {} bytes), maximum: {}." "would use {} (attempt to allocate chunk of {} bytes), maximum: {}."
"OvercommitTracker decision: {}.", "{}{}",
description ? " " : "", description ? " " : "",
description ? description : "", description ? description : "",
formatReadableSizeWithBinarySuffix(will_be), formatReadableSizeWithBinarySuffix(will_be),
size, size,
formatReadableSizeWithBinarySuffix(current_hard_limit), formatReadableSizeWithBinarySuffix(current_hard_limit),
overcommit_result == OvercommitResult::NONE ? "" : " OvercommitTracker decision: ",
toDescription(overcommit_result)); toDescription(overcommit_result));
} }
else else