forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-19640] Enable sorting inputs for batch
This PR adds feature flags for enabling/disabling the sorting inputs and special types of a state backend and a timer service for BATCH execution runtime. Those options are enabled by default for BATCH runtime execution mode.
- Loading branch information
Showing
11 changed files
with
705 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...ava/src/main/java/org/apache/flink/streaming/runtime/translators/BatchExecutionUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* 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:https://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.translators; | ||
|
||
import org.apache.flink.configuration.ExecutionOptions; | ||
import org.apache.flink.core.memory.ManagedMemoryUseCase; | ||
import org.apache.flink.streaming.api.graph.StreamNode; | ||
import org.apache.flink.streaming.api.graph.TransformationTranslator; | ||
import org.apache.flink.streaming.api.operators.ChainingStrategy; | ||
import org.apache.flink.streaming.api.operators.InputSelectable; | ||
import org.apache.flink.streaming.api.operators.StreamOperator; | ||
import org.apache.flink.streaming.api.operators.StreamOperatorFactory; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.apache.flink.util.Preconditions.checkState; | ||
|
||
/** | ||
* A utility class for applying sorting inputs. | ||
*/ | ||
class BatchExecutionUtils { | ||
private static final Logger LOG = LoggerFactory.getLogger(BatchExecutionUtils.class); | ||
|
||
static void applySortingInputs( | ||
int transformationId, | ||
TransformationTranslator.Context context) { | ||
StreamNode node = context.getStreamGraph().getStreamNode(transformationId); | ||
boolean sortInputs = context.getGraphGeneratorConfig().get(ExecutionOptions.SORT_INPUTS); | ||
boolean isInputSelectable = isInputSelectable(node); | ||
|
||
adjustChainingStrategy(node); | ||
|
||
checkState( | ||
!isInputSelectable || !sortInputs, | ||
"Batch state backend and sorting inputs are not supported in graphs with an InputSelectable operator." | ||
); | ||
|
||
if (sortInputs) { | ||
LOG.debug("Enabling sorting inputs for an operator {}.", node); | ||
node.setSortedInputs(true); | ||
Map<ManagedMemoryUseCase, Integer> operatorScopeUseCaseWeights = new HashMap<>(); | ||
operatorScopeUseCaseWeights.put(ManagedMemoryUseCase.BATCH_OP, 1); | ||
node.setManagedMemoryUseCaseWeights( | ||
operatorScopeUseCaseWeights, | ||
Collections.emptySet() | ||
); | ||
} | ||
} | ||
|
||
@SuppressWarnings("rawtypes") | ||
private static boolean isInputSelectable(StreamNode node) { | ||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); | ||
Class<? extends StreamOperator> operatorClass = node.getOperatorFactory() | ||
.getStreamOperatorClass(classLoader); | ||
return InputSelectable.class.isAssignableFrom(operatorClass); | ||
} | ||
|
||
private static void adjustChainingStrategy(StreamNode node) { | ||
StreamOperatorFactory<?> operatorFactory = node.getOperatorFactory(); | ||
ChainingStrategy currentChainingStrategy = operatorFactory.getChainingStrategy(); | ||
switch (currentChainingStrategy) { | ||
case ALWAYS: | ||
case HEAD_WITH_SOURCES: | ||
LOG.debug( | ||
"Setting chaining strategy to HEAD for operator {}, because of the BATCH execution mode.", | ||
node); | ||
operatorFactory.setChainingStrategy(ChainingStrategy.HEAD); | ||
break; | ||
case NEVER: | ||
case HEAD: | ||
break; | ||
} | ||
} | ||
|
||
private BatchExecutionUtils() { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.