Skip to content

Commit 2d1b058

Browse files
authored
Introduce Netty 4
This commit adds transport-netty4, a transport and HTTP implementation based on Netty 4. Relates #19526
1 parent 43c15f2 commit 2d1b058

File tree

109 files changed

+9095
-264
lines changed

Some content is hidden

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

109 files changed

+9095
-264
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ subprojects {
175175
"org.elasticsearch.test:logger-usage:${version}": ':test:logger-usage',
176176
// for transport client
177177
"org.elasticsearch.plugin:transport-netty3-client:${version}": ':modules:transport-netty3',
178+
"org.elasticsearch.plugin:transport-netty4-client:${version}": ':modules:transport-netty4',
178179
"org.elasticsearch.plugin:reindex-client:${version}": ':modules:reindex',
179180
"org.elasticsearch.plugin:lang-mustache-client:${version}": ':modules:lang-mustache',
180181
"org.elasticsearch.plugin:percolator-client:${version}": ':modules:percolator',

buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,10 @@ class BuildPlugin implements Plugin<Project> {
297297
url "http://s3.amazonaws.com/download.elasticsearch.org/lucenesnapshots/${revision}"
298298
}
299299
}
300+
repos.maven {
301+
name 'netty-snapshots'
302+
url "http://s3.amazonaws.com/download.elasticsearch.org/nettysnapshots/20160722"
303+
}
300304
}
301305

302306
/** Returns a closure which can be used with a MavenPom for removing transitive dependencies. */

