zhztheplayer commented on a change in pull request #7030:
URL: https://github.com/apache/arrow/pull/7030#discussion_r439266993



##########
File path: java/dataset/src/main/java/org/apache/arrow/memory/Ownerships.java
##########
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.arrow.memory;
+
+/**
+ * Utility class managing ownership's transferring between Native Arrow 
buffers and Java Arrow buffers.
+ */
+public class Ownerships {
+  private static final Ownerships INSTANCE = new Ownerships();
+
+  private Ownerships() {
+  }
+
+  public static Ownerships get() {
+    return INSTANCE;
+  }
+
+  /**
+   * Returned ledger's ref count is initialized or increased by 1.
+   */
+  public BufferLedger takeOwnership(BaseAllocator allocator, AllocationManager 
allocationManager) {
+    final BufferLedger ledger = allocationManager.associate(allocator);
+    long size = allocationManager.getSize();
+    boolean succeed = allocator.forceAllocate(size);
+    if (!succeed) {
+      throw new OutOfMemoryException("Target allocator is full");
+    }
+    ((BaseAllocator) 
allocationManager.getOwningLedger().getAllocator()).releaseBytes(size);

Review comment:
       Yes calls to `forceAllocate` should be synchronized.
   
   The fix appear to be in a separate topic because in Java API we don't yet 
provide give allocator the functionality to take over ownerless memory which 
requires for some slight refactors to allocation process. I'll open a ticket 
for that.




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to