Skip to content

Commit 9ad9f16

Browse files
authored
Remove some abstractions from TransportReplicationAction (#40706)
`TransportReplicationAction` is a rather complex beast, and some of its concrete implementations do not need all of its features. More specifically, it (a) chases a primary around the cluster until it manages to pin it down and then (b) executes an action on that primary and all its replicas. There are some actions that are coordinated by the primary itself, meaning that there is no need for the chase-the-primary phases, and in the case of peer recovery retention leases and primary/replica resync it is important to bypass these first phases. This commit is a step towards separating the `TransportReplicationAction` into these two parts. It is a mostly mechanical sequence of steps to remove some abstractions that are no longer in use.
1 parent fcc7158 commit 9ad9f16

File tree

6 files changed

+97
-226
lines changed

6 files changed

+97
-226
lines changed

server/src/main/java/org/elasticsearch/action/admin/indices/refresh/TransportShardRefreshAction.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ protected ReplicationResponse newResponseInstance() {
5353
}
5454

5555
@Override
56-
protected PrimaryResult shardOperationOnPrimary(BasicReplicationRequest shardRequest, IndexShard primary) {
56+
protected PrimaryResult<BasicReplicationRequest, ReplicationResponse> shardOperationOnPrimary(
57+
BasicReplicationRequest shardRequest, IndexShard primary) {
5758
primary.refresh("api");
5859
logger.trace("{} refresh request executed on primary", primary.shardId());
59-
return new PrimaryResult(shardRequest, new ReplicationResponse());
60+
return new PrimaryResult<>(shardRequest, new ReplicationResponse());
6061
}
6162

6263
@Override

server/src/main/java/org/elasticsearch/action/resync/TransportResyncReplicationAction.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@ public TransportResyncReplicationAction(Settings settings, TransportService tran
6666
@Override
6767
protected void registerRequestHandlers(String actionName, TransportService transportService, Supplier<ResyncReplicationRequest> request,
6868
Supplier<ResyncReplicationRequest> replicaRequest, String executor) {
69-
transportService.registerRequestHandler(actionName, request, ThreadPool.Names.SAME, new OperationTransportHandler());
69+
transportService.registerRequestHandler(actionName, request, ThreadPool.Names.SAME, this::handleOperationRequest);
7070
// we should never reject resync because of thread pool capacity on primary
7171
transportService.registerRequestHandler(transportPrimaryAction,
7272
() -> new ConcreteShardRequest<>(request),
7373
executor, true, true,
74-
new PrimaryOperationTransportHandler());
74+
this::handlePrimaryRequest);
7575
transportService.registerRequestHandler(transportReplicaAction,
7676
() -> new ConcreteReplicaRequest<>(replicaRequest),
7777
executor, true, true,
78-
new ReplicaOperationTransportHandler());
78+
this::handleReplicaRequest);
7979
}
8080

8181
@Override

server/src/main/java/org/elasticsearch/action/support/ChannelActionListener.java

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public void onFailure(Exception e) {
5555
try {
5656
channel.sendResponse(e);
5757
} catch (Exception e1) {
58+
e1.addSuppressed(e);
5859
logger.warn(() -> new ParameterizedMessage(
5960
"Failed to send error response for action [{}] and request [{}]", actionName, request), e1);
6061
}

0 commit comments

Comments
 (0)