Skip to content

Commit 8833e70

Browse files
DaveCTurnerkcm
authored andcommitted
Clean up TransportMasterNodeAction (#34076)
Mainly this fixes a warning by replacing the unchecked `new ActionListener` with the checked `new ActionListener<Response>`, and it also fixes the line length violations in this class.
1 parent e32d335 commit 8833e70

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

buildSrc/src/main/resources/checkstyle_suppressions.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@
166166
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]support[/\\]master[/\\]AcknowledgedRequestBuilder.java" checks="LineLength" />
167167
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]support[/\\]master[/\\]MasterNodeOperationRequestBuilder.java" checks="LineLength" />
168168
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]support[/\\]master[/\\]MasterNodeReadOperationRequestBuilder.java" checks="LineLength" />
169-
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]support[/\\]master[/\\]TransportMasterNodeAction.java" checks="LineLength" />
170169
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]support[/\\]master[/\\]info[/\\]ClusterInfoRequest.java" checks="LineLength" />
171170
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]support[/\\]master[/\\]info[/\\]ClusterInfoRequestBuilder.java" checks="LineLength" />
172171
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]support[/\\]master[/\\]info[/\\]TransportClusterInfoAction.java" checks="LineLength" />

server/src/main/java/org/elasticsearch/action/support/master/TransportMasterNodeAction.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import org.elasticsearch.common.io.stream.Writeable;
3939
import org.elasticsearch.common.settings.Settings;
4040
import org.elasticsearch.common.unit.TimeValue;
41-
import org.elasticsearch.discovery.Discovery;
41+
import org.elasticsearch.discovery.Discovery.FailedToCommitClusterStateException;
4242
import org.elasticsearch.discovery.MasterNotDiscoveredException;
4343
import org.elasticsearch.node.NodeClosedException;
4444
import org.elasticsearch.tasks.Task;
@@ -53,13 +53,15 @@
5353
/**
5454
* A base class for operations that needs to be performed on the master node.
5555
*/
56-
public abstract class TransportMasterNodeAction<Request extends MasterNodeRequest<Request>, Response extends ActionResponse> extends HandledTransportAction<Request, Response> {
56+
public abstract class TransportMasterNodeAction<Request extends MasterNodeRequest<Request>, Response extends ActionResponse>
57+
extends HandledTransportAction<Request, Response> {
58+
5759
protected final ThreadPool threadPool;
5860
protected final TransportService transportService;
5961
protected final ClusterService clusterService;
6062
protected final IndexNameExpressionResolver indexNameExpressionResolver;
6163

62-
final String executor;
64+
private final String executor;
6365

6466
protected TransportMasterNodeAction(Settings settings, String actionName, TransportService transportService,
6567
ClusterService clusterService, ThreadPool threadPool, ActionFilters actionFilters,
@@ -75,7 +77,8 @@ protected TransportMasterNodeAction(Settings settings, String actionName, Transp
7577

7678
protected TransportMasterNodeAction(Settings settings, String actionName, boolean canTripCircuitBreaker,
7779
TransportService transportService, ClusterService clusterService, ThreadPool threadPool,
78-
ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, Supplier<Request> request) {
80+
ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver,
81+
Supplier<Request> request) {
7982
super(settings, actionName, canTripCircuitBreaker, transportService, actionFilters, request);
8083
this.transportService = transportService;
8184
this.clusterService = clusterService;
@@ -138,7 +141,8 @@ class AsyncSingleAction {
138141

139142
public void start() {
140143
ClusterState state = clusterService.state();
141-
this.observer = new ClusterStateObserver(state, clusterService, request.masterNodeTimeout(), logger, threadPool.getThreadContext());
144+
this.observer
145+
= new ClusterStateObserver(state, clusterService, request.masterNodeTimeout(), logger, threadPool.getThreadContext());
142146
doStart(state);
143147
}
144148

@@ -174,16 +178,16 @@ public void onResponse(Response response) {
174178

175179
@Override
176180
public void onFailure(Exception t) {
177-
if (t instanceof Discovery.FailedToCommitClusterStateException
178-
|| (t instanceof NotMasterException)) {
179-
logger.debug(() -> new ParameterizedMessage("master could not publish cluster state or stepped down before publishing action [{}], scheduling a retry", actionName), t);
181+
if (t instanceof FailedToCommitClusterStateException || t instanceof NotMasterException) {
182+
logger.debug(() -> new ParameterizedMessage("master could not publish cluster state or " +
183+
"stepped down before publishing action [{}], scheduling a retry", actionName), t);
180184
retry(t, masterChangePredicate);
181185
} else {
182186
listener.onFailure(t);
183187
}
184188
}
185189
};
186-
threadPool.executor(executor).execute(new ActionRunnable(delegate) {
190+
threadPool.executor(executor).execute(new ActionRunnable<Response>(delegate) {
187191
@Override
188192
protected void doRun() throws Exception {
189193
masterOperation(task, request, clusterState, delegate);
@@ -204,7 +208,8 @@ public void handleException(final TransportException exp) {
204208
Throwable cause = exp.unwrapCause();
205209
if (cause instanceof ConnectTransportException) {
206210
// we want to retry here a bit to see if a new master is elected
207-
logger.debug("connection exception while trying to forward request with action name [{}] to master node [{}], scheduling a retry. Error: [{}]",
211+
logger.debug("connection exception while trying to forward request with action name [{}] to " +
212+
"master node [{}], scheduling a retry. Error: [{}]",
208213
actionName, nodes.getMasterNode(), exp.getDetailedMessage());
209214
retry(cause, masterChangePredicate);
210215
} else {
@@ -234,7 +239,8 @@ public void onClusterServiceClose() {
234239

235240
@Override
236241
public void onTimeout(TimeValue timeout) {
237-
logger.debug(() -> new ParameterizedMessage("timed out while retrying [{}] after failure (timeout [{}])", actionName, timeout), failure);
242+
logger.debug(() -> new ParameterizedMessage("timed out while retrying [{}] after failure (timeout [{}])",
243+
actionName, timeout), failure);
238244
listener.onFailure(new MasterNotDiscoveredException(failure));
239245
}
240246
}, statePredicate

0 commit comments

Comments
 (0)