TanYuxin-tyx commented on code in PR #22851:
URL: https://github.com/apache/flink/pull/22851#discussion_r1250829757


##########
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/hybrid/tiered/tier/remote/SubpartitionRemoteCacheManager.java:
##########
@@ -0,0 +1,188 @@
+/*
+ * 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.flink.runtime.io.network.partition.hybrid.tiered.tier.remote;
+
+import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.flink.runtime.io.network.buffer.Buffer;
+import 
org.apache.flink.runtime.io.network.partition.hybrid.tiered.common.TieredStoragePartitionId;
+import 
org.apache.flink.runtime.io.network.partition.hybrid.tiered.file.PartitionFileWriter;
+import 
org.apache.flink.runtime.io.network.partition.hybrid.tiered.storage.TieredStorageMemoryManager;
+import org.apache.flink.util.ExceptionUtils;
+import org.apache.flink.util.concurrent.FutureUtils;
+
+import net.jcip.annotations.GuardedBy;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Deque;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+
+import static org.apache.flink.util.Preconditions.checkState;
+
+/**
+ * This {@link SubpartitionRemoteCacheManager} is responsible for managing the 
buffers in a single
+ * subpartition.
+ */
+class SubpartitionRemoteCacheManager {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(SubpartitionRemoteCacheManager.class);
+
+    private final TieredStoragePartitionId partitionId;
+
+    private final int subpartitionId;
+
+    private final PartitionFileWriter partitionFileWriter;
+
+    /**
+     * All the buffers. The first field of the tuple is the buffer, while the 
second field of the
+     * buffer is the buffer index.
+     *
+     * <p>Note that this field can be accessed by the task thread or the write 
IO thread, so the
+     * thread safety should be ensured.
+     */
+    private final Deque<Tuple2<Buffer, Integer>> allBuffers = new 
LinkedList<>();
+
+    private CompletableFuture<Void> flushCompletableFuture = 
FutureUtils.completedVoidFuture();
+
+    /**
+     * Record the segment id that is writing to.
+     *
+     * <p>Note that when flushing buffers, this can be touched by task thread 
or the flushing
+     * thread, so the thread safety should be ensured.
+     */
+    @GuardedBy("allBuffers")
+    private int segmentId = -1;
+
+    /**
+     * Record the buffer index in the {@link SubpartitionRemoteCacheManager}. 
Each time a new buffer
+     * is added to the {@code allBuffers}, this field is increased by one.
+     *
+     * <p>Note that the field can only be touched by the task thread, so this 
field need not be
+     * guarded by any lock or synchronizations.
+     */
+    private int bufferIndex;
+
+    public SubpartitionRemoteCacheManager(
+            TieredStoragePartitionId partitionId,
+            int subpartitionId,
+            TieredStorageMemoryManager storageMemoryManager,
+            PartitionFileWriter partitionFileWriter) {
+        this.partitionId = partitionId;
+        this.subpartitionId = subpartitionId;
+        this.partitionFileWriter = partitionFileWriter;
+        storageMemoryManager.listenBufferReclaimRequest(this::flushBuffers);
+    }
+
+    // ------------------------------------------------------------------------
+    //  Called by RemoteCacheManager
+    // ------------------------------------------------------------------------
+
+    void startSegment(int segmentId) {
+        synchronized (allBuffers) {
+            this.segmentId = segmentId;

Review Comment:
   Fixed.



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