Skip to content

Commit 194a6b1

Browse files
authored
Remove LocalTransport in favor of MockTcpTransport (#20695)
This change proposes the removal of all non-tcp transport implementations. The mock transport can be used by default to run tests instead of local transport that has roughly the same performance compared to TCP or at least not noticeably slower. This is a master only change, deprecation notice in 5.x will be committed as a separate change.
1 parent eba60ee commit 194a6b1

File tree

151 files changed

+797
-1666
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+797
-1666
lines changed

TESTING.asciidoc

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,6 @@ following:
1616
gradle assemble
1717
-----------------------------
1818

19-
== Other test options
20-
21-
To disable and enable network transport, set the `tests.es.node.mode` system property.
22-
23-
Use network transport:
24-
25-
------------------------------------
26-
-Dtests.es.node.mode=network
27-
------------------------------------
28-
29-
Use local transport (default since 1.3):
30-
31-
-------------------------------------
32-
-Dtests.es.node.mode=local
33-
-------------------------------------
34-
3519
=== Running Elasticsearch from a checkout
3620

3721
In order to run Elasticsearch from source without building a package, you can

benchmarks/src/main/java/org/elasticsearch/benchmark/routing/allocation/Allocators.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,18 @@
3131
import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders;
3232
import org.elasticsearch.common.settings.ClusterSettings;
3333
import org.elasticsearch.common.settings.Settings;
34-
import org.elasticsearch.common.transport.LocalTransportAddress;
34+
import org.elasticsearch.common.transport.TransportAddress;
3535
import org.elasticsearch.common.util.set.Sets;
3636
import org.elasticsearch.gateway.GatewayAllocator;
3737

3838
import java.lang.reflect.InvocationTargetException;
39+
import java.net.InetAddress;
40+
import java.net.UnknownHostException;
3941
import java.util.Collection;
4042
import java.util.Collections;
4143
import java.util.List;
4244
import java.util.Map;
45+
import java.util.concurrent.atomic.AtomicInteger;
4346

4447
public final class Allocators {
4548
private static class NoopGatewayAllocator extends GatewayAllocator {
@@ -91,8 +94,11 @@ public static AllocationDeciders defaultAllocationDeciders(Settings settings, Cl
9194

9295
}
9396

97+
private static final AtomicInteger portGenerator = new AtomicInteger();
98+
9499
public static DiscoveryNode newNode(String nodeId, Map<String, String> attributes) {
95-
return new DiscoveryNode("", nodeId, LocalTransportAddress.buildUnique(), attributes, Sets.newHashSet(DiscoveryNode.Role.MASTER,
100+
return new DiscoveryNode("", nodeId, new TransportAddress(TransportAddress.META_ADDRESS,
101+
portGenerator.incrementAndGet()), attributes, Sets.newHashSet(DiscoveryNode.Role.MASTER,
96102
DiscoveryNode.Role.DATA), Version.CURRENT);
97103
}
98104
}

client/benchmark/src/main/java/org/elasticsearch/client/benchmark/transport/TransportClientBenchmark.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.elasticsearch.client.benchmark.ops.search.SearchRequestExecutor;
2828
import org.elasticsearch.client.transport.TransportClient;
2929
import org.elasticsearch.common.settings.Settings;
30-
import org.elasticsearch.common.transport.InetSocketTransportAddress;
30+
import org.elasticsearch.common.transport.TransportAddress;
3131
import org.elasticsearch.index.query.QueryBuilders;
3232
import org.elasticsearch.plugin.noop.NoopPlugin;
3333
import org.elasticsearch.plugin.noop.action.bulk.NoopBulkAction;
@@ -51,7 +51,7 @@ public static void main(String[] args) throws Exception {
5151
@Override
5252
protected TransportClient client(String benchmarkTargetHost) throws Exception {
5353
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY, NoopPlugin.class);
54-
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(benchmarkTargetHost), 9300));
54+
client.addTransportAddress(new TransportAddress(InetAddress.getByName(benchmarkTargetHost), 9300));
5555
return client;
5656
}
5757

core/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodes.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.elasticsearch.cluster.node.DiscoveryNode;
2828
import org.elasticsearch.common.network.NetworkModule;
2929
import org.elasticsearch.common.settings.Settings;
30-
import org.elasticsearch.common.transport.InetSocketTransportAddress;
3130
import org.elasticsearch.common.transport.TransportAddress;
3231
import org.elasticsearch.common.unit.ByteSizeValue;
3332
import org.elasticsearch.common.unit.TimeValue;
@@ -75,10 +74,7 @@ public class ClusterStatsNodes implements ToXContent {
7574

7675
// now do the stats that should be deduped by hardware (implemented by ip deduping)
7776
TransportAddress publishAddress = nodeResponse.nodeInfo().getTransport().address().publishAddress();
78-
InetAddress inetAddress = null;
79-
if (publishAddress.uniqueAddressTypeId() == 1) {
80-
inetAddress = ((InetSocketTransportAddress) publishAddress).address().getAddress();
81-
}
77+
final InetAddress inetAddress = publishAddress.address().getAddress();
8278
if (!seenAddresses.add(inetAddress)) {
8379
continue;
8480
}

core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.elasticsearch.common.io.stream.Writeable;
2727
import org.elasticsearch.common.settings.Settings;
2828
import org.elasticsearch.common.transport.TransportAddress;
29-
import org.elasticsearch.common.transport.TransportAddressSerializers;
3029
import org.elasticsearch.common.xcontent.ToXContent;
3130
import org.elasticsearch.common.xcontent.XContentBuilder;
3231
import org.elasticsearch.node.Node;
@@ -40,7 +39,6 @@
4039
import java.util.Set;
4140
import java.util.function.Predicate;
4241

43-
import static org.elasticsearch.common.transport.TransportAddressSerializers.addressToStream;
4442

4543
/**
4644
* A discovery node represents a node that is part of the cluster.
@@ -217,7 +215,7 @@ public DiscoveryNode(StreamInput in) throws IOException {
217215
this.ephemeralId = in.readString().intern();
218216
this.hostName = in.readString().intern();
219217
this.hostAddress = in.readString().intern();
220-
this.address = TransportAddressSerializers.addressFromStream(in);
218+
this.address = new TransportAddress(in);
221219
int size = in.readVInt();
222220
this.attributes = new HashMap<>(size);
223221
for (int i = 0; i < size; i++) {
@@ -242,7 +240,7 @@ public void writeTo(StreamOutput out) throws IOException {
242240
out.writeString(ephemeralId);
243241
out.writeString(hostName);
244242
out.writeString(hostAddress);
245-
addressToStream(out, address);
243+
address.writeTo(out);
246244
out.writeVInt(attributes.size());
247245
for (Map.Entry<String, String> entry : attributes.entrySet()) {
248246
out.writeString(entry.getKey());

core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeFilters.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import org.elasticsearch.common.network.NetworkAddress;
2525
import org.elasticsearch.common.regex.Regex;
2626
import org.elasticsearch.common.settings.Settings;
27-
import org.elasticsearch.common.transport.InetSocketTransportAddress;
27+
import org.elasticsearch.common.transport.TransportAddress;
2828

2929
import java.util.HashMap;
3030
import java.util.Map;
@@ -82,8 +82,8 @@ public boolean match(DiscoveryNode node) {
8282
if ("_ip".equals(attr)) {
8383
// We check both the host_ip or the publish_ip
8484
String publishAddress = null;
85-
if (node.getAddress() instanceof InetSocketTransportAddress) {
86-
publishAddress = NetworkAddress.format(((InetSocketTransportAddress) node.getAddress()).address().getAddress());
85+
if (node.getAddress() instanceof TransportAddress) {
86+
publishAddress = NetworkAddress.format(node.getAddress().address().getAddress());
8787
}
8888

8989
boolean match = matchByIP(values, node.getHostAddress(), publishAddress);
@@ -116,8 +116,8 @@ public boolean match(DiscoveryNode node) {
116116
} else if ("_publish_ip".equals(attr)) {
117117
// We check explicitly only the publish_ip
118118
String address = null;
119-
if (node.getAddress() instanceof InetSocketTransportAddress) {
120-
address = NetworkAddress.format(((InetSocketTransportAddress) node.getAddress()).address().getAddress());
119+
if (node.getAddress() instanceof TransportAddress) {
120+
address = NetworkAddress.format(node.getAddress().address().getAddress());
121121
}
122122

123123
boolean match = matchByIP(values, address, null);

core/src/main/java/org/elasticsearch/common/network/NetworkModule.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@
4545
import org.elasticsearch.transport.TransportInterceptor;
4646
import org.elasticsearch.transport.TransportRequest;
4747
import org.elasticsearch.transport.TransportRequestHandler;
48-
import org.elasticsearch.transport.local.LocalTransport;
4948

5049
import java.util.ArrayList;
51-
import java.util.Arrays;
5250
import java.util.Collections;
5351
import java.util.HashMap;
5452
import java.util.List;
@@ -112,7 +110,6 @@ public NetworkModule(Settings settings, boolean transportClient, List<NetworkPlu
112110
NetworkService networkService) {
113111
this.settings = settings;
114112
this.transportClient = transportClient;
115-
registerTransport(LOCAL_TRANSPORT, () -> new LocalTransport(settings, threadPool, namedWriteableRegistry, circuitBreakerService));
116113
for (NetworkPlugin plugin : plugins) {
117114
if (transportClient == false && HTTP_ENABLED.get(settings)) {
118115
Map<String, Supplier<HttpServerTransport>> httpTransportFactory = plugin.getHttpTransports(settings, threadPool, bigArrays,
@@ -126,7 +123,7 @@ public NetworkModule(Settings settings, boolean transportClient, List<NetworkPlu
126123
for (Map.Entry<String, Supplier<Transport>> entry : httpTransportFactory.entrySet()) {
127124
registerTransport(entry.getKey(), entry.getValue());
128125
}
129-
List<TransportInterceptor> transportInterceptors = plugin.getTransportInterceptors();
126+
List<TransportInterceptor> transportInterceptors = plugin.getTransportInterceptors(namedWriteableRegistry);
130127
for (TransportInterceptor interceptor : transportInterceptors) {
131128
registerTransportInterceptor(interceptor);
132129
}

core/src/main/java/org/elasticsearch/common/transport/BoundTransportAddress.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,18 @@ public void readFrom(StreamInput in) throws IOException {
6868
int boundAddressLength = in.readInt();
6969
boundAddresses = new TransportAddress[boundAddressLength];
7070
for (int i = 0; i < boundAddressLength; i++) {
71-
boundAddresses[i] = TransportAddressSerializers.addressFromStream(in);
71+
boundAddresses[i] = new TransportAddress(in);
7272
}
73-
publishAddress = TransportAddressSerializers.addressFromStream(in);
73+
publishAddress = new TransportAddress(in);
7474
}
7575

7676
@Override
7777
public void writeTo(StreamOutput out) throws IOException {
7878
out.writeInt(boundAddresses.length);
7979
for (TransportAddress address : boundAddresses) {
80-
TransportAddressSerializers.addressToStream(out, address);
80+
address.writeTo(out);
8181
}
82-
TransportAddressSerializers.addressToStream(out, publishAddress);
82+
publishAddress.writeTo(out);
8383
}
8484

8585
@Override

core/src/main/java/org/elasticsearch/common/transport/InetSocketTransportAddress.java

Lines changed: 0 additions & 127 deletions
This file was deleted.

0 commit comments

Comments
 (0)