如何修复损坏的lucene指数?

时间:2012-03-29 23:41:38

标签: lucene

我的服务器断电,lucene索引已损坏。我运行了IndexChecker,但它失败了:

java -cp /home/dthoai/programs/paesia/checker/lucene-core-3.5.0.jar -ea:org.apache.lucene... org.apache.lucene.index.CheckIndex /mnt/peda/paesia/index -fix


Opening index @ /mnt/peda/paesia/index

ERROR: could not read any segments file in directory
java.io.IOException: read past EOF: MMapIndexInput(path="/mnt/peda/paesia/index/segments_ls0l")
at org.apache.lucene.store.MMapDirectory$MMapIndexInput.readByte(MMapDirectory.java:279)
at org.apache.lucene.store.ChecksumIndexInput.readByte(ChecksumIndexInput.java:41)
at org.apache.lucene.store.DataInput.readInt(DataInput.java:84)
at org.apache.lucene.store.DataInput.readLong(DataInput.java:126)
at org.apache.lucene.index.SegmentInfo.<init>(SegmentInfo.java:202)
at org.apache.lucene.index.SegmentInfos.read(SegmentInfos.java:286)
at org.apache.lucene.index.SegmentInfos$1.doBody(SegmentInfos.java:363)
at org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:754)
at org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:593)
at org.apache.lucene.index.SegmentInfos.read(SegmentInfos.java:359)
at org.apache.lucene.index.CheckIndex.checkIndex(CheckIndex.java:327)
at org.apache.lucene.index.CheckIndex.main(CheckIndex.java:1007)

如何修复lucene索引?

2 个答案:

答案 0 :(得分:8)

看起来主目录文件segments_N已损坏。这可能意味着在提交运行时发生了断电。

如果是这种情况,这意味着您的目录中可能存在较旧的segments_N文件,并且引用的段仍然存在且有效。如果有这样的文件,请尝试删除已损坏的segments_ls0l文件并查看:

  • Lucene是否设法打开索引,
  • 您缺少哪些数据。

否则,有一些线程,一个Lucene用户邮件列表谈论重新生成segments_N文件。

确保在执行任何修改之前备份您的目录。

答案 1 :(得分:0)

我解决了腐败的lucene索引问题,这是jpountz先生的答案。

这是我们的日志错误:

> 2020-11-11 12:52:06,119 (BasicLuceneIndexer.java:87) INFO  com.softslate.commerce.businessobjects.product.BasicLuceneIndexer - Reindexing products.
> 2020-11-11 12:52:06,119 (BasicLuceneIndexer.java:59) INFO  com.softslate.commerce.businessobjects.product.BasicLuceneIndexer - Writing new index to: /app/etalaze_staging/apache-tomcat-8.0.17/webapps/jatis.etalaze.community/WEB-INF/lucene/new
> 2020-11-11 12:52:06,171 (BaseRequestProcessor.java:605) WARN  com.softslate.commerce.customer.core.BaseRequestProcessor - Exception follows: 
> org.apache.lucene.index.CorruptIndexException: checksum mismatch in segments file
>   at org.apache.lucene.index.SegmentInfos.read(SegmentInfos.java:248)
>   at org.apache.lucene.index.IndexFileDeleter.(IndexFileDeleter.java:175)
>   at org.apache.lucene.index.IndexWriter.init(IndexWriter.java:1109)
>   at org.apache.lucene.index.IndexWriter.(IndexWriter.java:626)
>   at com.softslate.commerce.businessobjects.product.BasicLuceneIndexer.getIndexWriter(BasicLuceneIndexer.java:62)
>   at com.softslate.commerce.businessobjects.product.BasicLuceneIndexer.reindex(BasicLuceneIndexer.java:88)
>   at com.softslate.commerce.administrator.product.LuceneAddAllAction.execute(LuceneAddAllAction.java:44)
>   at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
>   at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
>   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
>   at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
>   at javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
>   at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
>   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
>   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
>   at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
>   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
>   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
>   at com.softslate.commerce.administrator.core.AdministratorFilter.doFilter(AdministratorFilter.java:44)
>   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
>   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
>   at com.softslate.commerce.customer.core.SEOFilter.doFilter(SEOFilter.java:92)
>   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
>   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
>   at com.softslate.commerce.customer.core.HibernateFilter.doFilter(HibernateFilter.java:75)
>   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
>   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
>   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
>   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
>   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
>   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
>   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
>   at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
>   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
>   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
>   at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1086)
>   at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:659)
>   at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
>   at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1558)
>   at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1515)
>   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
>   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
>   at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
>   at java.lang.Thread.run(Thread.java:745)

我想告诉您它背后的故事,以便进一步理解。 2020年10月27日,我们的办公室在上午11:18断电。我认为这是Lucene索引损坏的原因。也许是提交失败。

每次我们进行重新索引编制时,都会产生上述错误并创建新的段。它一遍又一遍,直到2020年11月11日为止。在lucene / new目录中,有44个segements文件(例如,segments_1,segments_2,segments_3,...,segments_N)。

解决方案: 我在lucene文件夹上做了备份。然后删除所有的segements_N文件,最新的segments_N文件和segments.gen除外。我保留了这两个文件。

最后,错误不再显示。一切都照常进行。