Skip to content

Commit 6a377c1

Browse files
arteamgeorgewallace
authored andcommitted
Remove direct cloning of BytesTransportRequests (elastic#114808)
All request handlers should be able to read `BytesTransportRequest` to a class than can copied by re-serializing. Direct copying was only necessary by the legacy `JOIN_VALIDATE_ACTION_NAME` request handler. See elastic#89926
1 parent b3fee43 commit 6a377c1

File tree

1 file changed

+2
-18
lines changed

1 file changed

+2
-18
lines changed

test/framework/src/main/java/org/elasticsearch/test/transport/MockTransportService.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.elasticsearch.core.RefCounted;
4040
import org.elasticsearch.core.Strings;
4141
import org.elasticsearch.core.TimeValue;
42-
import org.elasticsearch.core.UpdateForV9;
4342
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
4443
import org.elasticsearch.node.Node;
4544
import org.elasticsearch.plugins.Plugin;
@@ -50,7 +49,6 @@
5049
import org.elasticsearch.test.ESTestCase;
5150
import org.elasticsearch.test.tasks.MockTaskManager;
5251
import org.elasticsearch.threadpool.ThreadPool;
53-
import org.elasticsearch.transport.BytesTransportRequest;
5452
import org.elasticsearch.transport.ClusterConnectionManager;
5553
import org.elasticsearch.transport.ConnectTransportException;
5654
import org.elasticsearch.transport.ConnectionProfile;
@@ -586,13 +584,8 @@ public void sendRequest(
586584
// poor mans request cloning...
587585
BytesStreamOutput bStream = new BytesStreamOutput();
588586
request.writeTo(bStream);
589-
final TransportRequest clonedRequest;
590-
if (request instanceof BytesTransportRequest) {
591-
clonedRequest = copyRawBytesForBwC(bStream);
592-
} else {
593-
RequestHandlerRegistry<?> reg = MockTransportService.this.getRequestHandler(action);
594-
clonedRequest = reg.newRequest(bStream.bytes().streamInput());
595-
}
587+
RequestHandlerRegistry<?> reg = MockTransportService.this.getRequestHandler(action);
588+
final TransportRequest clonedRequest = reg.newRequest(bStream.bytes().streamInput());
596589
assert clonedRequest.getClass().equals(MasterNodeRequestHelper.unwrapTermOverride(request).getClass())
597590
: clonedRequest + " vs " + request;
598591

@@ -640,15 +633,6 @@ protected void doRun() throws IOException {
640633
}
641634
}
642635

643-
// Some request handlers read back a BytesTransportRequest
644-
// into a different class that cannot be re-serialized (i.e. JOIN_VALIDATE_ACTION_NAME),
645-
// in those cases we just copy the raw bytes back to a BytesTransportRequest.
646-
// This is only needed for the BwC for JOIN_VALIDATE_ACTION_NAME and can be removed in the next major
647-
@UpdateForV9(owner = UpdateForV9.Owner.DISTRIBUTED_COORDINATION)
648-
private static TransportRequest copyRawBytesForBwC(BytesStreamOutput bStream) throws IOException {
649-
return new BytesTransportRequest(bStream.bytes().streamInput());
650-
}
651-
652636
@Override
653637
public void clearCallback() {
654638
synchronized (this) {

0 commit comments

Comments
 (0)