jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r615223 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene: CachingIndexReader.java DocId.java IndexMerger.java
Date Fri, 25 Jan 2008 13:46:15 GMT
Author: mreutegg
Date: Fri Jan 25 05:46:15 2008
New Revision: 615223

URL: http://svn.apache.org/viewvc?rev=615223&view=rev
Log:
JCR-1337: Optimize first execution queries for DescendantSelfAxisWeight/ChildAxisQuery

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/CachingIndexReader.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DocId.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexMerger.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/CachingIndexReader.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/CachingIndexReader.java?rev=615223&r1=615222&r2=615223&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/CachingIndexReader.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/CachingIndexReader.java
Fri Jan 25 05:46:15 2008
@@ -22,11 +22,16 @@
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermDocs;
 import org.apache.lucene.index.TermEnum;
+import org.apache.jackrabbit.uuid.UUID;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
 import java.util.BitSet;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.text.NumberFormat;
 
 /**
  * Implements an <code>IndexReader</code> that maintains caches to resolve
@@ -69,11 +74,14 @@
      * @param delegatee the base <code>IndexReader</code>.
      * @param cache     a document number cache, or <code>null</code> if not
      *                  available to this reader.
+     * @throws IOException if an error occurs while reading from the index.
      */
-    CachingIndexReader(IndexReader delegatee, DocNumberCache cache) {
+    CachingIndexReader(IndexReader delegatee, DocNumberCache cache)
+            throws IOException {
         super(delegatee);
         this.cache = cache;
         parents = new DocId[delegatee.maxDoc()];
+        initializeParents(delegatee);
     }
 
     /**
@@ -211,6 +219,74 @@
     private static long getNextCreationTick() {
         synchronized (CachingIndexReader.class) {
             return currentTick++;
+        }
+    }
+
+    /**
+     * Initializes the {@link #parents} <code>DocId</code> array.
+     *
+     * @param reader the underlying index reader.
+     * @throws IOException if an error occurs while reading from the index.
+     */
+    private void initializeParents(IndexReader reader) throws IOException {
+        long time = System.currentTimeMillis();
+        Map docs = new HashMap();
+        for (int i = 0; i < reader.maxDoc(); i++) {
+            if (!reader.isDeleted(i)) {
+                Document doc = reader.document(i, FieldSelectors.UUID_AND_PARENT);
+                UUID uuid = UUID.fromString(doc.get(FieldNames.UUID));
+                UUID parent = null;
+                try {
+                    parent = UUID.fromString(doc.get(FieldNames.PARENT));
+                } catch (IllegalArgumentException e) {
+                    // root node does not have a parent
+                }
+                NodeInfo info = new NodeInfo(i, uuid, parent);
+                docs.put(uuid, info);
+            }
+        }
+        double foreignParents = 0;
+        for (Iterator it = docs.values().iterator(); it.hasNext(); ) {
+            NodeInfo info = (NodeInfo) it.next();
+            NodeInfo parent = (NodeInfo) docs.get(info.parent);
+            if (parent != null) {
+                parents[info.docId] = DocId.create(parent.docId);
+            } else if (info.parent != null) {
+                foreignParents++;
+                parents[info.docId] = DocId.create(info.parent);
+            } else {
+                // no parent -> root node
+                parents[info.docId] = DocId.NULL;
+            }
+        }
+        if (log.isDebugEnabled()) {
+            NumberFormat nf = NumberFormat.getPercentInstance();
+            nf.setMaximumFractionDigits(1);
+            time = System.currentTimeMillis() - time;
+            if (parents.length > 0) {
+                foreignParents /= parents.length;
+            }
+            log.debug("initialized {} DocIds in {} ms, {} foreign parents",
+                    new Object[]{
+                        new Integer(parents.length),
+                        new Long(time),
+                        nf.format(foreignParents)
+                    });
+        }
+    }
+
+    private static class NodeInfo {
+
+        final int docId;
+
+        final UUID uuid;
+
+        final UUID parent;
+
+        public NodeInfo(int docId, UUID uuid, UUID parent) {
+            this.docId = docId;
+            this.uuid = uuid;
+            this.parent = parent;
         }
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DocId.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DocId.java?rev=615223&r1=615222&r2=615223&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DocId.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DocId.java
Fri Jan 25 05:46:15 2008
@@ -107,8 +107,19 @@
      *
      * @param uuid the node uuid.
      * @return a <code>DocId</code> based on a node UUID.
+     * @throws IllegalArgumentException if the <code>uuid</code> is malformed.
      */
     static DocId create(String uuid) {
+        return create(UUID.fromString(uuid));
+    }
+
+    /**
+     * Creates a <code>DocId</code> based on a node UUID.
+     *
+     * @param uuid the node uuid.
+     * @return a <code>DocId</code> based on a node UUID.
+     */
+    static DocId create(UUID uuid) {
         return new UUIDDocId(uuid);
     }
 
@@ -188,13 +199,10 @@
          * Creates a <code>DocId</code> based on a Node uuid.
          *
          * @param uuid the Node uuid.
-         * @throws IllegalArgumentException if the <code>uuid</code> is
-         *                                  malformed.
          */
-        UUIDDocId(String uuid) {
-            UUID tmp = UUID.fromString(uuid);
-            this.lsb = tmp.getLeastSignificantBits();
-            this.msb = tmp.getMostSignificantBits();
+        UUIDDocId(UUID uuid) {
+            this.lsb = uuid.getLeastSignificantBits();
+            this.msb = uuid.getMostSignificantBits();
         }
 
         /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexMerger.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexMerger.java?rev=615223&r1=615222&r2=615223&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexMerger.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexMerger.java
Fri Jan 25 05:46:15 2008
@@ -302,6 +302,12 @@
                             docCount += readers[i].numDocs();
                         }
                         log.info("merged " + docCount + " documents in " + time + " ms into
" + index.getName() + ".");
+
+                        // force initializing of caches
+                        time = System.currentTimeMillis();
+                        index.getReadOnlyIndexReader().close();
+                        time = System.currentTimeMillis() - time;
+                        log.debug("reader obtained in {} ms", new Long(time));
                     } finally {
                         for (int i = 0; i < readers.length; i++) {
                             try {



Mime
View raw message