Skip to content

Commit

Permalink
Revert "Remove direct cloning of BytesTransportRequests (elastic#114808
Browse files Browse the repository at this point in the history
…)"

This reverts commit 530d150.
  • Loading branch information
Tim-Brooks committed Nov 20, 2024
1 parent 3c0a975 commit 1e2a13e
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.elasticsearch.core.RefCounted;
import org.elasticsearch.core.Strings;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.core.UpdateForV9;
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
import org.elasticsearch.node.Node;
import org.elasticsearch.plugins.Plugin;
Expand All @@ -49,6 +50,7 @@
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.tasks.MockTaskManager;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.BytesTransportRequest;
import org.elasticsearch.transport.ClusterConnectionManager;
import org.elasticsearch.transport.ConnectTransportException;
import org.elasticsearch.transport.ConnectionProfile;
Expand Down Expand Up @@ -584,8 +586,13 @@ public void sendRequest(
// poor mans request cloning...
BytesStreamOutput bStream = new BytesStreamOutput();
request.writeTo(bStream);
RequestHandlerRegistry<?> reg = MockTransportService.this.getRequestHandler(action);
final TransportRequest clonedRequest = reg.newRequest(bStream.bytes().streamInput());
final TransportRequest clonedRequest;
if (request instanceof BytesTransportRequest) {
clonedRequest = copyRawBytesForBwC(bStream);
} else {
RequestHandlerRegistry<?> reg = MockTransportService.this.getRequestHandler(action);
clonedRequest = reg.newRequest(bStream.bytes().streamInput());
}
assert clonedRequest.getClass().equals(MasterNodeRequestHelper.unwrapTermOverride(request).getClass())
: clonedRequest + " vs " + request;

Expand Down Expand Up @@ -633,6 +640,15 @@ protected void doRun() throws IOException {
}
}

// Some request handlers read back a BytesTransportRequest
// into a different class that cannot be re-serialized (i.e. JOIN_VALIDATE_ACTION_NAME),
// in those cases we just copy the raw bytes back to a BytesTransportRequest.
// This is only needed for the BwC for JOIN_VALIDATE_ACTION_NAME and can be removed in the next major
@UpdateForV9(owner = UpdateForV9.Owner.DISTRIBUTED_COORDINATION)
private static TransportRequest copyRawBytesForBwC(BytesStreamOutput bStream) throws IOException {
return new BytesTransportRequest(bStream.bytes().streamInput());
}

@Override
public void clearCallback() {
synchronized (this) {
Expand Down

0 comments on commit 1e2a13e

Please sign in to comment.