You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Olga Dadasheva <ol...@harvard.edu> on 2004/04/02 05:09:34 UTC

"Already closed" IOException during index backup

Hi,

I am using Lucene latest CVS build and getting "Already closed" IOException during index backup. 
This code used to work , and I can still make it work if I set writer.setUseCompoundFile(false); 

Below is the stak trace and test code.


java.io.IOException: Already closed
Exception during index backup. java.io.IOException: Already closed
 at org.apache.lucene.index.CompoundFileReader.close(CompoundFileReader.java:110)
 at org.apache.lucene.index.SegmentReader.doClose(SegmentReader.java:170)
 at org.apache.lucene.index.IndexReader.close(IndexReader.java:413)
 at lucene.TestBackupIndex.backupCurrentIndex(TestBackupIndex.java:52)
 at lucene.TestBackupIndex.main(TestBackupIndex.java:43)


public class TestBackupIndex {
 String indexPath = "index";
 public TestBackupIndex() {
     try {
       IndexWriter writer = new IndexWriter(indexPath, new StandardAnalyzer(), true);
       Document doc = new Document();
       doc.add(new Field("category", "public", true, true, false));
       doc.add(new Field("content", "quick brown fox", true, true, false));
       writer.addDocument(doc);
       writer.optimize();
       writer.close();
       System.out.println("index built");

     } catch (IOException e) {
      e.printStackTrace();
     }
 }
 public static void main(String[] args) {
  TestBackupIndex test = new TestBackupIndex();
  test.backupCurrentIndex("backup");
 }
 
 public void backupCurrentIndex(String backupDir){
  try {
   IndexReader reader = IndexReader.open(indexPath);
   IndexWriter writer = new IndexWriter(backupDir, new StandardAnalyzer(), true);
   writer.addIndexes(new IndexReader[] { reader });
   writer.close();
   reader.close();
  } catch (IOException e) {
   System.out.println("Exception during index backup. "+e);
   e.printStackTrace();
  }
 }
 
}


Thank you,
-Olga