-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FLINK-21348] Add tests for AdaptiveScheduler's StateWithExecutionGraph #15342
Conversation
Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community Automated ChecksLast check on commit e326380 (Tue Mar 23 13:17:48 UTC 2021) Warnings:
Mention the bot in a comment to re-run the automated checks. Review Progress
Please see the Pull Request Review Guide for a full explanation of the review process. The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required Bot commandsThe @flinkbot bot supports the following commands:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for creating this PR @rmetzger. The changes look overall good. I had few comments. Please take a look.
void disposeAllOperatorCoordinators(); | ||
|
||
public OperatorCoordinatorHandler( | ||
ExecutionGraph executionGraph, Consumer<Throwable> globalFailureHandler) { | ||
this.executionGraph = executionGraph; | ||
void deliverOperatorEventToCoordinator( | ||
ExecutionAttemptID taskExecutionId, OperatorID operatorId, OperatorEvent evt) | ||
throws FlinkException; | ||
|
||
this.coordinatorMap = createCoordinatorMap(executionGraph); | ||
this.globalFailureHandler = globalFailureHandler; | ||
} | ||
|
||
private Map<OperatorID, OperatorCoordinatorHolder> createCoordinatorMap( | ||
ExecutionGraph executionGraph) { | ||
Map<OperatorID, OperatorCoordinatorHolder> coordinatorMap = new HashMap<>(); | ||
for (ExecutionJobVertex vertex : executionGraph.getAllVertices().values()) { | ||
for (OperatorCoordinatorHolder holder : vertex.getOperatorCoordinators()) { | ||
coordinatorMap.put(holder.operatorId(), holder); | ||
} | ||
} | ||
return coordinatorMap; | ||
} | ||
|
||
public void initializeOperatorCoordinators(ComponentMainThreadExecutor mainThreadExecutor) { | ||
for (OperatorCoordinatorHolder coordinatorHolder : coordinatorMap.values()) { | ||
coordinatorHolder.lazyInitialize(globalFailureHandler, mainThreadExecutor); | ||
} | ||
} | ||
|
||
public void startAllOperatorCoordinators() { | ||
final Collection<OperatorCoordinatorHolder> coordinators = coordinatorMap.values(); | ||
try { | ||
for (OperatorCoordinatorHolder coordinator : coordinators) { | ||
coordinator.start(); | ||
} | ||
} catch (Throwable t) { | ||
ExceptionUtils.rethrowIfFatalErrorOrOOM(t); | ||
coordinators.forEach(IOUtils::closeQuietly); | ||
throw new FlinkRuntimeException("Failed to start the operator coordinators", t); | ||
} | ||
} | ||
|
||
public void disposeAllOperatorCoordinators() { | ||
coordinatorMap.values().forEach(IOUtils::closeQuietly); | ||
} | ||
|
||
public void deliverOperatorEventToCoordinator( | ||
final ExecutionAttemptID taskExecutionId, | ||
final OperatorID operatorId, | ||
final OperatorEvent evt) | ||
throws FlinkException { | ||
|
||
// Failure semantics (as per the javadocs of the method): | ||
// If the task manager sends an event for a non-running task or an non-existing operator | ||
// coordinator, then respond with an exception to the call. If task and coordinator exist, | ||
// then we assume that the call from the TaskManager was valid, and any bubbling exception | ||
// needs to cause a job failure. | ||
|
||
final Execution exec = executionGraph.getRegisteredExecutions().get(taskExecutionId); | ||
if (exec == null || exec.getState() != ExecutionState.RUNNING) { | ||
// This situation is common when cancellation happens, or when the task failed while the | ||
// event was just being dispatched asynchronously on the TM side. | ||
// It should be fine in those expected situations to just ignore this event, but, to be | ||
// on the safe, we notify the TM that the event could not be delivered. | ||
throw new TaskNotRunningException( | ||
"Task is not known or in state running on the JobManager."); | ||
} | ||
|
||
final OperatorCoordinatorHolder coordinator = coordinatorMap.get(operatorId); | ||
if (coordinator == null) { | ||
throw new FlinkException("No coordinator registered for operator " + operatorId); | ||
} | ||
|
||
try { | ||
coordinator.handleEventFromOperator(exec.getParallelSubtaskIndex(), evt); | ||
} catch (Throwable t) { | ||
ExceptionUtils.rethrowIfFatalErrorOrOOM(t); | ||
globalFailureHandler.accept(t); | ||
} | ||
} | ||
|
||
public CompletableFuture<CoordinationResponse> deliverCoordinationRequestToCoordinator( | ||
OperatorID operator, CoordinationRequest request) throws FlinkException { | ||
|
||
final OperatorCoordinatorHolder coordinatorHolder = coordinatorMap.get(operator); | ||
if (coordinatorHolder == null) { | ||
throw new FlinkException("Coordinator of operator " + operator + " does not exist"); | ||
} | ||
|
||
final OperatorCoordinator coordinator = coordinatorHolder.coordinator(); | ||
if (coordinator instanceof CoordinationRequestHandler) { | ||
return ((CoordinationRequestHandler) coordinator).handleCoordinationRequest(request); | ||
} else { | ||
throw new FlinkException( | ||
"Coordinator of operator " + operator + " cannot handle client event"); | ||
} | ||
} | ||
CompletableFuture<CoordinationResponse> deliverCoordinationRequestToCoordinator( | ||
OperatorID operator, CoordinationRequest request) throws FlinkException; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JavaDocs are missing for this interface.
import java.util.function.Consumer; | ||
|
||
/** Handler implementation for the {@link OperatorCoordinator OperatorCoordinators}. */ | ||
public class OperatorCoordinatorHandlerImplementation implements OperatorCoordinatorHandler { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The naming pattern is unconventional. I think we do have the pattern DefaultXYZ
or XYZImpl
in the code base but not XYZImplementation
. Ideally one picks a meaningful name which tells us about the specific implementation but if you don't have a good idea, then stick to the existing naming patterns.
private static class MockOperatorCoordinatorHandler | ||
extends OperatorCoordinatorHandlerImplementation { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to extend the implementation or could we add a TestingOperatorCoordinatorHandler
?
new OperatorCoordinatorHandlerImplementation( | ||
executionGraph, | ||
globalFailure -> { | ||
throw new FlinkRuntimeException( | ||
"No global failures are expected", globalFailure); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use the TestingOperatorCoordinatorHandler
here?
Thanks a lot for your fast feedback! I hope I addressed all your concerns! |
3c30b1d
to
90f4e6d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating this PR @rmetzger. LGTM. +1 for merging after AZP gives green light.
Thanks a lot for your review. I'll merge this soon ;) |
What is the purpose of the change
Add more tests for StateWithExecutionGraph