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

Fix the bug that masterOperation(with task param) is bypassed #4103

Merged
merged 3 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,15 @@ protected void masterOperation(Request request, ClusterState state, ActionListen
throw new UnsupportedOperationException("Must be overridden");
}

// TODO: Add abstract keyword after removing the deprecated masterOperation()
protected void clusterManagerOperation(Request request, ClusterState state, ActionListener<Response> listener) throws Exception {
masterOperation(request, state, listener);
}

/** @deprecated As of 2.2, because supporting inclusive language, replaced by {@link #clusterManagerOperation(Task, ClusterManagerNodeRequest, ClusterState, ActionListener)} */
/**
* Override this operation if access to the task parameter is needed
* @deprecated As of 2.2, because supporting inclusive language, replaced by {@link #clusterManagerOperation(Task, ClusterManagerNodeRequest, ClusterState, ActionListener)}
*/
@Deprecated
protected void masterOperation(Task task, Request request, ClusterState state, ActionListener<Response> listener) throws Exception {
clusterManagerOperation(task, request, state, listener);
Expand Down Expand Up @@ -218,7 +222,7 @@ protected void doStart(ClusterState clusterState) {
}
});
threadPool.executor(executor)
.execute(ActionRunnable.wrap(delegate, l -> clusterManagerOperation(task, request, clusterState, l)));
.execute(ActionRunnable.wrap(delegate, l -> masterOperation(task, request, clusterState, l)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be we could keep the clusterManagerOperation but change its delegation model:

    protected void clusterManagerOperation(Task task, Request request, ClusterState state, ActionListener<Response> listener)
        throws Exception {
        masterOperation(task, request, state, listener);
    }

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the suggestion! It make sense, in this way, the benefit is there will be no references of the master name methods, but the disadvantage is there will be more work in changing the method definitions when removing the deprecated ones.
I will have a try to change in this way.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in the commit d4ec950, thanks for your brilliant idea! 😄

}
} else {
if (nodes.getClusterManagerNode() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ protected final void clusterManagerOperation(final Request request, final Cluste
doClusterManagerOperation(request, concreteIndices, state, listener);
}

// TODO: Add abstract keyword after removing the deprecated doMasterOperation()
protected void doClusterManagerOperation(
Request request,
String[] concreteIndices,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,43 @@ protected void clusterManagerOperation(Task task, Request request, ClusterState
}
}

/* The test is copied from testLocalOperationWithoutBlocks()
to validate the backwards compatibility for the deprecated method masterOperation(with task parameter). */
public void testDeprecatedMasterOperationWithTaskParameterCanBeCalled() throws ExecutionException, InterruptedException {
final boolean clusterManagerOperationFailure = randomBoolean();

Request request = new Request();
PlainActionFuture<Response> listener = new PlainActionFuture<>();

final Exception exception = new Exception();
final Response response = new Response();

setState(clusterService, ClusterStateCreationUtils.state(localNode, localNode, allNodes));

new Action("internal:testAction", transportService, clusterService, threadPool) {
@Override
protected void masterOperation(Task task, Request request, ClusterState state, ActionListener<Response> listener) {
if (clusterManagerOperationFailure) {
listener.onFailure(exception);
} else {
listener.onResponse(response);
}
}
}.execute(request, listener);
assertTrue(listener.isDone());

if (clusterManagerOperationFailure) {
try {
listener.get();
fail("Expected exception but returned proper result");
} catch (ExecutionException ex) {
assertThat(ex.getCause(), equalTo(exception));
}
} else {
assertThat(listener.get(), equalTo(response));
}
}

public void testLocalOperationWithBlocks() throws ExecutionException, InterruptedException {
final boolean retryableBlock = randomBoolean();
final boolean unblockBeforeTimeout = randomBoolean();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public void assertAfterTest() throws Exception {
/**
* Returns the number of data and cluster-manager eligible nodes in the cluster.
*/
// TODO: Add abstract keyword after removing the deprecated numDataAndMasterNodes()
public int numDataAndClusterManagerNodes() {
return numDataAndMasterNodes();
}
Expand Down