-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Check all queries returned memory on query runner teardown #11102
Conversation
ae531ba
to
ee82260
Compare
private void closeCloserSuppressing(Throwable exception) | ||
{ | ||
try { | ||
closer.close(); | ||
} | ||
catch (IOException e) { | ||
exception.addSuppressed(e); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
io.airlift.testing.Closeables#closeAllSuppress
?
@@ -583,6 +586,15 @@ public void loadExchangeManager(String name, Map<String, String> properties) | |||
public final void close() | |||
{ | |||
cancelAllQueries(); | |||
|
|||
try { | |||
checkQueryMemoryReleased(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
close() it not an awesome place to assert.
we could perhaps have a @AfterMethod
check in TestDistributedEngineOnlyQueries
, using queryRunner.getExclusiveLock()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AfterMethod
might not work great as we run tests in multiple threads. How about putting it in the AbstractTestQueryFramework#close
annotated with @AfterClass
? (or maybe have a dedicated @AfterClass
method that does just that?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah - I agree place is not great.
TestDistributedEngineOnlyQueries
is not the only place we want this. Specifically, we want to test in Test*QueryFailureRecoveryTest
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AfterClass
feels less invasive. Having @AfterMethod
with lock may make test execution significantly longer, due to threads waiting one for another.
Not sure we can have two @AfterClass
methods (would would be the ordering). But putting that in AbstractTestQueryFramework.close()
looks good to me.
There will still be some places where query runner is constructed directly (not via AbstractTestQueryFramework) which will not be subject to validation - but we can live with that I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having @AfterMethod with lock may make test execution significantly longer, due to threads waiting one for another.
i thought about that, but was more optimistic.
is it hard to measure?
note that pools should be empty immediately after query finishes, so the "assert eventually" should end real quick
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But putting that in
AbstractTestQueryFramework.close()
looks good to me.
Looks good to me too, let's do this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM % comments
@@ -583,6 +586,15 @@ public void loadExchangeManager(String name, Map<String, String> properties) | |||
public final void close() | |||
{ | |||
cancelAllQueries(); | |||
|
|||
try { | |||
checkQueryMemoryReleased(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AfterMethod
might not work great as we run tests in multiple threads. How about putting it in the AbstractTestQueryFramework#close
annotated with @AfterClass
? (or maybe have a dedicated @AfterClass
method that does just that?)
closer.close(); | ||
} | ||
catch (IOException e) { | ||
exception.addSuppressed(e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(exception != e)
as self suppression is not allowed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed as exception
cannot be IOException
(IOException is checked).
ee82260
to
7e81ac7
Compare
7e81ac7
to
7bc06f9
Compare
I temporarily cherry-picked #11097 here. Should fix the CI failures. |
throw e; | ||
} | ||
|
||
afterClassCloser.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this go to finally
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no. It would mess up exception in case closer would throw. I want to get exception from checkQueryMemoryReleased
if there is one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's still feels like it is worth calling close
. If close
is not called the in memory cluster will remain active while the testing framework is running other test cases. Maybe put it in finally
and wrap it in a try-catch
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i agree. afterClassCloser
must be invoked even if checkQueryMemoryReleased
fals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it is. In catch
clause
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, missed that.
you could also use try()
for same effect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true. Wil change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You meant like that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally missed that the close was called. The current state looks good to me.
7bc06f9
to
7793b00
Compare
throw e; | ||
} | ||
|
||
afterClassCloser.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i agree. afterClassCloser
must be invoked even if checkQueryMemoryReleased
fals.
7793b00
to
1724f93
Compare
h2QueryRunner = null; | ||
sqlParser = null; | ||
queryAssertions = null; | ||
try (AutoCloseable ignored = afterClassCloser) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try (afterClassCloser)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow. 🤯 . Was that always possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, not always. Initially wasn't.
1724f93
to
a971cac
Compare
Follow-up issue: #11275 |
Description
Check all queries returned memory on query runner teardown
testing improvement
tests
Related issues, pull requests, and links
fixes: #11093
Documentation
(x) No documentation is needed.
( ) Sufficient documentation is included in this PR.
( ) Documentation PR is available with #prnumber.
( ) Documentation issue #issuenumber is filed, and can be handled later.
Release notes
(x) No release notes entries required.
( ) Release notes entries required with the following suggested text: