emkornfield commented on a change in pull request #11182:
URL: https://github.com/apache/arrow/pull/11182#discussion_r712315553



##########
File path: 
java/memory/memory-core/src/main/java/org/apache/arrow/memory/BaseAllocator.java
##########
@@ -272,18 +282,37 @@ public ArrowBuf buffer(final long initialRequestSize, 
BufferManager manager) {
     }
 
     boolean success = false;
+    final ArrowBuf buffer;
     try {
-      ArrowBuf buffer = bufferWithoutReservation(actualRequestSize, manager);
+      buffer = bufferWithoutReservation(actualRequestSize, manager);
       success = true;
-      listener.onAllocation(actualRequestSize);
-      return buffer;
     } catch (OutOfMemoryError e) {
       throw e;
     } finally {
       if (!success) {
         releaseBytes(actualRequestSize);
       }
     }
+
+    final long grantedSize = buffer.getReferenceManager().getSize();
+    if (grantedSize != actualRequestSize) {
+      // reallocate bytes using the actual returned chunk size
+      long diff = grantedSize - actualRequestSize;
+      if (diff > 0) {
+        AllocationOutcome reallocateOutcome = allocateBytes(diff);
+        if (!reallocateOutcome.isOk()) {
+          // forcibly allocate for remaining bytes, then release all
+          forceAllocate(diff);
+          buffer.close();
+          throw new OutOfMemoryException(createErrorMsg(this, grantedSize, 
actualRequestSize,
+              initialRequestSize), reallocateOutcome.getDetails());
+        }
+      } else {
+        releaseBytes(-diff);

Review comment:
       it seems like getting less then requested should be an error?




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


Reply via email to