使用Spring Boot新版后,ElasticSearch出现如下错误
Cannot register setting [http.netty.max_composite_buffer_components] twice
Caused by: java.lang.IllegalArgumentException: Cannot register setting [http.netty.max_composite_buffer_components] twice
at org.elasticsearch.common.settings.SettingsModule.registerSetting(SettingsModule.java:172) ~[elasticsearch-5.6.16.jar:5.6.16]
at org.elasticsearch.common.settings.SettingsModule.<init>(SettingsModule.java:74) ~[elasticsearch-5.6.16.jar:5.6.16]
at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:141) ~[elasticsearch-5.6.16.jar:5.6.16]
at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:268) ~[elasticsearch-5.6.16.jar:5.6.16]
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:133) ~[transport-5.6.16.jar:5.6.16]
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:119) ~[transport-5.6.16.jar:5.6.16]
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:109) ~[transport-5.6.16.jar:5.6.16]
原因
因为transport使用的是5.5.3
版本,对应的transport-netty3-client
也是5.5.3
,但是transport-netty4-client
却被Spring Boot设置为6.4.3
解决办法
transport-netty4-client也设置为5.5.3
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>5.5.3</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>transport-netty4-client</artifactId>
<version>5.5.3</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.5.3</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>transport-netty4-client</artifactId>
</exclusion>
</exclusions>
</dependency>
版本不兼容原因分析
在两个版本中,Netty3Plugin和Netty4Plugin都会去设置属性http.netty.max_composite_buffer_components
,但是区别在于5.5.3中,这个属性是共享的Property.Shared
,但是在6.4.3中该属性不是共享(其实共享的本意我还没有弄得很清楚)
- 5.5.3
{Property.NodeScope, Property.Shared}
SETTING_HTTP_NETTY_MAX_COMPOSITE_BUFFER_COMPONENTS = Setting.intSetting("http.netty.max_composite_buffer_components", -1, new Property[]{Property.NodeScope, Property.Shared});
- 6.4.3
Property.NodeScope
public static Setting<Integer> SETTING_HTTP_NETTY_MAX_COMPOSITE_BUFFER_COMPONENTS =
new Setting<>(SETTING_KEY_HTTP_NETTY_MAX_COMPOSITE_BUFFER_COMPONENTS, (s) -> {
ByteSizeValue maxContentLength = SETTING_HTTP_MAX_CONTENT_LENGTH.get(s);
long maxBufferComponentsEstimate = Math.round((double) (maxContentLength.getBytes() / MTU.getBytes()));
long maxBufferComponents = Math.max(2, Math.min(maxBufferComponentsEstimate, Integer.MAX_VALUE));
return String.valueOf(maxBufferComponents);
}, s -> Setting.parseInt(s, 2, Integer.MAX_VALUE, SETTING_KEY_HTTP_NETTY_MAX_COMPOSITE_BUFFER_COMPONENTS), Property.NodeScope);
网友评论