zhijiangW commented on a change in pull request #11507: [FLINK-16587] Add basic
CheckpointBarrierHandler for unaligned checkpoint
URL: https://github.com/apache/flink/pull/11507#discussion_r400815721
##########
File path:
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/consumer/UnionInputGate.java
##########
@@ -77,37 +77,34 @@
*/
private final LinkedHashSet<InputGate> inputGatesWithData = new
LinkedHashSet<>();
- /** The total number of input channels across all unioned input gates.
*/
- private final int totalNumberOfInputChannels;
+ /** Input channels across all unioned input gates. */
+ private final InputChannel[] inputChannels;
/**
* A mapping from input gate to (logical) channel index offset. Valid
channel indexes go from 0
* (inclusive) to the total number of input channels (exclusive).
*/
- private final Map<InputGate, Integer> inputGateToIndexOffsetMap;
+ private final int[] inputGateChannelIndexOffsets;
public UnionInputGate(InputGate... inputGates) {
this.inputGates = checkNotNull(inputGates);
checkArgument(inputGates.length > 1, "Union input gate should
union at least two input gates.");
- this.inputGateToIndexOffsetMap =
Maps.newHashMapWithExpectedSize(inputGates.length);
this.inputGatesWithRemainingData =
Sets.newHashSetWithExpectedSize(inputGates.length);
+ final int maxGateIndex =
Arrays.stream(inputGates).mapToInt(InputGate::getGateIndex).max().orElse(0);
+ inputGateChannelIndexOffsets = new int[maxGateIndex + 1];
int currentNumberOfInputChannels = 0;
+ for (final InputGate inputGate : inputGates) {
+ currentNumberOfInputChannels +=
inputGate.getNumberOfInputChannels();
+ inputGateChannelIndexOffsets[inputGate.getGateIndex()]
= currentNumberOfInputChannels;
+ }
+ inputChannels = Arrays.stream(inputGates)
+ .flatMap(gate -> IntStream.range(0,
gate.getNumberOfInputChannels()).mapToObj(gate::getChannel))
+ .toArray(InputChannel[]::new);
synchronized (inputGatesWithData) {
for (InputGate inputGate : inputGates) {
- if (inputGate instanceof UnionInputGate) {
- // if we want to add support for this,
we need to implement pollNext()
- throw new
UnsupportedOperationException("Cannot union a union of input gates.");
- }
-
- // The offset to use for buffer or event
instances received from this input gate.
-
inputGateToIndexOffsetMap.put(checkNotNull(inputGate),
currentNumberOfInputChannels);
- inputGatesWithRemainingData.add(inputGate);
Review comment:
why remove this `inputGatesWithRemainingData.add(inputGate)`
----------------------------------------------------------------
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