Skip to content
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

Closed

Conversation

rmetzger
Copy link
Contributor

What is the purpose of the change

Add more tests for StateWithExecutionGraph

@flinkbot
Copy link
Collaborator

Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community
to review your pull request. We will use this comment to track the progress of the review.

Automated Checks

Last check on commit e326380 (Tue Mar 23 13:17:48 UTC 2021)

Warnings:

  • No documentation files were touched! Remember to keep the Flink docs up to date!

Mention the bot in a comment to re-run the automated checks.

Review Progress

  • ❓ 1. The [description] looks good.
  • ❓ 2. There is [consensus] that the contribution should go into to Flink.
  • ❓ 3. Needs [attention] from.
  • ❓ 4. The change fits into the overall [architecture].
  • ❓ 5. Overall code [quality] is good.

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 commands
The @flinkbot bot supports the following commands:

  • @flinkbot approve description to approve one or more aspects (aspects: description, consensus, architecture and quality)
  • @flinkbot approve all to approve all aspects
  • @flinkbot approve-until architecture to approve everything until architecture
  • @flinkbot attention @username1 [@username2 ..] to require somebody's attention
  • @flinkbot disapprove architecture to remove an approval you gave earlier

@flinkbot
Copy link
Collaborator

flinkbot commented Mar 23, 2021

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run travis re-run the last Travis build
  • @flinkbot run azure re-run the last Azure build

Copy link
Contributor

@tillrohrmann tillrohrmann left a 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.

Comment on lines 34 to 69
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;
Copy link
Contributor

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 {
Copy link
Contributor

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.

Comment on lines 693 to 694
private static class MockOperatorCoordinatorHandler
extends OperatorCoordinatorHandlerImplementation {
Copy link
Contributor

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?

Comment on lines 163 to 168
new OperatorCoordinatorHandlerImplementation(
executionGraph,
globalFailure -> {
throw new FlinkRuntimeException(
"No global failures are expected", globalFailure);
});
Copy link
Contributor

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?

@rmetzger
Copy link
Contributor Author

Thanks a lot for your fast feedback! I hope I addressed all your concerns!

@rmetzger rmetzger force-pushed the FLINK-21348-state-w-exec-test branch from 3c30b1d to 90f4e6d Compare March 23, 2021 16:07
Copy link
Contributor

@tillrohrmann tillrohrmann left a 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.

@rmetzger
Copy link
Contributor Author

Thanks a lot for your review. I'll merge this soon ;)

@rmetzger rmetzger closed this in 55a1d1b Mar 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants