How to repair corrupted lucene index?

匆匆过客 提交于 2019-12-20 18:33:05

问题


My server was power loss and lucene index was corrupted. I runned IndexChecker but it fail:

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)

How can I repair my lucene index?


回答1:


It looks like the main directory file, segments_N is corrupted. This probably means that the power loss happened while a commit was running.

If this is the case, this means that there is some chance that an older segments_N file is present in your directory, and that the referenced segments are still present and valid. If there is such a file, try to remove your corrupted segments_ls0l file and see:

  • whether Lucene manages to open the index,
  • what data you are missing.

Otherwise, there are some threads one Lucene user mailing-list talking about regenerating the segments_N file.

  • http://www.gossamer-threads.com/lists/lucene/java-user/102493
  • http://www.gossamer-threads.com/lists/lucene/java-user/39744

Make sure to backup your directory before performing any modification.



来源:https://stackoverflow.com/questions/9935177/how-to-repair-corrupted-lucene-index

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!