Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.api.operators.sort;
import org.apache.flink.api.common.ExecutionConfig;
import org.apache.flink.api.common.typeutils.TypeComparator;
import org.apache.flink.api.common.typeutils.TypeSerializer;
import org.apache.flink.api.java.functions.KeySelector;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.configuration.AlgorithmOptions;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.core.memory.DataOutputSerializer;
import org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter;
import org.apache.flink.runtime.io.AvailabilityProvider;
import org.apache.flink.runtime.io.disk.iomanager.IOManager;
import org.apache.flink.runtime.jobgraph.tasks.TaskInvokable;
import org.apache.flink.runtime.memory.MemoryAllocationException;
import org.apache.flink.runtime.memory.MemoryManager;
import org.apache.flink.runtime.operators.sort.ExternalSorter;
import org.apache.flink.runtime.operators.sort.PushSorter;
import org.apache.flink.streaming.api.operators.BoundedMultiInput;
import org.apache.flink.streaming.api.operators.InputSelectable;
import org.apache.flink.streaming.api.operators.InputSelection;
import org.apache.flink.streaming.api.watermark.Watermark;
import org.apache.flink.streaming.runtime.io.DataInputStatus;
import org.apache.flink.streaming.runtime.io.PushingAsyncDataInput;
import org.apache.flink.streaming.runtime.io.StreamInputProcessor;
import org.apache.flink.streaming.runtime.io.StreamTaskInput;
import org.apache.flink.streaming.runtime.streamrecord.LatencyMarker;
import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
import org.apache.flink.streaming.runtime.watermarkstatus.WatermarkStatus;
import org.apache.flink.util.ExceptionUtils;
import org.apache.flink.util.MutableObjectIterator;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
/**
* An input that wraps an underlying input and sorts the incoming records. It starts emitting
* records downstream only when all the other inputs coupled with this {@link
* MultiInputSortingDataInput} have finished sorting as well.
*
*
Moreover it will report it is {@link #isAvailable() available} or {@link
* #isApproximatelyAvailable() approximately available} if it has some records pending only if the
* head of the {@link CommonContext#getQueueOfHeads()} belongs to the input. That way there is only
* ever one input that reports it is available.
*
*
The sorter uses binary comparison of keys, which are extracted and serialized when received
* from the chained input. Moreover the timestamps of incoming records are used for secondary
* ordering. For the comparison it uses either {@link FixedLengthByteKeyComparator} if the length of
* the serialized key is constant, or {@link VariableLengthByteKeyComparator} otherwise.
*
*
Watermarks, watermark statuses, nor latency markers are propagated downstream as they do not
* make sense with buffered records. The input emits the largest watermark seen after all records.
*/
public final class MultiInputSortingDataInput implements StreamTaskInput {
private final int idx;
private final StreamTaskInput wrappedInput;
private final PushSorter>> sorter;
private final CommonContext commonContext;
private final SortingPhaseDataOutput sortingPhaseDataOutput = new SortingPhaseDataOutput();
private final KeySelector keySelector;
private final TypeSerializer keySerializer;
private final DataOutputSerializer dataOutputSerializer;
private MutableObjectIterator>> sortedInput;
private long seenWatermark = Long.MIN_VALUE;
private MultiInputSortingDataInput(
CommonContext commonContext,
StreamTaskInput wrappedInput,
int inputIdx,
PushSorter>> sorter,
KeySelector keySelector,
TypeSerializer keySerializer,
DataOutputSerializer dataOutputSerializer) {
this.wrappedInput = wrappedInput;
this.idx = inputIdx;
this.commonContext = commonContext;
this.sorter = sorter;
this.keySelector = keySelector;
this.keySerializer = keySerializer;
this.dataOutputSerializer = dataOutputSerializer;
}
/**
* A wrapper that combines sorting {@link StreamTaskInput inputs} with a {@link InputSelectable}
* that should be used to choose which input to consume next from.
*/
public static class SelectableSortingInputs {
private final InputSelectable inputSelectable;
private final StreamTaskInput[] sortedInputs;
private final StreamTaskInput[] passThroughInputs;
public SelectableSortingInputs(
StreamTaskInput[] sortedInputs,
StreamTaskInput[] passThroughInputs,
InputSelectable inputSelectable) {
this.sortedInputs = sortedInputs;
this.passThroughInputs = passThroughInputs;
this.inputSelectable = inputSelectable;
}
public InputSelectable getInputSelectable() {
return inputSelectable;
}
public StreamTaskInput[] getSortedInputs() {
return sortedInputs;
}
public StreamTaskInput[] getPassThroughInputs() {
return passThroughInputs;
}
}
public static SelectableSortingInputs wrapInputs(
TaskInvokable containingTask,
StreamTaskInput