Elasticsearch升级1.5版本暴露jdk的bug
把测试环境的Elasticsearch升级到1.5.1版本,启动的时候报错:
[root@node2 elasticsearch-1.5.1]# bin/service/elasticsearch start
Starting Elasticsearch…
Waiting for Elasticsearch……
WARNING: Elasticsearch may have failed to start.
到日志里看,发现这样的异常:
[ERROR][bootstrap ] Exception
java.lang.RuntimeException: Java version: 1.7.0_51 suffers from critical bug
https://bugs.openjdk.java.net/browse/JDK-8024830 which can cause data corruption. Please upgrade the JVM, see http://www.elastic.co/guide/en/elasticsearch/reference/current/_installation.html for current recommendations.
If you absolutely cannot upgrade, please add -XX:-UseSuperWord to the JVM_OPTS environment variable.
Upgrading is preferred, this workaround will result in degraded performance.
at org.elasticsearch.bootstrap.JVMCheck.check(JVMCheck.java:121)
at org.elasticsearch.bootstrap.Bootstrap.main(Bootstrap.java:211)
at org.elasticsearch.bootstrap.ElasticsearchF.main(ElasticsearchF.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.tanukisoftware.wrapper.WrapperSimpleApp.run(WrapperSimpleApp.java:290)
测试环境的jdk使用的是1.7.0_51版本,这个版本有个bug,可能引起Lucene崩溃,造成seg文件或者index文件损坏。Elasticsearch建议升级jdk的版本,或者在启动命令中设置-XX:-UseSuperWord,关闭UseSuperWord功能,可以避免这个bug。
于是修改Elasticsearch的启动设置,打开bin/service/elasticsearch.conf, 增加下面的设置:
wrapper.java.additional.10=-XX:-UseSuperWord
然后启动:
[root@node2 elasticsearch-1.5.1]# bin/service/elasticsearch start
Starting Elasticsearch…
Waiting for Elasticsearch……
running: PID:3283
好了启动起来了。看一下jvm进程的状态:
[root@node2 elasticsearch-1.5.1]# jinfo 3285
Attaching to process ID 3285, please wait…
Debugger attached successfully. Server compiler detected. JVM version is 24.51-b03
…memes….
-Delasticsearch-service -Des.path.home=/server/elasticsearch-1.5.1 -Xss256k -XX:+UseParNewGC
-XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly
-XX:+HeapDumpOnOutOfMemoryError -Djava.awt.headless=true -XX:-UseSuperWord -Xms1024m -Xmx1024m
-Djava.library.path=/server/elasticsearch-1.5.1/bin/service/lib -Dwrapper.key=7w8xGTzSEUve1FvC
-Dwrapper.port=32000 -Dwrapper.jvm.port.min=31000 -Dwrapper.jvm.port.max=31999
-Dwrapper.disable_console_input=TRUE -Dwrapper.pid=3283 -Dwrapper.version=3.5.14
-Dwrapper.native_library=wrapper -Dwrapper.service=TRUE -Dwrapper.cpu.timeout=10
-Dwrapper.jvmid=1
可以看到-XX:-UseSuperWord指令已经生效了,Elasticsearch已经启动成功了。可是去掉UseSuperWord特性有没有负面的影响呢?查了一下,UseSuperWord的功能是这样的:
http://search-lucene.com/m/l6pAi13MPrt1BjCmN1&subj=Crazy+Solr+startup+params+please+review
摘要如下:
“-XX:-UseSuperWord If you have a Haswell CPU, all other improvements in these command line settings are eaten up by this flag! If you have 7u55 at minimum, you should never disable this. Things like BooleanFilter and other bitset operations are up to 2 times faster with Java 7u55 on Haswell CPUs and later!!! This setting only makes sense if you have one of those buggy JDKs (7u40 to 7u51). In all other cases this slows down enormous! In addition, enabling this option may break JDKs before 7u40 (this option was added in 7u40), so breaks:
It would be good, if we could fix the startup scripts not not have options, which may also break with JDK 8 or later!”
大概是这样的意思:UseSuperWord会在字节运算时启用布隆过滤器之类的特性,能在haswell架构的cpu上提高2倍以上的速度。看来这个功能还是开启的好。最好的方式还是升级jdk的版本到1.7.0_51以上。