xintongsong commented on code in PR #22342: URL: https://github.com/apache/flink/pull/22342#discussion_r1222361205
########## flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/hybrid/tiered/netty/TieredStorageNettyServiceImpl.java: ########## @@ -0,0 +1,191 @@ +/* + * 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 org.apache.flink.runtime.io.network.partition.BufferAvailabilityListener; +import org.apache.flink.runtime.io.network.partition.ResultSubpartitionView; +import org.apache.flink.runtime.io.network.partition.consumer.InputChannel; +import org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate; +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.shuffle.TieredResultPartition; +import org.apache.flink.runtime.io.network.partition.hybrid.tiered.storage.NettyPayload; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Queue; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.function.Function; + +import static org.apache.flink.util.Preconditions.checkState; + +/** The default implementation of {@link TieredStorageNettyService}. */ +public class TieredStorageNettyServiceImpl implements TieredStorageNettyService { + + // ------------------------------------ + // For producer side + // ------------------------------------ + + private final Map<TieredStoragePartitionId, List<NettyServiceProducer>> + registeredServiceProducers = new ConcurrentHashMap<>(); + + private final Map<NettyConnectionId, BufferAvailabilityListener> + registeredAvailabilityListeners = new ConcurrentHashMap<>(); + + private final Map<TieredStoragePartitionId, Map<TieredStorageSubpartitionId, Integer>> + registeredChannelIndexes = new ConcurrentHashMap<>(); Review Comment: Shouldn't this belong to the consumer side? ########## flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/hybrid/tiered/netty/NettyConnectionReaderImpl.java: ########## @@ -0,0 +1,77 @@ +/* + * 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 org.apache.flink.runtime.io.network.buffer.Buffer; +import org.apache.flink.runtime.io.network.partition.consumer.InputChannel; +import org.apache.flink.util.ExceptionUtils; + +import java.io.IOException; +import java.util.Optional; +import java.util.function.Function; + +/** The default implementation of {@link NettyConnectionReader}. */ +public class NettyConnectionReaderImpl implements NettyConnectionReader { + + /** The index of input channel related to the reader. */ + private final int inputChannelIndex; + + /** The provider to provide the input channel by channel index. */ + private final Function<Integer, InputChannel> inputChannelProvider; + + /** The helper is used to notify the available and priority status of reader. */ + private final NettyConnectionReaderAvailabilityAndPriorityHelper helper; + + /** The last required segment id. */ + private int lastRequiredSegmentId = 0; + + public NettyConnectionReaderImpl( + int inputChannelIndex, + Function<Integer, InputChannel> inputChannelProvider, Review Comment: Why do we need this integer as the function input? ########## flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/hybrid/tiered/storage/NettyPayload.java: ########## @@ -0,0 +1,114 @@ +/* + * 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.storage; + +import org.apache.flink.runtime.io.network.buffer.Buffer; + +import javax.annotation.Nullable; + +import java.util.Optional; + +import static org.apache.flink.util.Preconditions.checkState; + +/** + * The {@link NettyPayload} represents the payload that will be transferred to netty connection. It + * could indicate a combination of buffer, buffer index, and its subpartition id, and it could also + * indicate an error or a segment id. + */ +public class NettyPayload { + + /** + * The data buffer. If the buffer is not null, bufferIndex and subpartitionId will be + * non-negative, error will be null, segmentId will be -1; + */ + @Nullable private final Buffer buffer; + + /** + * The error information. If the error is not null, buffer will be null, segmentId and + * bufferIndex and subpartitionId will be -1. + */ + @Nullable private final Throwable error; + + /** + * The index of buffer. If the buffer index is non-negative, buffer won't be null, error will be + * null, subpartitionId will be non-negative, segmentId will be -1. + */ + private final int bufferIndex; + + /** + * The id of subpartition. If the subpartition id is non-negative, buffer won't be null, error + * will be null, bufferIndex will be non-negative, segmentId will be -1. + */ + private final int subpartitionId; + + /** + * The id of segment. If the segment id is non-negative, buffer and error be null, bufferIndex + * and subpartitionId will be -1. + */ + private final int segmentId; + + private NettyPayload( + @Nullable Buffer buffer, + int bufferIndex, + int subpartitionId, + @Nullable Throwable error, + int segmentId) { + this.buffer = buffer; + this.bufferIndex = bufferIndex; + this.subpartitionId = subpartitionId; + this.error = error; + this.segmentId = segmentId; + } + + public static NettyPayload newBuffer(Buffer buffer, int bufferIndex, int subpartitionId) { + checkState(buffer != null && bufferIndex != -1 && subpartitionId != -1); + return new NettyPayload(buffer, bufferIndex, subpartitionId, null, -1); + } + + public static NettyPayload newError(Throwable error) { + checkState(error != null); + return new NettyPayload(null, -1, -1, error, -1); + } + + public static NettyPayload newSegment(int segmentId) { + checkState(segmentId != -1); + return new NettyPayload(null, -1, -1, null, segmentId); + } + + public Optional<Buffer> getBuffer() { + return buffer != null ? Optional.of(buffer) : Optional.empty(); + } + + @Nullable + public Throwable getError() { + return error; + } Review Comment: Optional -- 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]
