You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2020/06/25 06:04:38 UTC

[GitHub] [druid] clintropolis opened a new pull request #10076: Parallel merge combining sequence close yielders

clintropolis opened a new pull request #10076:
URL: https://github.com/apache/druid/pull/10076


   
   ### Description
   #9934 but for `ParallelMergeCombiningSequence`. Also spotted a place where we weren't closing a non-exploding `BatchedResultCursor` so fixes more leaks than I was anticipating :metal:.
   
   I might be abusing `ExplodingSequence` added in #9934 in my added tests... but I needed an interface for checking if my Sequence yielders were cleaning up after themselves, so.. it served my purposes.
   
   <hr>
   
   This PR has:
   - [x] been self-reviewed.
      - [x] 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.)
   - [x] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
   - [x] 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.
   - [ ] been tested in a test Druid cluster.
   
   <hr>
   
   ##### Key changed/added classes in this PR
    * `ParallelMergeCombiningSequence`
   


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] clintropolis merged pull request #10076: ensure ParallelMergeCombiningSequence closes its closeables

Posted by GitBox <gi...@apache.org>.
clintropolis merged pull request #10076:
URL: https://github.com/apache/druid/pull/10076


   


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] suneet-s commented on a change in pull request #10076: ensure ParallelMergeCombiningSequence closes it's closeables

Posted by GitBox <gi...@apache.org>.
suneet-s commented on a change in pull request #10076:
URL: https://github.com/apache/druid/pull/10076#discussion_r446200630



##########
File path: core/src/main/java/org/apache/druid/java/util/common/guava/ParallelMergeCombiningSequence.java
##########
@@ -341,6 +344,7 @@ protected void compute()
         }
       }
       catch (Exception ex) {
+        closeAllCursors(sequenceCursors);

Review comment:
       Have you considered closing the sequenceCursors in a finally block incase a Throwable is thrown instead of an exception?




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] suneet-s commented on a change in pull request #10076: ensure ParallelMergeCombiningSequence closes it's closeables

Posted by GitBox <gi...@apache.org>.
suneet-s commented on a change in pull request #10076:
URL: https://github.com/apache/druid/pull/10076#discussion_r446285774



##########
File path: core/src/main/java/org/apache/druid/java/util/common/guava/ParallelMergeCombiningSequence.java
##########
@@ -341,6 +344,7 @@ protected void compute()
         }
       }
       catch (Exception ex) {
+        closeAllCursors(sequenceCursors);

Review comment:
       Sorry, I misread this. A finally block won't work 🤦 
   
   Does it provide any better guarantees if we catch a Throwable instead of an exception here - so that in case any of the code in the try block throws an `Error` instead of an `Exception`
   
   This code appears to have been running ok all this time with a `catch (Exception)` block so I'm guessing it's not too bad if the catch condition is left as is




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] clintropolis commented on a change in pull request #10076: ensure ParallelMergeCombiningSequence closes it's closeables

Posted by GitBox <gi...@apache.org>.
clintropolis commented on a change in pull request #10076:
URL: https://github.com/apache/druid/pull/10076#discussion_r446363639



##########
File path: core/src/main/java/org/apache/druid/java/util/common/guava/ParallelMergeCombiningSequence.java
##########
@@ -341,6 +344,7 @@ protected void compute()
         }
       }
       catch (Exception ex) {
+        closeAllCursors(sequenceCursors);

Review comment:
       Seems reasonable to switch to catching throwable, can swap it out




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] jihoonson commented on a change in pull request #10076: ensure ParallelMergeCombiningSequence closes it's closeables

Posted by GitBox <gi...@apache.org>.
jihoonson commented on a change in pull request #10076:
URL: https://github.com/apache/druid/pull/10076#discussion_r445696870



##########
File path: core/src/main/java/org/apache/druid/java/util/common/guava/ParallelMergeCombiningSequence.java
##########
@@ -1350,4 +1363,24 @@ long getTotalCpuTimeNanos()
       return totalCpuTimeNanos;
     }
   }
+
+  private static <T> void closeAllCursors(final PriorityQueue<BatchedResultsCursor<T>> pQueue)
+  {
+    Closer closer = Closer.create();
+    while (!pQueue.isEmpty()) {
+      final BatchedResultsCursor<T> yielder = pQueue.poll();
+      if (yielder != null) {
+        // Note: yielder can be null if our comparator threw an exception during queue.add.
+        closer.register(yielder);

Review comment:
       nit: `Closer.register()` has null check. You can use `registerAll()` instead.

##########
File path: core/src/main/java/org/apache/druid/java/util/common/guava/ParallelMergeCombiningSequence.java
##########
@@ -1036,11 +1047,13 @@ public boolean isReleasable()
     @Override
     public void close()
     {
-      try {
-        yielder.close();
-      }
-      catch (IOException e) {
-        throw new RuntimeException("Failed to close yielder", e);
+      if (yielder != null) {
+        try {
+          yielder.close();
+        }
+        catch (IOException e) {
+          throw new RuntimeException("Failed to close yielder", e);

Review comment:
       It seems the exception will be eventually handled by `CloseQuietly`.

##########
File path: core/src/main/java/org/apache/druid/java/util/common/guava/ParallelMergeCombiningSequence.java
##########
@@ -1350,4 +1363,24 @@ long getTotalCpuTimeNanos()
       return totalCpuTimeNanos;
     }
   }
+
+  private static <T> void closeAllCursors(final PriorityQueue<BatchedResultsCursor<T>> pQueue)
+  {
+    Closer closer = Closer.create();
+    while (!pQueue.isEmpty()) {
+      final BatchedResultsCursor<T> yielder = pQueue.poll();
+      if (yielder != null) {
+        // Note: yielder can be null if our comparator threw an exception during queue.add.
+        closer.register(yielder);
+      }
+    }
+    CloseQuietly.close(closer);
+  }
+
+  private static <T> void closeAllCursors(final List<BatchedResultsCursor<T>> list)

Review comment:
       You can merge these methods if you use `registerAll()` above.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] clintropolis commented on a change in pull request #10076: ensure ParallelMergeCombiningSequence closes it's closeables

Posted by GitBox <gi...@apache.org>.
clintropolis commented on a change in pull request #10076:
URL: https://github.com/apache/druid/pull/10076#discussion_r445326768



##########
File path: core/src/main/java/org/apache/druid/java/util/common/guava/ParallelMergeCombiningSequence.java
##########
@@ -1036,11 +1047,13 @@ public boolean isReleasable()
     @Override
     public void close()
     {
-      try {
-        yielder.close();
-      }
-      catch (IOException e) {
-        throw new RuntimeException("Failed to close yielder", e);
+      if (yielder != null) {
+        try {
+          yielder.close();
+        }
+        catch (IOException e) {
+          throw new RuntimeException("Failed to close yielder", e);

Review comment:
       I... can't remember if there is a reason why this explodes violently while the others are all `CloseQuietly`... I'll try to figure out if this should be eaten too.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org