jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r210092 - /incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/VolatileIndex.java
Date Mon, 11 Jul 2005 10:19:09 GMT
Author: mreutegg
Date: Mon Jul 11 03:19:06 2005
New Revision: 210092

URL: http://svn.apache.org/viewcvs?rev=210092&view=rev
Log:
JCR-128: Deleting binary property does not remove 'blob file' in filesystem
- Query handler did not close Reader in some cases (though introduction of LazyFileInputStream
already solved jira issue).

Modified:
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/VolatileIndex.java

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/VolatileIndex.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/VolatileIndex.java?rev=210092&r1=210091&r2=210092&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/VolatileIndex.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/VolatileIndex.java
Mon Jul 11 03:19:06 2005
@@ -20,13 +20,16 @@
 import org.apache.jackrabbit.core.fs.FileSystemException;
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.store.RAMDirectory;
+import org.apache.log4j.Logger;
 
 import java.io.IOException;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.Enumeration;
 
 /**
  * Implements an in-memory index with a redo log.
@@ -34,6 +37,11 @@
 class VolatileIndex extends AbstractIndex {
 
     /**
+     * Logger instance for this class.
+     */
+    private static final Logger log = Logger.getLogger(VolatileIndex.class);
+
+    /**
      * Default value for {@link #bufferSize}.
      */
     private static final int DEFAULT_BUFFER_SIZE = 10;
@@ -83,7 +91,10 @@
         } catch (FileSystemException e) {
             throw new IOException(e.getMessage());
         }
-        pending.put(doc.get(FieldNames.UUID), doc);
+        Document old = (Document) pending.put(doc.get(FieldNames.UUID), doc);
+        if (old != null) {
+            disposeDocument(old);
+        }
         if (pending.size() >= bufferSize) {
             commitPending();
         }
@@ -106,7 +117,9 @@
         } catch (FileSystemException e) {
             throw new IOException(e.getMessage());
         }
-        if (pending.remove(idTerm.text()) != null) {
+        Document doc = (Document) pending.remove(idTerm.text());
+        if (doc != null) {
+            disposeDocument(doc);
             // pending document has been removed
             return 1;
         } else {
@@ -154,6 +167,25 @@
             Document doc = (Document) it.next();
             super.addDocument(doc);
             it.remove();
+        }
+    }
+
+    /**
+     * Disposes the document <code>old</code>. Closes any potentially open
+     * readers held by the document.
+     *
+     * @param old the document to dispose.
+     */
+    private void disposeDocument(Document old) {
+        for (Enumeration e = old.fields(); e.hasMoreElements(); ) {
+            Field f = (Field) e.nextElement();
+            if (f.readerValue() != null) {
+                try {
+                    f.readerValue().close();
+                } catch (IOException ex) {
+                    log.warn("Exception while disposing index document: " + ex);
+                }
+            }
         }
     }
 }



Mime
View raw message