lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r515316 - in /lucene/java/trunk: ./ src/java/org/apache/lucene/index/ src/java/org/apache/lucene/store/ src/test/org/apache/lucene/index/ src/test/org/apache/lucene/search/ src/test/org/apache/lucene/store/
Date Tue, 06 Mar 2007 21:40:56 GMT
Author: mikemccand
Date: Tue Mar  6 13:40:55 2007
New Revision: 515316

URL: http://svn.apache.org/viewvc?view=rev&rev=515316
Log:
LUCENE-823: add unit test coverage to assert that when a MockRAMDirectory is closed, there
are no open files; fixed 2 minor cases this check uncovered

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java
    lucene/java/trunk/src/java/org/apache/lucene/store/RAMDirectory.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestFilterIndexReader.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestParallelReader.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestMultiSearcher.java
    lucene/java/trunk/src/test/org/apache/lucene/store/MockRAMDirectory.java
    lucene/java/trunk/src/test/org/apache/lucene/store/MockRAMInputStream.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?view=diff&rev=515316&r1=515315&r2=515316
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Tue Mar  6 13:40:55 2007
@@ -38,6 +38,11 @@
     failed to reduce the number of open descriptors since it was still
     opened once per field with norms. (yonik)
 
+ 5. LUCENE-823: Make sure internal file handles are closed when
+    hitting an exception (eg disk full) while flushing deletes in
+    IndexWriter's mergeSegments, and also during
+    IndexWriter.addIndexes.  (Mike McCandless)
+
 New features
 
  1. LUCENE-759: Added two n-gram-producing TokenFilters.

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java?view=diff&rev=515316&r1=515315&r2=515316
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java Tue Mar  6 13:40:55
2007
@@ -1274,42 +1274,49 @@
     SegmentMerger merger = new SegmentMerger(this, mergedName);
 
     final Vector segmentsToDelete = new Vector();
+    SegmentInfo info;
+    String segmentsInfosFileName = segmentInfos.getCurrentSegmentFileName();
+
     IndexReader sReader = null;
-    if (segmentInfos.size() == 1){ // add existing index, if any
+    try {
+      if (segmentInfos.size() == 1){ // add existing index, if any
         sReader = SegmentReader.get(segmentInfos.info(0));
         merger.add(sReader);
         segmentsToDelete.addElement(sReader);   // queue segment for deletion
-    }
-
-    for (int i = 0; i < readers.length; i++)      // add new indexes
-      merger.add(readers[i]);
-
-    SegmentInfo info;
+      }
 
-    String segmentsInfosFileName = segmentInfos.getCurrentSegmentFileName();
+      for (int i = 0; i < readers.length; i++)      // add new indexes
+        merger.add(readers[i]);
 
-    boolean success = false;
+      boolean success = false;
 
-    startTransaction();
+      startTransaction();
 
-    try {
-      int docCount = merger.merge();                // merge 'em
+      try {
+        int docCount = merger.merge();                // merge 'em
 
-      segmentInfos.setSize(0);                      // pop old infos & add new
-      info = new SegmentInfo(mergedName, docCount, directory, false, true);
-      segmentInfos.addElement(info);
-      commitPending = true;
+        segmentInfos.setSize(0);                      // pop old infos & add new
+        info = new SegmentInfo(mergedName, docCount, directory, false, true);
+        segmentInfos.addElement(info);
+        commitPending = true;
 
-      if(sReader != null)
-        sReader.close();
+        if(sReader != null) {
+          sReader.close();
+          sReader = null;
+        }
 
-      success = true;
+        success = true;
 
+      } finally {
+        if (!success) {
+          rollbackTransaction();
+        } else {
+          commitTransaction();
+        }
+      }
     } finally {
-      if (!success) {
-        rollbackTransaction();
-      } else {
-        commitTransaction();
+      if (sReader != null) {
+        sReader.close();
       }
     }
 
@@ -1317,7 +1324,7 @@
     deleter.deleteSegments(segmentsToDelete);     // delete now-unused segments
 
     if (useCompoundFile) {
-      success = false;
+      boolean success = false;
 
       segmentsInfosFileName = segmentInfos.getCurrentSegmentFileName();
       Vector filesToDelete;
@@ -1699,8 +1706,13 @@
           // the documents buffered before it, not those buffered after it.
           applyDeletesSelectively(bufferedDeleteTerms, reader);
         } finally {
-          if (reader != null)
-            reader.close();
+          if (reader != null) {
+            try {
+              reader.doCommit();
+            } finally {
+              reader.doClose();
+            }
+          }
         }
       }
 
@@ -1719,8 +1731,13 @@
           // except the one just flushed from ram.
           applyDeletes(bufferedDeleteTerms, reader);
         } finally {
-          if (reader != null)
-            reader.close();
+          if (reader != null) {
+            try {
+              reader.doCommit();
+            } finally {
+              reader.doClose();
+            }
+          }
         }
       }
 

