yaooqinn commented on code in PR #13754:
URL: https://github.com/apache/gluten/pull/13754#discussion_r4725300560


##########
backends-velox/src/test/java/org/apache/gluten/columnarbatch/ColumnarBatchTest.java:
##########
@@ -232,6 +234,52 @@ public void testToString() {
         });
   }
 
+  @Test
+  public void testUntrackedLoadDoesNotReserveNativeMemoryTwice() {
+    TaskResources$.MODULE$.runUnsafe(
+        () -> {
+          final int numRows = 4 * 1024 * 1024;
+          final long dataBytes = numRows * 8L;
+          final Iterator<InternalRow> rows =
+              new Iterator<InternalRow>() {
+                private int rowId = 0;
+
+                @Override
+                public boolean hasNext() {
+                  return rowId < numRows;
+                }
+
+                @Override
+                public InternalRow next() {
+                  return new GenericInternalRow(new Object[] {(long) rowId++});
+                }
+              };
+          final ColumnarBatch veloxBatch =
+              RowToVeloxColumnarExec.toColumnarBatchIterator(
+                      JavaConverters.asScalaIterator(rows),
+                      StructType.fromDDL("a bigint"),
+                      numRows,
+                      Integer.MAX_VALUE)
+                  .next();
+          Assert.assertEquals(numRows, veloxBatch.numRows());
+          // The buffers of the loaded batch are still allocated from (and 
reserved by) the Velox
+          // memory pool, so loading them into the untracked allocator (as 
operators do for the
+          // batches they only read) must not reserve Spark memory for them 
again.
+          final SimpleMemoryUsageRecorder usage = 
TaskResources$.MODULE$.getSharedUsage();
+          final long beforeLoad = usage.current();
+          final ColumnarBatch loaded =
+              
ColumnarBatches.load(ArrowBufferAllocators.contextUntrackedInstance(), 
veloxBatch);
+          final long reservedByLoad = usage.current() - beforeLoad;
+          loaded.close();
+          Assert.assertTrue(
+              String.format(
+                  "Loading %d bytes of native data reserved %d more bytes",
+                  dataBytes, reservedByLoad),
+              reservedByLoad < dataBytes / 2);

Review Comment:
   This loads straight into `contextUntrackedInstance()`, whose listener is 
`NOOP`, so it checks the allocator, not the three call sites: it stays green if 
any of them goes back to `contextInstance()`, and it can't fail if 
`getSharedUsage()` stopped seeing Arrow reservations. Could you add the control 
from the PR description, loading a second native batch into `contextInstance()` 
and asserting it reserves at least `dataBytes`? Also, the fork CI has no run 
for the current head `3ae7ec3a`; could you push again so it runs?
   



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