hudi-agent commented on code in PR #19728:
URL: https://github.com/apache/hudi/pull/19728#discussion_r3850684597


##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/sink/buffer/PreemptiveMemorySegmentPool.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * 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.hudi.sink.buffer;
+
+import org.apache.hudi.common.util.ValidationUtils;
+
+import org.apache.flink.core.memory.MemorySegment;
+import org.apache.flink.table.runtime.util.MemorySegmentPool;
+
+import javax.annotation.Nullable;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * A {@link MemorySegmentPool} wrapper that can reclaim pages from an inactive 
owner when the
+ * delegate pool is exhausted.
+ *
+ * <p>The owner represents the bucket whose buffer is currently requesting 
pages. The reclaimer
+ * must never reclaim that owner because the request may occur in the middle 
of serializing a row.
+ * If no other owner can release pages, this pool returns {@code null} and 
lets the caller handle
+ * the allocation failure.
+ */
+public class PreemptiveMemorySegmentPool implements MemorySegmentPool, 
Closeable {
+
+  /** Callback that reclaims memory from an owner other than the excluded 
in-flight owner. */
+  @FunctionalInterface
+  public interface MemoryReclaimer {
+    /**
+     * Reclaims memory from an inactive owner.
+     *
+     * @param excludedOwnerId the owner currently requesting a page
+     * @return {@code true} if memory was reclaimed and allocation should be 
retried
+     */
+    boolean reclaim(String excludedOwnerId);
+  }
+
+  private final MemorySegmentPool delegate;
+  private final MemoryReclaimer memoryReclaimer;
+
+  @Nullable
+  private String currentOwnerId;
+  private boolean preempting;

Review Comment:
   🤖 nit: could you rename `preempting` to `isPreempting`? Boolean fields 
typically read as predicates in this codebase (e.g. `isDiverged`), and the `is` 
prefix makes the guard in `nextSegment()` a bit easier to parse at a glance.
   
   <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



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