xintongsong commented on code in PR #23919:
URL: https://github.com/apache/flink/pull/23919#discussion_r1426213522


##########
flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/io/RecordAttributesCombiner.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.streaming.runtime.io.PushingAsyncDataInput.DataOutput;
+import org.apache.flink.streaming.runtime.streamrecord.RecordAttributes;
+import org.apache.flink.streaming.runtime.streamrecord.RecordAttributesBuilder;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+
+/** RecordAttributesValve combine RecordAttributes from different input 
channels. */
+public class RecordAttributesCombiner {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(RecordAttributesCombiner.class);
+
+    private final int numInputChannels;
+    private final RecordAttributes[] allChannelRecordAttributes;
+    private int nonBacklogChannelsCnt = 0;
+    private RecordAttributes lastOutputAttributes = null;
+
+    public RecordAttributesCombiner(int numInputChannels) {
+        this.numInputChannels = numInputChannels;
+        this.allChannelRecordAttributes = new 
RecordAttributes[numInputChannels];
+    }
+
+    public void inputRecordAttributes(
+            RecordAttributes recordAttributes, int channelIdx, DataOutput<?> 
output)
+            throws Exception {
+        LOG.debug("RecordAttributes: {} from channel idx: {}", 
recordAttributes, channelIdx);
+        RecordAttributes lastChannelRecordAttributes = 
allChannelRecordAttributes[channelIdx];
+        allChannelRecordAttributes[channelIdx] = recordAttributes;
+
+        // skip if the input RecordAttributes of the input channel is the same 
as the last.
+        if (recordAttributes.equals(lastChannelRecordAttributes)) {
+            return;
+        }
+
+        final RecordAttributesBuilder builder =
+                new RecordAttributesBuilder(Collections.emptyList());
+
+        builder.setBacklog(combineIsBacklog(lastChannelRecordAttributes, 
recordAttributes));
+
+        final RecordAttributes outputAttribute = builder.build();
+        if (!outputAttribute.equals(lastOutputAttributes)) {
+            output.emitRecordAttributes(outputAttribute);
+            lastOutputAttributes = outputAttribute;
+        }
+    }
+
+    /** If any of the input channels is backlog, the combined RecordAttributes 
is backlog. */
+    private boolean combineIsBacklog(
+            RecordAttributes lastRecordAttributes, RecordAttributes 
recordAttributes) {
+        if (lastRecordAttributes == null
+                || lastRecordAttributes.isBacklog() != 
recordAttributes.isBacklog()) {
+            if (lastRecordAttributes != null && recordAttributes.isBacklog()) {
+                nonBacklogChannelsCnt -= 1;
+            }
+            if (!recordAttributes.isBacklog()) {
+                nonBacklogChannelsCnt += 1;
+            }
+        }
+
+        return nonBacklogChannelsCnt < numInputChannels;
+    }

Review Comment:
   I'm trying to understand the behavior during job initialization. According 
to this method, this will be:
   
   * As soon as the first `RecordAttributes` is received, despite its 
`isBacklog` is true or false, the combiner will emit a `RecordAttributes` with 
`isBacklog` being false to the downstream, unless there's only one input 
channel. Is that correct?
   
   * Then the questions is, what happens before the first `RecordAttributes` is 
received? What is the initial status, and how should the operators behave? 
Would it be possible that the operators are initialized for one mode (e.g., 
non-backlog) and have to switch to another mode (e.g., backlog) before 
receiving any records? Or even worse, different operators might be initialized 
with inconsistent modes?



-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to