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


##########
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/hybrid/tiered/netty/TestingNettyConnectionWriter.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.netty;
+
+import javax.annotation.Nullable;
+
+import java.util.function.Supplier;
+
+/** Test implementation for {@link NettyConnectionWriter}. */
+public class TestingNettyConnectionWriter implements NettyConnectionWriter {
+
+    private final Runnable writeBufferFunction;
+
+    private final Supplier<NettyConnectionId> nettyConnectionIdSupplier;
+
+    private final Supplier<Integer> numQueuedBuffersSupplier;
+
+    private final Runnable closeFunction;
+
+    private TestingNettyConnectionWriter(
+            Runnable writeBufferFunction,
+            Supplier<NettyConnectionId> nettyConnectionIdSupplier,
+            Supplier<Integer> numQueuedBuffersSupplier,
+            Runnable closeFunction) {
+        this.writeBufferFunction = writeBufferFunction;
+        this.nettyConnectionIdSupplier = nettyConnectionIdSupplier;
+        this.numQueuedBuffersSupplier = numQueuedBuffersSupplier;
+        this.closeFunction = closeFunction;
+    }
+
+    @Override
+    public void writeBuffer(NettyPayload nettyPayload) {
+        writeBufferFunction.run();
+    }
+
+    @Override
+    public NettyConnectionId getNettyConnectionId() {
+        return nettyConnectionIdSupplier.get();
+    }
+
+    @Override
+    public int numQueuedBuffers() {
+        return numQueuedBuffersSupplier.get();
+    }
+
+    @Override
+    public void close(@Nullable Throwable error) {
+        closeFunction.run();

Review Comment:
   Fixed.



##########
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/hybrid/tiered/tier/memory/MemoryTierProducerAgent.java:
##########
@@ -0,0 +1,175 @@
+/*
+ * 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.memory;
+
+import org.apache.flink.core.memory.MemorySegment;
+import org.apache.flink.core.memory.MemorySegmentFactory;
+import org.apache.flink.runtime.io.network.api.EndOfSegmentEvent;
+import org.apache.flink.runtime.io.network.api.serialization.EventSerializer;
+import org.apache.flink.runtime.io.network.buffer.Buffer;
+import org.apache.flink.runtime.io.network.buffer.FreeingBufferRecycler;
+import org.apache.flink.runtime.io.network.buffer.NetworkBuffer;
+import 
org.apache.flink.runtime.io.network.partition.hybrid.tiered.common.TieredStoragePartitionId;
+import 
org.apache.flink.runtime.io.network.partition.hybrid.tiered.common.TieredStorageSubpartitionId;
+import 
org.apache.flink.runtime.io.network.partition.hybrid.tiered.netty.NettyConnectionId;
+import 
org.apache.flink.runtime.io.network.partition.hybrid.tiered.netty.NettyConnectionWriter;
+import 
org.apache.flink.runtime.io.network.partition.hybrid.tiered.netty.NettyServiceProducer;
+import 
org.apache.flink.runtime.io.network.partition.hybrid.tiered.netty.TieredStorageNettyService;
+import 
org.apache.flink.runtime.io.network.partition.hybrid.tiered.storage.TieredStorageMemoryManager;
+import 
org.apache.flink.runtime.io.network.partition.hybrid.tiered.storage.TieredStorageResourceRegistry;
+import 
org.apache.flink.runtime.io.network.partition.hybrid.tiered.tier.TierProducerAgent;
+import org.apache.flink.util.ExceptionUtils;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+import static 
org.apache.flink.runtime.io.network.buffer.Buffer.DataType.END_OF_SEGMENT;
+import static org.apache.flink.util.Preconditions.checkArgument;
+
+/** The memory tier implementation of {@link TierProducerAgent}. */
+public class MemoryTierProducerAgent implements TierProducerAgent, 
NettyServiceProducer {
+
+    private final int numBuffersPerSegment;
+
+    private final TieredStorageMemoryManager memoryManager;
+
+    /**
+     * Record the writ bytes to each subpartition. When starting a new 
segment, the value will be
+     * reset to 0.
+     */
+    private final int[] currentSubpartitionWriteBuffers;
+
+    /**
+     * Whether a subpartition's netty connection has been established. The 
array index is
+     * corresponding to the subpartition id.
+     */
+    private final boolean[] nettyConnectionEstablished;
+
+    private final MemoryTierSubpartitionProducerAgent[] 
subpartitionProducerAgents;
+
+    public MemoryTierProducerAgent(
+            TieredStoragePartitionId partitionId,
+            int numSubpartitions,
+            int bufferSizeBytes,
+            int segmentSizeBytes,
+            boolean isBroadcastOnly,
+            TieredStorageMemoryManager memoryManager,
+            TieredStorageNettyService nettyService,
+            TieredStorageResourceRegistry resourceRegistry) {
+        checkArgument(
+                segmentSizeBytes >= bufferSizeBytes, "One segment contains at 
least one buffer.");

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