一、异常描述
之前通过apache solr连接mysql数据库生成主题内容subject索引文件,最近操作Dataimprt生成时报出“ ERROR org.apache.solr.handler.dataimport.DataImporter... Full Import failed:java.lang.RuntimeException: java.lang.RuntimeException: org.apache.solr.handler.dataimport.DataImportHandlerException: Unable to execute query:select...Caused by: java.net.ConnectException: Connection timed out: connect...”异常内容,详情如下所示
334401 [Thread-20] ERROR org.apache.solr.handler.dataimport.DataImporter – Ful@b@l Import failed:java.lang.RuntimeException: java.lang.RuntimeException: org.apac@b@he.solr.handler.dataimport.DataImportHandlerException: Unable to execute query:@b@select .... Processing Document # 1@b@ at org.apache.solr.handler.dataimport.DocBuilder.execute(DocBuilder.java@b@:270)@b@ at org.apache.solr.handler.dataimport.DataImporter.doFullImport(DataImpo@b@rter.java:411)@b@ at org.apache.solr.handler.dataimport.DataImporter.runCmd(DataImporter.j@b@ava:476)@b@ at org.apache.solr.handler.dataimport.DataImporter$1.run(DataImporter.ja@b@va:457)@b@Caused by: java.lang.RuntimeException: org.apache.solr.handler.dataimport.DataIm@b@portHandlerException: Unable to execute query: select id,title,create_time,url,k@b@eywords,zhaiyao,folder_id,img_icon,ori_url,air_url,cdn_url from pms_rep_view Pr@b@ocessing Document # 1@b@ at org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilde@b@r.java:410)@b@ at org.apache.solr.handler.dataimport.DocBuilder.doFullDump(DocBuilder.j@b@ava:323)@b@ at org.apache.solr.handler.dataimport.DocBuilder.execute(DocBuilder.java@b@:231)@b@ ... 3 more@b@Caused by: org.apache.solr.handler.dataimport.DataImportHandlerException: Unable@b@ to execute query: select id,title,create_time,url,keywords,zhaiyao,folder_id,im@b@g_icon,ori_url,air_url,cdn_url from pms_rep_view Processing Document # 1@b@ at org.apache.solr.handler.dataimport.DataImportHandlerException.wrapAnd@b@Throw(DataImportHandlerException.java:71)@b@ at org.apache.solr.handler.dataimport.JdbcDataSource$ResultSetIterator.<@b@init>(JdbcDataSource.java:279)@b@ at org.apache.solr.handler.dataimport.JdbcDataSource.getData(JdbcDataSou@b@rce.java:236)@b@ at org.apache.solr.handler.dataimport.JdbcDataSource.getData(JdbcDataSou@b@rce.java:40)@b@ at org.apache.solr.handler.dataimport.SqlEntityProcessor.initQuery(SqlEn@b@tityProcessor.java:59)@b@ at org.apache.solr.handler.dataimport.SqlEntityProcessor.nextRow(SqlEnti@b@tyProcessor.java:73)@b@ at org.apache.solr.handler.dataimport.EntityProcessorWrapper.nextRow(Ent@b@ityProcessorWrapper.java:243)@b@ at org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilde@b@r.java:469)@b@ at org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilde@b@r.java:408)@b@ ... 5 more@b@Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communicatio@b@ns link failure@b@@b@The last packet sent successfully to the server was 0 milliseconds ago. The driv@b@er has not received any packets from the server.@b@ at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)@b@@b@ at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct@b@orAccessorImpl.java:57)@b@ at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC@b@onstructorAccessorImpl.java:45)@b@ at java.lang.reflect.Constructor.newInstance(Constructor.java:526)@b@ at com.mysql.jdbc.Util.handleNewInstance(Util.java:377)@b@ at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1@b@036)@b@ at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:338)@b@ at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2232)@b@ at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2@b@265)@b@ at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2064)@b@ at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:790)@b@ at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)@b@ at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)@b@@b@ at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct@b@orAccessorImpl.java:57)@b@ at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC@b@onstructorAccessorImpl.java:45)@b@ at java.lang.reflect.Constructor.newInstance(Constructor.java:526)@b@ at com.mysql.jdbc.Util.handleNewInstance(Util.java:377)@b@ at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:395)@b@ at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java@b@:325)@b@ at org.apache.solr.handler.dataimport.JdbcDataSource$1.call(JdbcDataSour@b@ce.java:149)@b@ at org.apache.solr.handler.dataimport.JdbcDataSource$1.call(JdbcDataSour@b@ce.java:129)@b@ at org.apache.solr.handler.dataimport.JdbcDataSource.getConnection(JdbcD@b@ataSource.java:392)@b@ at org.apache.solr.handler.dataimport.JdbcDataSource.access$200(JdbcData@b@Source.java:40)@b@ at org.apache.solr.handler.dataimport.JdbcDataSource$ResultSetIterator.<@b@init>(JdbcDataSource.java:266)@b@ ... 12 more@b@Caused by: java.net.ConnectException: Connection timed out: connect@b@ at java.net.DualStackPlainSocketImpl.connect0(Native Method)@b@ at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketI@b@mpl.java:79)@b@ at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.ja@b@va:339)@b@ at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocket@b@Impl.java:200)@b@ at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java@b@:182)@b@ at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)@b@ at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)@b@ at java.net.Socket.connect(Socket.java:579)@b@ at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.ja@b@va:213)@b@ at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:297)@b@ ... 29 more
二、解决方法
从异常日志“..Caused by: java.net.ConnectException: Connection timed out: connect”判断是因为网络延时异常(查询数据库时)超时造成的,具体优化方法如下
方法一:之前配置的DDNS花生壳的动态域名映射到远程数据库,改为具体ip地址后,重新生成,问题解决了.
方法二:由于用的动态公网ip,不定期的ip地址就要手动修改比较麻烦,因此才考虑换其他方法解决,具体步骤如下:
1. 在内网和公网服务器分别配置两台solr服务器,把外网原来导入更新和导入功能注释掉(在solrconfig.xml文件进行操作)
...@b@ @b@<!--@b@ 2017 - 05 -07 注释掉更新功能@b@ <requestHandler name="/update" class="solr.UpdateRequestHandler" />@b@ -->@b@ @b@ ...@b@ @b@<!--@b@ 2017 - 05 -07 注释掉导入功能@b@ @b@ <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">@b@ <lst name="defaults">@b@ <str name="config">mysql-dsmconfig.xml</str>@b@ </lst>@b@ </requestHandler>@b@ -->@b@...
2. 内网的solr服务配置保持不变,这样在内网服务进行索引的创建更新,在公网solr服务只进行读取查询操作
3. 在通过同步工具或配置replication集群将索引从内网服务器上同步外网服务器上,就可以了