lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Zhang, Lisheng" <Lisheng.Zh...@BroadVision.com>
Subject RE: Detect a corrupted index
Date Sat, 27 Jul 2013 05:38:49 GMT
Hi,

I used in the following code to detect data corruption in lucene 4.3.0:

   /////////////////////////////////
   import org.apache.lucene.index.CheckIndex;

   ...
   CheckIndex checkIndex = new CheckIndex(getLuceneDirectory(folderPath));
   CheckIndex.Status status = checkIndex.checkIndex();
   if(!status.clean) {
     printStatusDetails(status);
   }

   private static void printStatusDetails(CheckIndex.Status status) {
    if(status.toolOutOfDate) {
      log("Index version and checking tool does not match, checking is not conclusive");
      return;
    }

    if(status.missingSegments) {
      log("Cannot locate and load the segments_N file.");
    }

    if(status.missingSegmentVersion) {
      log("Cannot read version number from segment_N file");
    }

    if(status.cantOpenSegments) {
      log("Cannot open segment_N file");
    }

    if(status.numBadSegments > 0) {
      log("There are (" + status.numBadSegments + ") out of (" + status.numSegments + ") total
segments");
    }
  }

  private static Directory getLuceneDirectory(String path)
    throws Exception {
    return FSDirectory.open(new File(path));
  }
  ///////////////////////////

Best regards, Lisheng

-----Original Message-----
From: ABlaise [mailto:ablaise@hotpads.com]
Sent: Friday, July 26, 2013 7:33 PM
To: java-user@lucene.apache.org
Subject: Detect a corrupted index


Hi everyone !

So I am working on a Lucene index that will run on a server and since this
server might crash/be killed at any time, even during the creation of an
index, I would like to be able to detect if an index is corrupted or not. I
don't care about repairing it, rebuilding it from scratch doesn't take too
long.

Any idea or hint on how I should proceed ? I searched for related topics but
they all seemed old and don't apply to Lucene 4.3.1

Thanks in advance

Adrien



--
View this message in context: http://lucene.472066.n3.nabble.com/Detect-a-corrupted-index-tp4080747.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message