client/transport/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ group = 'org.elasticsearch.client'
2626
dependencies {
2727
compile "org.elasticsearch:elasticsearch:${version}"
2828
compile project(path: ':modules:transport-netty3', configuration: 'runtime')
29+
compile project(path: ':modules:transport-netty4', configuration: 'runtime')
2930
compile project(path: ':modules:reindex', configuration: 'runtime')
3031
compile project(path: ':modules:lang-mustache', configuration: 'runtime')
3132
compile project(path: ':modules:percolator', configuration: 'runtime')

client/transport/src/main/java/org/elasticsearch/transport/client/PreBuiltTransportClient.java

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,47 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19+
1920
package org.elasticsearch.transport.client;
2021

2122
import org.elasticsearch.client.transport.TransportClient;
23+
import org.elasticsearch.common.network.NetworkModule;
24+
import org.elasticsearch.common.settings.Setting;
2225
import org.elasticsearch.common.settings.Settings;
2326
import org.elasticsearch.index.reindex.ReindexPlugin;
2427
import org.elasticsearch.percolator.PercolatorPlugin;
2528
import org.elasticsearch.plugins.Plugin;
2629
import org.elasticsearch.script.mustache.MustachePlugin;
2730
import org.elasticsearch.transport.Netty3Plugin;
31+
import org.elasticsearch.transport.Netty4Plugin;
2832

2933
import java.util.Arrays;
3034
import java.util.Collection;
3135
import java.util.Collections;
32-
36+
import java.util.List;
3337

3438
/**
3539
* A builder to create an instance of {@link TransportClient}
36-
* This class pre-installs the {@link Netty3Plugin}, {@link ReindexPlugin}, {@link PercolatorPlugin}, and {@link MustachePlugin}
40+
* This class pre-installs the
41+
* {@link Netty3Plugin},
42+
* {@link Netty4Plugin},
43+
* {@link ReindexPlugin},
44+
* {@link PercolatorPlugin},
45+
* and {@link MustachePlugin}
3746
* for the client. These plugins are all elasticsearch core modules required.
3847
*/
3948
@SuppressWarnings({"unchecked","varargs"})
4049
public class PreBuiltTransportClient extends TransportClient {
41-
private static final Collection<Class<? extends Plugin>> PRE_INSTALLED_PLUGINS = Collections.unmodifiableList(Arrays.asList(
42-
TransportPlugin.class, ReindexPlugin.class, PercolatorPlugin.class, MustachePlugin.class));
50+
51+
private static final Collection<Class<? extends Plugin>> PRE_INSTALLED_PLUGINS =
52+
Collections.unmodifiableList(
53+
Arrays.asList(
54+
Netty3Plugin.class,
55+
Netty4Plugin.class,
56+
TransportPlugin.class,
57+
ReindexPlugin.class,
58+
PercolatorPlugin.class,
59+
MustachePlugin.class));
4360

4461
@SafeVarargs
4562
public PreBuiltTransportClient(Settings settings, Class<? extends Plugin>... plugins) {
@@ -50,14 +67,25 @@ public PreBuiltTransportClient(Settings settings, Collection<Class<? extends Plu
5067
super(settings, Settings.EMPTY, addPlugins(plugins, PRE_INSTALLED_PLUGINS));
5168
}
5269

53-
/**
54-
* The default transport implementation for the transport client.
55-
*/
56-
public static final class TransportPlugin extends Netty3Plugin {
57-
// disable assertions for permissions since we might not have the permissions here
58-
// compared to if we are loaded as a real module to the es server
59-
public TransportPlugin(Settings settings) {
60-
super(Settings.builder().put("netty.assert.buglevel", false).put(settings).build());
70+
public static final class TransportPlugin extends Plugin {
71+
72+
private static final Setting<Boolean> ASSERT_NETTY_BUGLEVEL =
73+
Setting.boolSetting("netty.assert.buglevel", true, Setting.Property.NodeScope);
74+
75+
@Override
76+
public List<Setting<?>> getSettings() {
77+
return Collections.singletonList(ASSERT_NETTY_BUGLEVEL);
6178
}
79+
80+
@Override
81+
public Settings additionalSettings() {
82+
return Settings.builder()
83+
.put(NetworkModule.TRANSPORT_TYPE_KEY, Netty3Plugin.NETTY_TRANSPORT_NAME)
84+
.put(NetworkModule.HTTP_TYPE_KEY, Netty3Plugin.NETTY_HTTP_TRANSPORT_NAME)
85+
.put("netty.assert.buglevel", true)
86+
.build();
87+
}
88+
6289
}
90+
6391
}

client/transport/src/test/java/org/elasticsearch/transport/client/PreBuiltTransportClientTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19+
1920
package org.elasticsearch.transport.client;
2021

2122
import com.carrotsearch.randomizedtesting.RandomizedTest;
@@ -57,4 +58,5 @@ public void testInstallPluginTwice() {
5758
}
5859
}
5960
}
61+
6062
}

core/src/main/java/org/elasticsearch/common/bytes/PagedBytesReference.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import org.apache.lucene.util.BytesRef;
2323
import org.apache.lucene.util.BytesRefIterator;
24-
import org.elasticsearch.common.io.stream.StreamInput;
2524
import org.elasticsearch.common.util.BigArrays;
2625
import org.elasticsearch.common.util.ByteArray;
2726

@@ -36,24 +35,24 @@ public class PagedBytesReference extends BytesReference {
3635
private static final int PAGE_SIZE = BigArrays.BYTE_PAGE_SIZE;
3736

3837
private final BigArrays bigarrays;
39-
protected final ByteArray bytearray;
38+
protected final ByteArray byteArray;
4039
private final int offset;
4140
private final int length;
4241

43-
public PagedBytesReference(BigArrays bigarrays, ByteArray bytearray, int length) {
44-
this(bigarrays, bytearray, 0, length);
42+
public PagedBytesReference(BigArrays bigarrays, ByteArray byteArray, int length) {
43+
this(bigarrays, byteArray, 0, length);
4544
}
4645

47-
public PagedBytesReference(BigArrays bigarrays, ByteArray bytearray, int from, int length) {
46+
public PagedBytesReference(BigArrays bigarrays, ByteArray byteArray, int from, int length) {
4847
this.bigarrays = bigarrays;
49-
this.bytearray = bytearray;
48+
this.byteArray = byteArray;
5049
this.offset = from;
5150
this.length = length;
5251
}
5352

5453
@Override
5554
public byte get(int index) {
56-
return bytearray.get(offset + index);
55+
return byteArray.get(offset + index);
5756
}
5857

5958
@Override
@@ -66,14 +65,14 @@ public BytesReference slice(int from, int length) {
6665
if (from < 0 || (from + length) > length()) {
6766
throw new IllegalArgumentException("can't slice a buffer with length [" + length() + "], with slice parameters from [" + from + "], length [" + length + "]");
6867
}
69-
return new PagedBytesReference(bigarrays, bytearray, offset + from, length);
68+
return new PagedBytesReference(bigarrays, byteArray, offset + from, length);
7069
}
7170

7271
@Override
7372
public BytesRef toBytesRef() {
7473
BytesRef bref = new BytesRef();
7574
// if length <= pagesize this will dereference the page, or materialize the byte[]
76-
bytearray.get(offset, length, bref);
75+
byteArray.get(offset, length, bref);
7776
return bref;
7877
}
7978

@@ -95,7 +94,7 @@ public final BytesRefIterator iterator() {
9594
@Override
9695
public BytesRef next() throws IOException {
9796
if (nextFragmentSize != 0) {
98-
final boolean materialized = bytearray.get(offset + position, nextFragmentSize, slice);
97+
final boolean materialized = byteArray.get(offset + position, nextFragmentSize, slice);
9998
assert materialized == false : "iteration should be page aligned but array got materialized";
10099
position += nextFragmentSize;
101100
final int remaining = length - position;
@@ -111,6 +110,6 @@ public BytesRef next() throws IOException {
111110

112111
@Override
113112
public long ramBytesUsed() {
114-
return bytearray.ramBytesUsed();
113+
return byteArray.ramBytesUsed();
115114
}
116115
}

core/src/main/java/org/elasticsearch/common/bytes/ReleasablePagedBytesReference.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@
3030
*/
3131
public final class ReleasablePagedBytesReference extends PagedBytesReference implements Releasable {
3232

33-
public ReleasablePagedBytesReference(BigArrays bigarrays, ByteArray bytearray, int length) {
34-
super(bigarrays, bytearray, length);
33+
public ReleasablePagedBytesReference(BigArrays bigarrays, ByteArray byteArray, int length) {
34+
super(bigarrays, byteArray, length);
3535
}
3636

3737
@Override
3838
public void close() {
39-
Releasables.close(bytearray);
39+
Releasables.close(byteArray);
4040
}
41+
4142
}

core/src/main/java/org/elasticsearch/common/io/ReleasableBytesStream.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ public interface ReleasableBytesStream extends BytesStream {
2828

2929
@Override
3030
ReleasablePagedBytesReference bytes();
31+
3132
}

core/src/main/java/org/elasticsearch/common/io/stream/BytesStreamOutput.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
*/
3434
public class BytesStreamOutput extends StreamOutput implements BytesStream {
3535

36-
protected final BigArrays bigarrays;
36+
protected final BigArrays bigArrays;
3737

3838
protected ByteArray bytes;
3939
protected int count;
@@ -57,9 +57,9 @@ public BytesStreamOutput(int expectedSize) {
5757
this(expectedSize, BigArrays.NON_RECYCLING_INSTANCE);
5858
}
5959

60-
protected BytesStreamOutput(int expectedSize, BigArrays bigarrays) {
61-
this.bigarrays = bigarrays;
62-
this.bytes = bigarrays.newByteArray(expectedSize);
60+
protected BytesStreamOutput(int expectedSize, BigArrays bigArrays) {
61+
this.bigArrays = bigArrays;
62+
this.bytes = bigArrays.newByteArray(expectedSize);
6363
}
6464

6565
@Override
@@ -100,7 +100,7 @@ public void writeBytes(byte[] b, int offset, int length) throws IOException {
100100
public void reset() {
101101
// shrink list of pages
102102
if (bytes.size() > BigArrays.PAGE_SIZE_IN_BYTES) {
103-
bytes = bigarrays.resize(bytes, BigArrays.PAGE_SIZE_IN_BYTES);
103+
bytes = bigArrays.resize(bytes, BigArrays.PAGE_SIZE_IN_BYTES);
104104
}
105105

106106
// go back to start
@@ -145,7 +145,7 @@ public int size() {
145145

146146
@Override
147147
public BytesReference bytes() {
148-
return new PagedBytesReference(bigarrays, bytes, count);
148+
return new PagedBytesReference(bigArrays, bytes, count);
149149
}
150150

151151
/**
@@ -157,7 +157,7 @@ public long ramBytesUsed() {
157157
}
158158

159159
private void ensureCapacity(int offset) {
160-
bytes = bigarrays.grow(bytes, offset);
160+
bytes = bigArrays.grow(bytes, offset);
161161
}
162162

163163
}

core/src/main/java/org/elasticsearch/common/io/stream/ReleasableBytesStreamOutput.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ public ReleasableBytesStreamOutput(BigArrays bigarrays) {
3636
super(BigArrays.PAGE_SIZE_IN_BYTES, bigarrays);
3737
}
3838

39-
public ReleasableBytesStreamOutput(int expectedSize, BigArrays bigarrays) {
40-
super(expectedSize, bigarrays);
39+
public ReleasableBytesStreamOutput(int expectedSize, BigArrays bigArrays) {
40+
super(expectedSize, bigArrays);
4141
}
4242

4343
@Override
4444
public ReleasablePagedBytesReference bytes() {
45-
return new ReleasablePagedBytesReference(bigarrays, bytes, count);
45+
return new ReleasablePagedBytesReference(bigArrays, bytes, count);
4646
}
47+
4748
}

0 commit comments

Comments
 (0)