Modified: lucene/java/trunk/src/java/org/apache/lucene/store/RAMDirectory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/RAMDirectory.java?view=diff&rev=515316&r1=515315&r2=515316
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/RAMDirectory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/RAMDirectory.java Tue Mar  6 13:40:55
2007
@@ -226,7 +226,7 @@
   }
 
   /** Closes the store to future operations, releasing associated memory. */
-  public final void close() {
+  public void close() {
     fileMap = null;
   }
 

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestFilterIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestFilterIndexReader.java?view=diff&rev=515316&r1=515315&r2=515316
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestFilterIndexReader.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestFilterIndexReader.java Tue Mar
 6 13:40:55 2007
@@ -23,6 +23,7 @@
 import junit.textui.TestRunner;
 
 import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.store.MockRAMDirectory;
 import org.apache.lucene.analysis.WhitespaceAnalyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
@@ -91,7 +92,7 @@
    * @throws Exception on error
    */
   public void testFilterIndexReader() throws Exception {
-    RAMDirectory directory = new RAMDirectory();
+    RAMDirectory directory = new MockRAMDirectory();
     IndexWriter writer =
       new IndexWriter(directory, new WhitespaceAnalyzer(), true);
 
@@ -123,5 +124,6 @@
     }
 
     reader.close();
+    directory.close();
   }
 }

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java?view=diff&rev=515316&r1=515315&r2=515316
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java Tue Mar  6 13:40:55
2007
@@ -61,7 +61,7 @@
 
     public void testIsCurrent() throws Exception
     {
-      RAMDirectory d = new RAMDirectory();
+      RAMDirectory d = new MockRAMDirectory();
       IndexWriter writer = new IndexWriter(d, new StandardAnalyzer(), true);
       addDocumentWithFields(writer);
       writer.close();
@@ -79,6 +79,7 @@
       writer.close();
       assertFalse(reader.isCurrent());
       reader.close();
+      d.close();
     }
 
     /**
@@ -87,7 +88,7 @@
      */
     public void testGetFieldNames() throws Exception
     {
-        RAMDirectory d = new RAMDirectory();
+        RAMDirectory d = new MockRAMDirectory();
         // set up writer
         IndexWriter writer = new IndexWriter(d, new StandardAnalyzer(), true);
         addDocumentWithFields(writer);
@@ -99,6 +100,7 @@
         assertTrue(fieldNames.contains("text"));
         assertTrue(fieldNames.contains("unindexed"));
         assertTrue(fieldNames.contains("unstored"));
+        reader.close();
         // add more documents
         writer = new IndexWriter(d, new StandardAnalyzer(), false);
         // want to get some more segments here
@@ -173,7 +175,8 @@
         fieldNames = reader.getFieldNames(IndexReader.FieldOption.TERMVECTOR_WITH_POSITION_OFFSET);
         assertEquals(1, fieldNames.size());    // 4 fields are indexed with term vectors
         assertTrue(fieldNames.contains("tvpositionoffset"));
-        
+        reader.close();
+        d.close();
     }
 
 
