BartMiki opened a new pull request, #15754:
URL: https://github.com/apache/druid/pull/15754

   <!-- Thanks for trying to help us make Apache Druid be the best it can be! 
Please fill out as much of the following information as is possible (where 
relevant, and remove it when irrelevant) to help make the intention and scope 
of this PR clear in order to ease review. -->
   
   <!-- Please read the doc for contribution 
(https://github.com/apache/druid/blob/master/CONTRIBUTING.md) before making 
this PR. Also, once you open a PR, please _avoid using force pushes and 
rebasing_ since these make it difficult for reviewers to see what you've 
changed in response to their reviews. See [the 'If your pull request shows 
conflicts with master' 
section](https://github.com/apache/druid/blob/master/CONTRIBUTING.md#if-your-pull-request-shows-conflicts-with-master)
 for more details. -->
   
   Fixes #15069.
   
   <!-- If you are a committer, follow the PR action item checklist for 
committers:
   
https://github.com/apache/druid/blob/master/dev/committer-instructions.md#pr-and-issue-action-item-checklist-for-committers.
 -->
   
   ### Description
   
   This PR fixes #15069 by resolving a memory leak caused by a thread leak in 
`query-cancellation-executor`.
   
   #### Root of the bug
   The problem was caused by removal of queryable server from a Broker list. 
Some of the servers have a DirectQueryRunner that creates 
`SingleThreadedScheduledExecutor`. In a case when native query was cancelled a 
thread would be created.
   
   However, when the server was removed from the list we lost a reference to 
the server view that holds the runner that holds executor. When at least one 
query was cancelled, but the reference was lost, then the thread would be 
waiting infinitely, with no possibility to GC it.
   
   There was no cleanup of the executor.
   
   #### Solution
   
   * Add `AutoClosable` to `QueryRunner` with default empty implementation - 
this way all functional interfaces implementation are still correct.
   * Add timeout of 5 minutes to one of the `future.get` methods that were 
blocking indefinitely (and they were in our clients case) in 
`DruidDirectClient`.
   * Implement `close` in `DruidDirectClient` that properly shuts down a thread 
pool.
   * Invoke `close` in removal of the `QueryableDruidServer` from the 
`BrokerServerView`.
   
   #### Reproducing
   
   To reproduce this bug before the patch, we need to have a standard Druid 
cluster (for example `micro quickstart`) with one broker and one historical. We 
want to monitor Broker threads (for example with: `jconsol`). We need to have a 
command to spin up a second historical. Then the steps to reproduce are:
   
   1. Execute a long running native query and cancel it - this should trigger 
creation of the `query-cancellation-executor` thread. There should be only 
_one_ thread now.
   2. Start another historical.
   3. Execute a long running native query and cancel it - there should be _two_ 
of these threads
   4. Kill this 2nd historical - we still should have two threads on a list
   5. Start 2nd historical again
   6. Execute a long running native query and cancel it - there should be 
_three_ of these threads
   7. Thread leak detected, as we have 2 historical nodes, but 3 threads.
   8. Repeat kill, start, execute, cancel to get more threads.
   
   #### Release note
   
   Fixed: DirectDruidClient no longer leaks query-cancellation-executor threads 
after being removed by BrokerServerView.
   
   <hr>
   
   ##### Key changed/added classes in this PR
    * `QueryRunner`
    * `DruidDirectClient`
    * `BrokerServerView`
    * `QueryableDruidServer`
   
   <hr>
   
   <!-- Check the items by putting "x" in the brackets for the done things. Not 
all of these items apply to every PR. Remove the items which are not done or 
not relevant to the PR. None of the items from the checklist below are strictly 
necessary, but it would be very helpful if you at least self-review the PR. -->
   
   This PR has:
   
   - [ ] been self-reviewed.
      - [ ] using the [concurrency 
checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md)
 (Remove this item if the PR doesn't have any relation to concurrency.)
   - [ ] added documentation for new or modified features or behaviors.
   - [ ] a release note entry in the PR description.
   - [ ] added Javadocs for most classes and all non-trivial methods. Linked 
related entities via Javadoc links.
   - [ ] added or updated version, license, or notice information in 
[licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
   - [ ] added comments explaining the "why" and the intent of the code 
wherever would not be obvious for an unfamiliar reader.
   - [ ] added unit tests or modified existing tests to cover new code paths, 
ensuring the threshold for [code 
coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md)
 is met.
   - [ ] added integration tests.
   - [x] been tested in a test Druid cluster.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to