Skip to content

Commit 81720d4

Browse files
authored
Always compress based on the settings (#36522) (#36566)
Currently TransportRequestOptions allows specific requests to request compression. This commit removes this and always compresses based on the settings. Additionally, it removes TransportResponseOptions as they are unused. This closes #36399.
1 parent f9866c0 commit 81720d4

16 files changed

+39
-155
lines changed

server/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/get/TransportGetTaskAction.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ private void runOnNodeWithTaskIfPossible(Task thisTask, GetTaskRequest request,
108108
if (request.getTimeout() != null) {
109109
builder.withTimeout(request.getTimeout());
110110
}
111-
builder.withCompress(false);
112111
DiscoveryNode node = clusterService.state().nodes().get(request.getTaskId().getNodeId());
113112
if (node == null) {
114113
// Node is no longer part of the cluster! Try and look the task up from the results index.

server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/TransportNodesSnapshotsStatus.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,6 @@ public TransportNodesSnapshotsStatus(Settings settings, ThreadPool threadPool,
7272
this.snapshotShardsService = snapshotShardsService;
7373
}
7474

75-
@Override
76-
protected boolean transportCompress() {
77-
return true; // compress since the metadata can become large
78-
}
79-
8075
@Override
8176
protected NodeRequest newNodeRequest(String nodeId, Request request) {
8277
return new NodeRequest(nodeId, request);

server/src/main/java/org/elasticsearch/action/bulk/BulkAction.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ public BulkRequestBuilder newRequestBuilder(ElasticsearchClient client) {
4545

4646
@Override
4747
public TransportRequestOptions transportOptions(Settings settings) {
48-
return TransportRequestOptions.builder()
49-
.withType(TransportRequestOptions.Type.BULK)
50-
.withCompress(settings.getAsBoolean("action.bulk.compress", true)
51-
).build();
48+
return TransportRequestOptions.builder().withType(TransportRequestOptions.Type.BULK).build();
5249
}
5350
}

server/src/main/java/org/elasticsearch/action/support/nodes/TransportNodesAction.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ protected void doExecute(Task task, NodesRequest request, ActionListener<NodesRe
9191
new AsyncAction(task, request, listener).start();
9292
}
9393

94-
protected boolean transportCompress() {
95-
return false;
96-
}
97-
9894
/**
9995
* Map the responses into {@code nodeResponseClass} responses and {@link FailedNodeException}s.
10096
*
@@ -182,7 +178,6 @@ void start() {
182178
if (request.timeout() != null) {
183179
builder.withTimeout(request.timeout());
184180
}
185-
builder.withCompress(transportCompress());
186181
for (int i = 0; i < nodes.length; i++) {
187182
final int idx = i;
188183
final DiscoveryNode node = nodes[i];

server/src/main/java/org/elasticsearch/action/support/tasks/TransportTasksAction.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,6 @@ protected TasksResponse newResponse(TasksRequest request, AtomicReferenceArray r
222222
*/
223223
protected abstract void taskOperation(TasksRequest request, OperationTask task, ActionListener<TaskResponse> listener);
224224

225-
protected boolean transportCompress() {
226-
return false;
227-
}
228-
229225
private class AsyncAction {
230226

231227
private final TasksRequest request;
@@ -265,7 +261,6 @@ private void start() {
265261
if (request.getTimeout() != null) {
266262
builder.withTimeout(request.getTimeout());
267263
}
268-
builder.withCompress(transportCompress());
269264
for (int i = 0; i < nodesIds.length; i++) {
270265
final String nodeId = nodesIds[i];
271266
final int idx = i;

server/src/main/java/org/elasticsearch/discovery/zen/PublishClusterStateAction.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ public class PublishClusterStateAction {
7474
public static final String SEND_ACTION_NAME = "internal:discovery/zen/publish/send";
7575
public static final String COMMIT_ACTION_NAME = "internal:discovery/zen/publish/commit";
7676

77+
// -> no need to put a timeout on the options, because we want the state response to eventually be received
78+
// and not log an error if it arrives after the timeout
79+
private final TransportRequestOptions stateRequestOptions = TransportRequestOptions.builder()
80+
.withType(TransportRequestOptions.Type.STATE).build();
81+
7782
public interface IncomingClusterStateListener {
7883

7984
/**
@@ -282,14 +287,9 @@ private void sendClusterStateToNode(final ClusterState clusterState, BytesRefere
282287
final boolean sendDiffs, final Map<Version, BytesReference> serializedStates) {
283288
try {
284289

285-
// -> no need to put a timeout on the options here, because we want the response to eventually be received
286-
// and not log an error if it arrives after the timeout
287-
// -> no need to compress, we already compressed the bytes
288-
TransportRequestOptions options = TransportRequestOptions.builder()
289-
.withType(TransportRequestOptions.Type.STATE).withCompress(false).build();
290290
transportService.sendRequest(node, SEND_ACTION_NAME,
291291
new BytesTransportRequest(bytes, node.getVersion()),
292-
options,
292+
stateRequestOptions,
293293
new EmptyTransportResponseHandler(ThreadPool.Names.SAME) {
294294

295295
@Override
@@ -322,12 +322,9 @@ private void sendCommitToNode(final DiscoveryNode node, final ClusterState clust
322322
try {
323323
logger.trace("sending commit for cluster state (uuid: [{}], version [{}]) to [{}]",
324324
clusterState.stateUUID(), clusterState.version(), node);
325-
TransportRequestOptions options = TransportRequestOptions.builder().withType(TransportRequestOptions.Type.STATE).build();
326-
// no need to put a timeout on the options here, because we want the response to eventually be received
327-
// and not log an error if it arrives after the timeout
328325
transportService.sendRequest(node, COMMIT_ACTION_NAME,
329326
new CommitClusterStateRequest(clusterState.stateUUID()),
330-
options,
327+
stateRequestOptions,
331328
new EmptyTransportResponseHandler(ThreadPool.Names.SAME) {
332329

333330
@Override

server/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayMetaState.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ public ActionFuture<NodesGatewayMetaState> list(String[] nodesIds, @Nullable Tim
6868
return execute(new Request(nodesIds).timeout(timeout));
6969
}
7070

71-
@Override
72-
protected boolean transportCompress() {
73-
return true; // compress since the metadata can become large
74-
}
75-
7671
@Override
7772
protected NodeRequest newNodeRequest(String nodeId, Request request) {
7873
return new NodeRequest(nodeId);

server/src/main/java/org/elasticsearch/gateway/TransportNodesListGatewayStartedShards.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@ public void list(ShardId shardId, DiscoveryNode[] nodes,
9595
execute(new Request(shardId, nodes), listener);
9696
}
9797

98-
@Override
99-
protected boolean transportCompress() {
100-
return true; // this can become big...
101-
}
102-
10398
@Override
10499
protected NodeRequest newNodeRequest(String nodeId, Request request) {
105100
return new NodeRequest(nodeId, request);

server/src/main/java/org/elasticsearch/indices/recovery/RemoteRecoveryTargetHandler.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,10 @@ public RemoteRecoveryTargetHandler(long recoveryId, ShardId shardId, TransportSe
6262
this.recoverySettings = recoverySettings;
6363
this.onSourceThrottle = onSourceThrottle;
6464
this.translogOpsRequestOptions = TransportRequestOptions.builder()
65-
.withCompress(true)
6665
.withType(TransportRequestOptions.Type.RECOVERY)
6766
.withTimeout(recoverySettings.internalActionLongTimeout())
6867
.build();
6968
this.fileChunkRequestOptions = TransportRequestOptions.builder()
70-
.withCompress(false) // lucene files are already compressed and therefore compressing this won't really help much so
7169
// we are saving the cpu for other things
7270
.withType(TransportRequestOptions.Type.RECOVERY)
7371
.withTimeout(recoverySettings.internalActionTimeout())

server/src/main/java/org/elasticsearch/transport/TcpTransport.java

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public abstract class TcpTransport extends AbstractLifecycleComponent implements
195195
// this lock is here to make sure we close this transport and disconnect all the client nodes
196196
// connections while no connect operations is going on
197197
private final ReadWriteLock closeLock = new ReentrantReadWriteLock();
198-
private final boolean compressResponses;
198+
private final boolean compressAllResponses;
199199
private volatile BoundTransportAddress boundAddress;
200200
private final String transportName;
201201

@@ -220,16 +220,16 @@ public TcpTransport(String transportName, Settings settings, Version version, T
220220
this.pageCacheRecycler = pageCacheRecycler;
221221
this.circuitBreakerService = circuitBreakerService;
222222
this.namedWriteableRegistry = namedWriteableRegistry;
223-
this.compressResponses = Transport.TRANSPORT_TCP_COMPRESS.get(settings);
223+
this.compressAllResponses = Transport.TRANSPORT_TCP_COMPRESS.get(settings);
224224
this.networkService = networkService;
225225
this.transportName = transportName;
226226
this.transportLogger = new TransportLogger();
227227
this.handshaker = new TransportHandshaker(version, threadPool,
228228
(node, channel, requestId, v) -> sendRequestToChannel(node, channel, requestId,
229229
TransportHandshaker.HANDSHAKE_ACTION_NAME, new TransportHandshaker.HandshakeRequest(version),
230-
TransportRequestOptions.EMPTY, v, TransportStatus.setHandshake((byte) 0)),
230+
TransportRequestOptions.EMPTY, v, false, TransportStatus.setHandshake((byte) 0)),
231231
(v, features, channel, response, requestId) -> sendResponse(v, features, channel, response, requestId,
232-
TransportHandshaker.HANDSHAKE_ACTION_NAME, TransportResponseOptions.EMPTY, TransportStatus.setHandshake((byte) 0)));
232+
TransportHandshaker.HANDSHAKE_ACTION_NAME, false, TransportStatus.setHandshake((byte) 0)));
233233
this.keepAlive = new TransportKeepAlive(threadPool, this::internalSendMessage);
234234
this.nodeName = Node.NODE_NAME_SETTING.get(settings);
235235

@@ -337,11 +337,7 @@ public void sendRequest(long requestId, String action, TransportRequest request,
337337
throw new NodeNotConnectedException(node, "connection already closed");
338338
}
339339
TcpChannel channel = channel(options.type());
340-
341-
if (compress) {
342-
options = TransportRequestOptions.builder(options).withCompress(true).build();
343-
}
344-
sendRequestToChannel(this.node, channel, requestId, action, request, options, getVersion(), (byte) 0);
340+
sendRequestToChannel(this.node, channel, requestId, action, request, options, getVersion(), compress, (byte) 0);
345341
}
346342
}
347343

@@ -768,11 +764,11 @@ private boolean canCompress(TransportRequest request) {
768764

769765
private void sendRequestToChannel(final DiscoveryNode node, final TcpChannel channel, final long requestId, final String action,
770766
final TransportRequest request, TransportRequestOptions options, Version channelVersion,
771-
byte status) throws IOException, TransportException {
767+
boolean compressRequest, byte status) throws IOException, TransportException {
772768

773769
// only compress if asked and the request is not bytes. Otherwise only
774770
// the header part is compressed, and the "body" can't be extracted as compressed
775-
final boolean compressMessage = options.compress() && canCompress(request);
771+
final boolean compressMessage = compressRequest && canCompress(request);
776772

777773
status = TransportStatus.setRequest(status);
778774
ReleasableBytesStreamOutput bStream = new ReleasableBytesStreamOutput(bigArrays);
@@ -871,8 +867,8 @@ public void sendResponse(
871867
final TransportResponse response,
872868
final long requestId,
873869
final String action,
874-
final TransportResponseOptions options) throws IOException {
875-
sendResponse(nodeVersion, features, channel, response, requestId, action, options, (byte) 0);
870+
final boolean compress) throws IOException {
871+
sendResponse(nodeVersion, features, channel, response, requestId, action, compress, (byte) 0);
876872
}
877873

878874
private void sendResponse(
@@ -882,29 +878,26 @@ private void sendResponse(
882878
final TransportResponse response,
883879
final long requestId,
884880
final String action,
885-
TransportResponseOptions options,
881+
boolean compress,
886882
byte status) throws IOException {
887-
if (compressResponses && options.compress() == false) {
888-
options = TransportResponseOptions.builder(options).withCompress(true).build();
889-
}
883+
boolean compressMessage = compress || compressAllResponses;
890884

891885
status = TransportStatus.setResponse(status);
892886
ReleasableBytesStreamOutput bStream = new ReleasableBytesStreamOutput(bigArrays);
893-
CompressibleBytesOutputStream stream = new CompressibleBytesOutputStream(bStream, options.compress());
887+
CompressibleBytesOutputStream stream = new CompressibleBytesOutputStream(bStream, compressMessage);
894888
boolean addedReleaseListener = false;
895889
try {
896-
if (options.compress()) {
890+
if (compressMessage) {
897891
status = TransportStatus.setCompress(status);
898892
}
899893
threadPool.getThreadContext().writeTo(stream);
900894
stream.setVersion(nodeVersion);
901895
stream.setFeatures(features);
902896
BytesReference message = buildMessage(requestId, status, nodeVersion, response, stream);
903897

904-
final TransportResponseOptions finalOptions = options;
905898
// this might be called in a different thread
906899
ReleaseListener releaseListener = new ReleaseListener(stream,
907-
() -> messageListener.onResponseSent(requestId, action, response, finalOptions));
900+
() -> messageListener.onResponseSent(requestId, action, response));
908901
internalSendMessage(channel, message, releaseListener);
909902
addedReleaseListener = true;
910903
} finally {
@@ -1530,9 +1523,9 @@ public void onRequestReceived(long requestId, String action) {
15301523
}
15311524

15321525
@Override
1533-
public void onResponseSent(long requestId, String action, TransportResponse response, TransportResponseOptions finalOptions) {
1526+
public void onResponseSent(long requestId, String action, TransportResponse response) {
15341527
for (TransportMessageListener listener : listeners) {
1535-
listener.onResponseSent(requestId, action, response, finalOptions);
1528+
listener.onResponseSent(requestId, action, response);
15361529
}
15371530
}
15381531

server/src/main/java/org/elasticsearch/transport/TcpTransportChannel.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,7 @@ public String getProfileName() {
6161
@Override
6262
public void sendResponse(TransportResponse response) throws IOException {
6363
try {
64-
TransportResponseOptions options;
65-
if (compressResponse) {
66-
options = TransportResponseOptions.builder().withCompress(true).build();
67-
} else {
68-
options = TransportResponseOptions.EMPTY;
69-
}
70-
transport.sendResponse(version, features, channel, response, requestId, action, options);
64+
transport.sendResponse(version, features, channel, response, requestId, action, compressResponse);
7165
} finally {
7266
release(false);
7367
}

server/src/main/java/org/elasticsearch/transport/TransportMessageListener.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ default void onRequestReceived(long requestId, String action) {}
3535
* @param requestId the request ID (unique per client)
3636
* @param action the request action
3737
* @param response the response send
38-
* @param finalOptions the response options
3938
*/
40-
default void onResponseSent(long requestId, String action, TransportResponse response, TransportResponseOptions finalOptions) {}
39+
default void onResponseSent(long requestId, String action, TransportResponse response) {}
4140

4241
/***
4342
* Called for every failed action response after the response has been passed to the underlying network implementation.

server/src/main/java/org/elasticsearch/transport/TransportRequestOptions.java

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,17 @@
2424
public class TransportRequestOptions {
2525

2626
private final TimeValue timeout;
27-
private final boolean compress;
2827
private final Type type;
2928

30-
private TransportRequestOptions(TimeValue timeout, boolean compress, Type type) {
29+
private TransportRequestOptions(TimeValue timeout, Type type) {
3130
this.timeout = timeout;
32-
this.compress = compress;
3331
this.type = type;
3432
}
3533

3634
public TimeValue timeout() {
3735
return this.timeout;
3836
}
3937

40-
public boolean compress() {
41-
return this.compress;
42-
}
43-
4438
public Type type() {
4539
return this.type;
4640
}
@@ -60,15 +54,11 @@ public static Builder builder() {
6054
}
6155

6256
public static Builder builder(TransportRequestOptions options) {
63-
return new Builder()
64-
.withTimeout(options.timeout)
65-
.withCompress(options.compress)
66-
.withType(options.type());
57+
return new Builder().withTimeout(options.timeout).withType(options.type());
6758
}
6859

6960
public static class Builder {
7061
private TimeValue timeout;
71-
private boolean compress;
7262
private Type type = Type.REG;
7363

7464
private Builder() {
@@ -83,18 +73,13 @@ public Builder withTimeout(TimeValue timeout) {
8373
return this;
8474
}
8575

86-
public Builder withCompress(boolean compress) {
87-
this.compress = compress;
88-
return this;
89-
}
90-
9176
public Builder withType(Type type) {
9277
this.type = type;
9378
return this;
9479
}
9580

9681
public TransportRequestOptions build() {
97-
return new TransportRequestOptions(timeout, compress, type);
82+
return new TransportRequestOptions(timeout, type);
9883
}
9984
}
10085
}

0 commit comments

Comments
 (0)