@@ -205,7 +208,7 @@
 
     public void testBasicDelete() throws IOException
     {
-        Directory dir = new RAMDirectory();
+        Directory dir = new MockRAMDirectory();
 
         IndexWriter writer = null;
         IndexReader reader = null;
@@ -224,6 +227,7 @@
         reader = IndexReader.open(dir);
         assertEquals("first docFreq", 100, reader.docFreq(searchTerm));
         assertTermDocsCount("first reader", reader, searchTerm, 100);
+        reader.close();
 
         // DELETE DOCUMENTS CONTAINING TERM: aaa
         int deleted = 0;
@@ -244,6 +248,8 @@
         assertEquals("deleted docFreq", 100, reader.docFreq(searchTerm));
         assertTermDocsCount("deleted termDocs", reader, searchTerm, 0);
         reader.close();
+        reader2.close();
+        dir.close();
     }
 
     // Make sure attempts to make changes after reader is
@@ -561,7 +567,7 @@
 
     public void testLastModified() throws IOException {
       assertFalse(IndexReader.indexExists("there_is_no_such_index"));
-      Directory dir = new RAMDirectory();
+      Directory dir = new MockRAMDirectory();
       assertFalse(IndexReader.indexExists(dir));
       IndexWriter writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
       addDocumentWithFields(writer);
@@ -580,11 +586,12 @@
       reader = IndexReader.open(dir);
       assertTrue("old lastModified is " + version + "; new lastModified is " + IndexReader.lastModified(dir),
version <= IndexReader.lastModified(dir));
       reader.close();
+      dir.close();
     }
 
     public void testVersion() throws IOException {
       assertFalse(IndexReader.indexExists("there_is_no_such_index"));
-      Directory dir = new RAMDirectory();
+      Directory dir = new MockRAMDirectory();
       assertFalse(IndexReader.indexExists(dir));
       IndexWriter writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
       addDocumentWithFields(writer);
@@ -603,10 +610,11 @@
       reader = IndexReader.open(dir);
       assertTrue("old version is " + version + "; new version is " + IndexReader.getCurrentVersion(dir),
version < IndexReader.getCurrentVersion(dir));
       reader.close();
+      dir.close();
     }
 
     public void testLock() throws IOException {
-      Directory dir = new RAMDirectory();
+      Directory dir = new MockRAMDirectory();
       IndexWriter writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
       addDocumentWithFields(writer);
       writer.close();
@@ -622,10 +630,11 @@
       reader.deleteDocument(0);
       reader.close();
       writer.close();
+      dir.close();
     }
 
     public void testUndeleteAll() throws IOException {
-      Directory dir = new RAMDirectory();
+      Directory dir = new MockRAMDirectory();
       IndexWriter writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
       addDocumentWithFields(writer);
       addDocumentWithFields(writer);
@@ -638,10 +647,11 @@
       reader = IndexReader.open(dir);
       assertEquals(2, reader.numDocs());	// nothing has really been deleted thanks to undeleteAll()
       reader.close();
+      dir.close();
     }
 
     public void testUndeleteAllAfterClose() throws IOException {
-      Directory dir = new RAMDirectory();
+      Directory dir = new MockRAMDirectory();
       IndexWriter writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
       addDocumentWithFields(writer);
       addDocumentWithFields(writer);
@@ -654,10 +664,11 @@
       reader.undeleteAll();
       assertEquals(2, reader.numDocs());	// nothing has really been deleted thanks to undeleteAll()
       reader.close();
+      dir.close();
     }
 
     public void testUndeleteAllAfterCloseThenReopen() throws IOException {
-      Directory dir = new RAMDirectory();
+      Directory dir = new MockRAMDirectory();
       IndexWriter writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
       addDocumentWithFields(writer);
       addDocumentWithFields(writer);
@@ -672,6 +683,7 @@
       reader = IndexReader.open(dir);
       assertEquals(2, reader.numDocs());	// nothing has really been deleted thanks to undeleteAll()
       reader.close();
+      dir.close();
     }
 
     public void testDeleteReaderReaderConflictUnoptimized() throws IOException{
@@ -694,7 +706,7 @@
       int END_COUNT = 144;
       
       // First build up a starting index:
-      RAMDirectory startDir = new RAMDirectory();
+      RAMDirectory startDir = new MockRAMDirectory();
       IndexWriter writer = new IndexWriter(startDir, new WhitespaceAnalyzer(), true);
       for(int i=0;i<157;i++) {
         Document d = new Document();
@@ -875,10 +887,12 @@
         // Try again with 10 more bytes of free space:
         diskFree += 10;
       }
+
+      startDir.close();
     }
 
     public void testDocsOutOfOrderJIRA140() throws IOException {
-      Directory dir = new RAMDirectory();      
+      Directory dir = new MockRAMDirectory();      
       IndexWriter writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
       for(int i=0;i<11;i++) {
         addDoc(writer, "aaa");
@@ -913,11 +927,12 @@
       if (!gotException) {
         fail("delete of out-of-bounds doc number failed to hit exception");
       }
+      dir.close();
     }
 
     public void testExceptionReleaseWriteLockJIRA768() throws IOException {
 
-      Directory dir = new RAMDirectory();      
+      Directory dir = new MockRAMDirectory();      
       IndexWriter writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
       addDoc(writer, "aaa");
       writer.close();
@@ -945,6 +960,7 @@
       if (IndexReader.isLocked(dir)) {
         fail("write lock is still held after close");
       }
+      dir.close();
     }
 
     private String arrayToString(String[] l) {

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java?view=diff&rev=515316&r1=515315&r2=515316
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java Tue Mar  6 13:40:55
2007
@@ -427,6 +427,7 @@
 
       assertTrue("optimized used too much temporary space: starting usage was " + startDiskUsage
+ " bytes; max temp usage was " + maxDiskUsage + " but should have been " + (2*startDiskUsage)
+ " (= 2X starting usage)",
                  maxDiskUsage <= 2*startDiskUsage);
+      dir.close();
     }
 
     private String arrayToString(String[] l) {

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestParallelReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestParallelReader.java?view=diff&rev=515316&r1=515315&r2=515316
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestParallelReader.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestParallelReader.java Tue Mar  6
13:40:55 2007
@@ -36,6 +36,7 @@
 import org.apache.lucene.search.BooleanClause.Occur;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.store.MockRAMDirectory;
 
 public class TestParallelReader extends TestCase {
 
@@ -103,7 +104,7 @@
     Directory dir1 = getDir1();
 
     // one document only:
-    Directory dir2 = new RAMDirectory();
+    Directory dir2 = new MockRAMDirectory();
     IndexWriter w2 = new IndexWriter(dir2, new StandardAnalyzer(), true);
     Document d3 = new Document();
     d3.add(new Field("f3", "v1", Field.Store.YES, Field.Index.TOKENIZED));
@@ -137,7 +138,7 @@
 
   // Fiels 1-4 indexed together:
   private Searcher single() throws IOException {
-    Directory dir = new RAMDirectory();
+    Directory dir = new MockRAMDirectory();
     IndexWriter w = new IndexWriter(dir, new StandardAnalyzer(), true);
     Document d1 = new Document();
     d1.add(new Field("f1", "v1", Field.Store.YES, Field.Index.TOKENIZED));
@@ -167,7 +168,7 @@
   }
 
   private Directory getDir1() throws IOException {
-    Directory dir1 = new RAMDirectory();
+    Directory dir1 = new MockRAMDirectory();
     IndexWriter w1 = new IndexWriter(dir1, new StandardAnalyzer(), true);
     Document d1 = new Document();
     d1.add(new Field("f1", "v1", Field.Store.YES, Field.Index.TOKENIZED));

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing.java?view=diff&rev=515316&r1=515315&r2=515316
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing.java Tue Mar  6
13:40:55 2007
@@ -150,7 +150,7 @@
   public void testStressIndexAndSearching() throws Exception {
 
     // First in a RAM directory:
-    Directory directory = new RAMDirectory();
+    Directory directory = new MockRAMDirectory();
     runStressTest(directory);
     directory.close();
 

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestMultiSearcher.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestMultiSearcher.java?view=diff&rev=515316&r1=515315&r2=515316
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestMultiSearcher.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestMultiSearcher.java Tue Mar  6
13:40:55 2007
@@ -29,6 +29,7 @@
 import org.apache.lucene.queryParser.QueryParser;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.store.MockRAMDirectory;
 
 import java.io.IOException;
 import java.util.Collections;
@@ -59,8 +60,8 @@
         throws Exception
     {
         // creating two directories for indices
-        Directory indexStoreA = new RAMDirectory();
-        Directory indexStoreB = new RAMDirectory();
+        Directory indexStoreA = new MockRAMDirectory();
+        Directory indexStoreB = new MockRAMDirectory();
 
         // creating a document to store
         Document lDoc = new Document();
@@ -196,6 +197,8 @@
             Document d = hits3.doc(i);
         }
         mSearcher3.close();
+        indexStoreA.close();
+        indexStoreB.close();
     }
     
     private static Document createDocument(String contents1, String contents2) {
@@ -288,7 +291,7 @@
         IndexSearcher indexSearcher1;
         Hits hits;
         
-        ramDirectory1=new RAMDirectory();
+        ramDirectory1=new MockRAMDirectory();
         
         // First put the documents in the same index
         initIndex(ramDirectory1, nDocs, true, null); // documents with a single token "doc0",
"doc1", etc...
@@ -316,8 +319,8 @@
         RAMDirectory ramDirectory2;
         IndexSearcher indexSearcher2;
         
-        ramDirectory1=new RAMDirectory();
-        ramDirectory2=new RAMDirectory();
+        ramDirectory1=new MockRAMDirectory();
+        ramDirectory2=new MockRAMDirectory();
         
         // Now put the documents in a different index
         initIndex(ramDirectory1, nDocs, true, null); // documents with a single token "doc0",
"doc1", etc...

Modified: lucene/java/trunk/src/test/org/apache/lucene/store/MockRAMDirectory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/store/MockRAMDirectory.java?view=diff&rev=515316&r1=515315&r2=515316
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/store/MockRAMDirectory.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/store/MockRAMDirectory.java Tue Mar  6 13:40:55
2007
@@ -200,4 +200,17 @@
       size += ((RAMFile) it.next()).length;
     return size;
   }
+
+  public void close() {
+    if (openFiles == null) {
+      openFiles = new HashMap();
+    }
+    synchronized(openFiles) {
+      if (noDeleteOpenFile && openFiles.size() > 0) {
+        // RuntimeException instead of IOException because
+        // super() does not throw IOException currently:
+        throw new RuntimeException("MockRAMDirectory: cannot close: there are still open
files: " + openFiles);
+      }
+    }
+  }
 }

Modified: lucene/java/trunk/src/test/org/apache/lucene/store/MockRAMInputStream.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/store/MockRAMInputStream.java?view=diff&rev=515316&r1=515315&r2=515316
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/store/MockRAMInputStream.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/store/MockRAMInputStream.java Tue Mar  6
13:40:55 2007
@@ -25,6 +25,7 @@
 public class MockRAMInputStream extends RAMInputStream {
   private MockRAMDirectory dir;
   private String name;
+  private boolean isClone;
 
   /** Construct an empty output buffer. */
   public MockRAMInputStream(MockRAMDirectory dir, String name, RAMFile f) {
@@ -35,19 +36,29 @@
 
   public void close() {
     super.close();
-    synchronized(dir.openFiles) {
-      Integer v = (Integer) dir.openFiles.get(name);
-      if (v.intValue() == 1) {
-        dir.openFiles.remove(name);
-      } else {
-        v = new Integer(v.intValue()-1);
-        dir.openFiles.put(name, v);
+    // Pending resolution on LUCENE-686 we may want to
+    // remove the conditional check so we also track that
+    // all clones get closed:
+    if (!isClone) {
+      synchronized(dir.openFiles) {
+        Integer v = (Integer) dir.openFiles.get(name);
+        if (v.intValue() == 1) {
+          dir.openFiles.remove(name);
+        } else {
+          v = new Integer(v.intValue()-1);
+          dir.openFiles.put(name, v);
+        }
       }
     }
   }
 
   public Object clone() {
     MockRAMInputStream clone = (MockRAMInputStream) super.clone();
+    clone.isClone = true;
+    // Pending resolution on LUCENE-686 we may want to
+    // uncomment this code so that we also track that all
+    // clones get closed:
+    /*
     synchronized(dir.openFiles) {
       if (dir.openFiles.containsKey(name)) {
         Integer v = (Integer) dir.openFiles.get(name);
@@ -57,6 +68,7 @@
         throw new RuntimeException("BUG: cloned file was not open?");
       }
     }
+    */
     return clone;
   }
 }



Mime
View raw message