pnowojski commented on a change in pull request #8476: [FLINK-12490][network] 
Introduce Input and NetworkInput interfaces
URL: https://github.com/apache/flink/pull/8476#discussion_r286070802
 
 

 ##########
 File path: 
flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/io/NetworkInput.java
 ##########
 @@ -0,0 +1,154 @@
+/*
+ * 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.streaming.runtime.io;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.runtime.event.AbstractEvent;
+import org.apache.flink.runtime.io.disk.iomanager.IOManager;
+import org.apache.flink.runtime.io.network.api.EndOfPartitionEvent;
+import 
org.apache.flink.runtime.io.network.api.serialization.RecordDeserializer;
+import 
org.apache.flink.runtime.io.network.api.serialization.RecordDeserializer.DeserializationResult;
+import 
org.apache.flink.runtime.io.network.api.serialization.SpillingAdaptiveSpanningRecordDeserializer;
+import org.apache.flink.runtime.io.network.buffer.Buffer;
+import org.apache.flink.runtime.io.network.partition.consumer.BufferOrEvent;
+import org.apache.flink.runtime.io.network.partition.consumer.InputGate;
+import org.apache.flink.runtime.plugable.DeserializationDelegate;
+import org.apache.flink.runtime.plugable.NonReusingDeserializationDelegate;
+import org.apache.flink.streaming.runtime.streamrecord.StreamElement;
+import org.apache.flink.streaming.runtime.streamrecord.StreamElementSerializer;
+
+import java.io.IOException;
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * Implementation of taking {@link InputGate} as {@link Input}.
+ */
+@Internal
+public final class NetworkInput implements Input {
+
+       private final int numberOfInputChannels;
+
+       private final CheckpointBarrierHandler barrierHandler;
+
+       private final DeserializationDelegate<StreamElement> 
deserializationDelegate;
+
+       private final 
RecordDeserializer<DeserializationDelegate<StreamElement>>[] 
recordDeserializers;
+
+       /**
+        * The channel from which a buffer came, tracked so that we can 
appropriately map
+        * the watermarks and watermark statuses to the correct channel index 
of the correct valve.
+        */
+       private int currentChannel = -1;
+
+       private RecordDeserializer<DeserializationDelegate<StreamElement>> 
currentRecordDeserializer = null;
+
+       private boolean isFinished = false;
+
+       @SuppressWarnings("unchecked")
+       public NetworkInput(
+                       CheckpointBarrierHandler barrierHandler,
+                       TypeSerializer<?> inputSerializer,
+                       IOManager ioManager) {
+               this.barrierHandler = barrierHandler;
+               this.numberOfInputChannels = 
barrierHandler.getNumberOfInputChannels();
+               this.deserializationDelegate = new 
NonReusingDeserializationDelegate<>(
+                       new StreamElementSerializer<>(inputSerializer));
+
+               // Initialize one deserializer per input channel
+               this.recordDeserializers = new 
SpillingAdaptiveSpanningRecordDeserializer[numberOfInputChannels];
+               for (int i = 0; i < recordDeserializers.length; i++) {
+                       recordDeserializers[i] = new 
SpillingAdaptiveSpanningRecordDeserializer<>(
+                               ioManager.getSpillingDirectoriesPaths());
+               }
+       }
+
+       @Override
+       public StreamElement pollNext() throws Exception {
+
+               while (true) {
+                       // get the stream element from the deserializer
+                       if (currentRecordDeserializer != null) {
+                               DeserializationResult result = 
currentRecordDeserializer.getNextRecord(deserializationDelegate);
+                               if (result.isBufferConsumed()) {
+                                       
currentRecordDeserializer.getCurrentBuffer().recycleBuffer();
+                                       currentRecordDeserializer = null;
+                               }
+
+                               if (result.isFullRecord()) {
+                                       return 
deserializationDelegate.getInstance();
+                               }
+                       }
+
+                       Optional<BufferOrEvent> bufferOrEvent = 
barrierHandler.pollNext();
 
 Review comment:
   True, that's the next thing that I want to address. In this commit I just 
want to make sure that the basic abstraction of `NetworkInput` is not 
introducing performance regressions, which was one of our concern in the 
offline discussions.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to