github-advanced-security[bot] commented on code in PR #18731:
URL: https://github.com/apache/druid/pull/18731#discussion_r2712144894
##########
processing/src/test/java/org/apache/druid/query/groupby/epinephelinae/LimitedBufferHashGrouperTest.java:
##########
@@ -307,6 +307,63 @@
Assert.assertEquals(LIMIT, i);
}
+ @Test
+ public void testMaxMergeBufferUsedBytesTracksMaxUsageAfterReset()
+ {
+ final GroupByTestColumnSelectorFactory columnSelectorFactory =
GrouperTestUtil.newColumnSelectorFactory();
+ final LimitedBufferHashGrouper<IntKey> grouper =
makeGrouper(columnSelectorFactory, 20000);
+
+ Assert.assertEquals(0L, grouper.getMergeBufferUsedBytes());
+ columnSelectorFactory.setRow(new MapBasedRow(0, ImmutableMap.of("value",
10L)));
+
+ Assert.assertTrue(String.valueOf(KEY_BASE), grouper.aggregate(new
IntKey(KEY_BASE)).isOk());
+ final long usagePerEntry = grouper.getMergeBufferUsedBytes();
+
+ grouper.reset();
+ Assert.assertEquals(0, grouper.getSize());
+ Assert.assertEquals(usagePerEntry, grouper.getMergeBufferUsedBytes());
+
+ // Add 10 entries after reset
+ for (int i = 0; i < 10; i++) {
+ Assert.assertTrue(String.valueOf(i + KEY_BASE), grouper.aggregate(new
IntKey(i + KEY_BASE)).isOk());
+ }
+
+ Assert.assertEquals(10 * usagePerEntry, grouper.getMergeBufferUsedBytes());
+ }
+
+ @Test
+ public void testMaxMergeBufferUsedBytesAfterBufferSwap()
+ {
+ // This test closely follows the flow of testLimitAndBufferSwapping().
+ final GroupByTestColumnSelectorFactory columnSelectorFactory =
GrouperTestUtil.newColumnSelectorFactory();
+ final LimitedBufferHashGrouper<IntKey> grouper =
makeGrouper(columnSelectorFactory, 20000);
+
+ columnSelectorFactory.setRow(new MapBasedRow(0, ImmutableMap.of("value",
10L)));
+
+ // Calculate usage per entry from first entry
+ Assert.assertTrue(String.valueOf(KEY_BASE), grouper.aggregate(new
IntKey(KEY_BASE)).isOk());
+ final long usagePerEntry = grouper.getMergeBufferUsedBytes();
+
+ // This results in 13 swaps and final size of 116 (100 keys + 16 new keys
after last swap)
+ for (int i = 1; i < NUM_ROWS; i++) {
+ Assert.assertTrue(String.valueOf(i + KEY_BASE), grouper.aggregate(new
IntKey(i + KEY_BASE)).isOk());
+ }
+
+ Assert.assertEquals(13, grouper.getGrowthCount());
+ Assert.assertEquals(116, grouper.getSize());
+ Assert.assertEquals(168, grouper.getMaxSize());
+
+ // Peak usage is the sum of hash table peak and heap peak, which peak at
different sizes...
+ // Hash table peak: maxSize (168) * bucketSizeWithHash
+ // Heap peak: (LIMIT + 1) * Integer.BYTES (4) = 404 (heap can temporarily
have LIMIT + 1 before removing one)
+ final long bucketSizeWithHash = usagePerEntry - Integer.BYTES;
+ final long hashTablePeak = grouper.getMaxSize() * bucketSizeWithHash;
+ final long heapPeak = (LIMIT + 1) * Integer.BYTES;
Review Comment:
## Result of multiplication cast to wider type
Potential overflow in [int multiplication](1) before it is converted to long
by use in an assignment context.
[Show more
details](https://github.com/apache/druid/security/code-scanning/10777)
--
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]