Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MemoryTracker new no throw #24483

Merged
merged 3 commits into from May 27, 2021

Conversation

kitaisreal
Copy link
Collaborator

@kitaisreal kitaisreal commented May 25, 2021

I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

This closes #24110

@robot-clickhouse robot-clickhouse added the pr-not-for-changelog This PR should not be mentioned in the changelog label May 25, 2021
@kitaisreal kitaisreal added the force tests Force test ignoring fast test output. label May 25, 2021
description ? " " : "", description ? description : "",
formatReadableSizeWithBinarySuffix(will_be),
size, formatReadableSizeWithBinarySuffix(current_hard_limit));
}
}

updatePeak(will_be);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is logging in updatePeak that should be disabled in "light" version of MemoryTracker.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

if (unlikely(current_profiler_limit && will_be > current_profiler_limit))
{
BlockerInThread untrack_lock(VariableContext::Global);
DB::TraceCollector::collect(DB::TraceType::Memory, StackTrace(), size);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But profiling should remain enabled in "light" version of MemoryTracker.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexey-milovidov DB::TraceCollector::collect can throw exception.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make it non throwing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked DB::TraceCollector::collect does not throw exception, it use special buffer subclass that does not throw.

@alexey-milovidov alexey-milovidov self-assigned this May 25, 2021
@alexey-milovidov
Copy link
Member

Ok. Cannot merge due to 01149_zookeeper_mutation_stuck_after_replace_partition.

Also there is one potential downside - the messages "Current memory usage" that are printed every 1 GiB can be skipped.
(We cannot output them in the "light" invocation of MemoryTracker, but maybe we can postpone them). I'm not sure how better to fix it - need to think.

@kitaisreal kitaisreal merged commit e5b7872 into ClickHouse:master May 27, 2021
@@ -173,29 +173,36 @@ void MemoryTracker::alloc(Int64 size)
}

#ifdef MEMORY_TRACKER_DEBUG_CHECKS
if (unlikely(_memory_tracker_always_throw_logical_error_on_allocation))
if (unlikely(_memory_tracker_always_throw_logical_error_on_allocation) && throw_if_memory_exceeded)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this should check for throw_if_memory_exceeded? since this is logical error, so an error in the code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is issue, will create pull request.

description ? " " : "", description ? description : "",
formatReadableSizeWithBinarySuffix(will_be),
size, formatReadableSizeWithBinarySuffix(current_hard_limit));
throw DB::Exception(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But should it prohibit fault injection?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was discussed and we decided to prevent fault injection for lite version of MemoryTracker.

void MemoryTracker::allocNoThrow(Int64 size)
{
bool throw_if_memory_exceeded = false;
allocImpl(size, throw_if_memory_exceeded);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW why not simply allocImpl(size, /* throw_if_memory_exceeded= */ false);
Looks a little bit excessive.
clang-tidy will detect if the comment will not match with the variable name from the function signature

Or is it the "new coding style"? (in other places I saw this via comment not via separate variable)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to inline comments.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both variants are ok.

Copy link
Contributor

@akuzm akuzm May 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both variants are ok.

What we're saying is that introducing a separate non-const variable looks exceedingly verbose (extra line) and confusing (maybe it's used somewhere else later?).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akuzm what I am saying that it is just style preference, both variants are equally bad, additional comment of bool property name is unreadable in case you have more than 1 bool. For function with 3 lines current variant is ok.

azat added a commit to azat/ClickHouse that referenced this pull request Jun 7, 2021
After ClickHouse#24483 had been merged the only place where the allocation may
fail is the insert into PODArray in DB::OwnSplitChannel::log, but this
MR ignores the errors in this function, so to check new behaviour
separate server is required.
azat added a commit to azat/ClickHouse that referenced this pull request Aug 22, 2022
It looks useless nowadays, because operator new cannot throw
MEMORY_LIMIT_EXCEEDED today, and so any code that works on Exception is
likely safe.

Refs: ClickHouse#40249
Refs: ClickHouse#24483
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
force tests Force test ignoring fast test output. pr-not-for-changelog This PR should not be mentioned in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MemoryTracker should be used in operator new in a light way
5 participants