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/05/27 03:55:21 UTC

[GitHub] [druid] jihoonson commented on a change in pull request #9928: Fix various processing buffer leaks and simplify BlockingPool.

jihoonson commented on a change in pull request #9928:
URL: https://github.com/apache/druid/pull/9928#discussion_r430806515



##########
File path: processing/src/main/java/org/apache/druid/query/topn/PooledTopNAlgorithm.java
##########
@@ -243,27 +240,38 @@ public PooledTopNParams makeInitParams(ColumnSelectorPlus selectorPlus, Cursor c
       }
     };
 
-    final int numBytesToWorkWith = resultsBuf.remaining();
-    final int[] aggregatorSizes = new int[query.getAggregatorSpecs().size()];
-    int numBytesPerRecord = 0;
+    final ResourceHolder<ByteBuffer> resultsBufHolder = bufferPool.take();
 
-    for (int i = 0; i < query.getAggregatorSpecs().size(); ++i) {
-      aggregatorSizes[i] = query.getAggregatorSpecs().get(i).getMaxIntermediateSizeWithNulls();
-      numBytesPerRecord += aggregatorSizes[i];
-    }
+    try {
+      final ByteBuffer resultsBuf = resultsBufHolder.get();
+      resultsBuf.clear();
+
+      final int numBytesToWorkWith = resultsBuf.remaining();
+      final int[] aggregatorSizes = new int[query.getAggregatorSpecs().size()];
+      int numBytesPerRecord = 0;
 
-    final int numValuesPerPass = numBytesPerRecord > 0 ? numBytesToWorkWith / numBytesPerRecord : cardinality;
-
-    return PooledTopNParams.builder()
-                           .withSelectorPlus(selectorPlus)
-                           .withCursor(cursor)
-                           .withResultsBufHolder(resultsBufHolder)
-                           .withResultsBuf(resultsBuf)
-                           .withArrayProvider(arrayProvider)
-                           .withNumBytesPerRecord(numBytesPerRecord)
-                           .withNumValuesPerPass(numValuesPerPass)
-                           .withAggregatorSizes(aggregatorSizes)
-                           .build();
+      for (int i = 0; i < query.getAggregatorSpecs().size(); ++i) {
+        aggregatorSizes[i] = query.getAggregatorSpecs().get(i).getMaxIntermediateSizeWithNulls();
+        numBytesPerRecord += aggregatorSizes[i];
+      }
+
+      final int numValuesPerPass = numBytesPerRecord > 0 ? numBytesToWorkWith / numBytesPerRecord : cardinality;

Review comment:
       What line can throw an exception? Or is this more like to be safer?




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