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_r400817529
##########
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) {
Review comment:
It is better to retain this check to solve my above comments
https://github.com/apache/flink/pull/11507/commits/63f5dcb77fce09d76e04f28fa50fc80d3ecfcc6d#r400814235.
Although it would still throw `UnsupportedOperationException` after
`getGateIndex`, the root cause message should be `Cannot union a union of input
gates`.
----------------------------------------------------------------
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