jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1365005 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/mk/index/ test/java/org/apache/jackrabbit/mk/index/
Date Tue, 24 Jul 2012 12:23:09 GMT
Author: thomasm
Date: Tue Jul 24 12:23:08 2012
New Revision: 1365005

URL: http://svn.apache.org/viewvc?rev=1365005&view=rev
Log:
OAK-137 Query: content index

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreeLeaf.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreeNode.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreePage.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Cursor.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/IndexTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PrefixIndexTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PropertyIndexTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreeLeaf.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreeLeaf.java?rev=1365005&r1=1365004&r2=1365005&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreeLeaf.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreeLeaf.java
Tue Jul 24 12:23:08 2012
@@ -110,7 +110,7 @@ class BTreeLeaf extends BTreePage {
 
     @Override
     public String toString() {
-    		return "leaf: " + getJsop();
+        return "leaf: " + getJsop();
     }
 
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreeNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreeNode.java?rev=1365005&r1=1365004&r2=1365005&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreeNode.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreeNode.java
Tue Jul 24 12:23:08 2012
@@ -178,7 +178,7 @@ class BTreeNode extends BTreePage {
 
     @Override
     public String toString() {
-    		return "node: " + getJsop();
+        return "node: " + getJsop();
     }
 
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreePage.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreePage.java?rev=1365005&r1=1365004&r2=1365005&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreePage.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/BTreePage.java
Tue Jul 24 12:23:08 2012
@@ -52,7 +52,7 @@ abstract class BTreePage {
                 newParent.writeCreate();
             }
             tree.bufferMove(
-            			temp,
+                    temp,
                     PathUtils.concat(tree.getName(), Indexer.INDEX_CONTENT, getParentPath(),
newName));
             parent = newParent;
             name = newName;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Cursor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Cursor.java?rev=1365005&r1=1365004&r2=1365005&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Cursor.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Cursor.java
Tue Jul 24 12:23:08 2012
@@ -73,15 +73,20 @@ public class Cursor implements Iterator<
         this.pos = pos;
     }
 
+    /**
+     * An iterator over a cursor.
+     */
     public static class RangeIterator implements Iterator<String> {
         private final Cursor cursor;
         private final String maxKey;
         private String value;
+
         RangeIterator(Cursor cursor, String maxKey) {
             this.cursor = cursor;
             this.maxKey = maxKey;
             step();
         }
+
         private void step() {
             value = null;
             if (cursor.hasNext()) {
@@ -91,20 +96,24 @@ public class Cursor implements Iterator<
                 }
             }
         }
+
         @Override
         public boolean hasNext() {
             return value != null;
         }
+
         @Override
         public String next() {
             String v = value;
             step();
             return v;
         }
+
         @Override
         public void remove() {
             throw new UnsupportedOperationException();
         }
+
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java?rev=1365005&r1=1365004&r2=1365005&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java
Tue Jul 24 12:23:08 2012
@@ -42,17 +42,17 @@ import java.util.Map.Entry;
  */
 public class Indexer implements QueryIndexProvider {
 
-	/**
-	 * The root node of the index definition (configuration) nodes.
-	 */
+    /**
+     * The root node of the index definition (configuration) nodes.
+     */
     // TODO OAK-178 discuss where to store index config data
-    public static final String INDEX_CONFIG_ROOT = "/jcr:system/indexes";
+    public static final String INDEX_CONFIG_PATH = "/jcr:system/indexes";
 
-	/**
-	 * For each index, the index content is stored relative to the index
-	 * definition below this node. There is also such a node just below the
-	 * index definition node, to store the last revision and for temporary data.
-	 */
+    /**
+     * For each index, the index content is stored relative to the index
+     * definition below this node. There is also such a node just below the
+     * index definition node, to store the last revision and for temporary data.
+     */
     public static final String INDEX_CONTENT = ":data";
 
     /**
@@ -63,6 +63,7 @@ public class Indexer implements QueryInd
     /**
      * The node name prefix of a property index.
      */
+    // TODO support multi-property indexes
     static final String TYPE_PROPERTY = "property@";
 
     /**
@@ -70,11 +71,16 @@ public class Indexer implements QueryInd
      */
     static final String UNIQUE = "unique";
 
+    /**
+     * The maximum length of the write buffer.
+     */
+    private static final int MAX_BUFFER_LENGTH = 100000;
+
     private static final boolean DISABLED = Boolean.getBoolean("mk.indexDisabled");
 
     private MicroKernel mk;
     private String revision;
-    private String indexRootNode = INDEX_CONFIG_ROOT;
+    private String indexRootNode = INDEX_CONFIG_PATH;
     private int indexRootNodeDepth;
     private StringBuilder buffer;
     private ArrayList<QueryIndex> queryIndexList;
@@ -135,8 +141,8 @@ public class Indexer implements QueryInd
         revision = mk.getHeadRevision();
         readRevision = revision;
         boolean exists = mk.nodeExists(indexRootNode, revision);
-		createNodes(INDEX_CONTENT);
-		if (exists) {
+        createNodes(INDEX_CONTENT);
+            if (exists) {
             String node = mk.getNodes(indexRootNode, revision, 1, 0, Integer.MAX_VALUE, null);
             JsopTokenizer t = new JsopTokenizer(node);
             NodeMap map = new NodeMap();
@@ -146,21 +152,21 @@ public class Indexer implements QueryInd
             if (rev != null) {
                 readRevision = rev;
             }
-			for (int i = 0; i < n.getChildNodeCount(); i++) {
-				String k = n.getChildNodeName(i);
-				PropertyIndex prop = PropertyIndex.fromNodeName(this, k);
-				if (prop != null) {
-					indexes.put(prop.getIndexNodeName(), prop);
-					propertyIndexes.put(prop.getPropertyName(), prop);
-					queryIndexList = null;
-				}
-				PrefixIndex pref = PrefixIndex.fromNodeName(this, k);
-				if (pref != null) {
-					indexes.put(pref.getIndexNodeName(), pref);
-					prefixIndexes.put(pref.getPrefix(), pref);
-					queryIndexList = null;
-				}
-			}
+            for (int i = 0; i < n.getChildNodeCount(); i++) {
+                String k = n.getChildNodeName(i);
+                PropertyIndex prop = PropertyIndex.fromNodeName(this, k);
+                if (prop != null) {
+                    indexes.put(prop.getIndexNodeName(), prop);
+                    propertyIndexes.put(prop.getPropertyName(), prop);
+                    queryIndexList = null;
+                }
+                PrefixIndex pref = PrefixIndex.fromNodeName(this, k);
+                if (pref != null) {
+                    indexes.put(pref.getIndexNodeName(), pref);
+                    prefixIndexes.put(pref.getPrefix(), pref);
+                    queryIndexList = null;
+                }
+            }
         }
     }
 
@@ -208,14 +214,15 @@ public class Indexer implements QueryInd
     }
 
     void createNodes(String path) {
-    		String rev = mk.getHeadRevision();
+        String rev = mk.getHeadRevision();
         JsopBuilder jsop = new JsopBuilder();
         String p = "/";
         path = PathUtils.concat(indexRootNode, path);
         for (String e : PathUtils.elements(path)) {
             p = PathUtils.concat(p, e);
             if (!mk.nodeExists(p, rev)) {
-                jsop.tag('+').key(PathUtils.relativize("/", p)).object().endObject().newline();
+                jsop.tag('+').key(PathUtils.relativize("/", p)).
+                    object().endObject().newline();
             }
         }
         revision = mk.commit("/", jsop.toString(), rev, null);
@@ -373,6 +380,9 @@ public class Indexer implements QueryInd
             }
             lastRevision = rev;
             t.read('}');
+            if (buffer != null && buffer.length() > MAX_BUFFER_LENGTH) {
+                updateEnd(rev);
+            }
         } while (t.matches(','));
         updateEnd(toRevision);
     }
@@ -388,17 +398,21 @@ public class Indexer implements QueryInd
         JsopBuilder jsop = new JsopBuilder();
         jsop.tag('^').key(PathUtils.concat(INDEX_CONTENT, "rev")).value(readRevision);
         buffer(jsop.toString());
+        flushBuffer();
+        return revision;
+    }
+
+    private void flushBuffer() {
         try {
             commitChanges();
         } catch (MicroKernelException e) {
             if (!mk.nodeExists(indexRootNode, revision)) {
                 // the index node itself was removed, which is
                 // unexpected but possible
-            		// this will cause all indexes to be removed, so
-            		// it can be ignored here
+                // this will cause all indexes to be removed, so
+                // it can be ignored here
             }
         }
-        return revision;
     }
 
     /**
@@ -493,12 +507,8 @@ public class Indexer implements QueryInd
     private void addOrRemoveRecursive(NodeImpl n, boolean remove, boolean add) {
         String path = n.getPath();
         if (isInIndex(path)) {
-            if (n.getPropertyCount() == 0) {
-                // add or remove the index itself - otherwise it's
-                // changing the root page of the index
-                addOrRemoveIndex(path, remove, add);
-            }
-            // don't index the index
+            addOrRemoveIndex(path, remove, add);
+            // don't index the index data itself
             return;
         }
         for (Index index : indexes.values()) {
@@ -561,7 +571,7 @@ public class Indexer implements QueryInd
 
     private void removeProperty(String path, String lastRevision) {
         if (isInIndex(path)) {
-            // don't index the index
+            // don't index the index data itself
             return;
         }
         String nodePath = PathUtils.getParentPath(path);
@@ -585,7 +595,7 @@ public class Indexer implements QueryInd
 
     private void addProperty(String path, String value) {
         if (isInIndex(path)) {
-            // don't index the index
+            // don't index the index data itself
             return;
         }
         String nodePath = PathUtils.getParentPath(path);
@@ -603,7 +613,7 @@ public class Indexer implements QueryInd
             if (targetPath != null) {
                 addOrRemoveIndex(targetPath, false, true);
             }
-            // don't index the index
+            // don't index the index data itself
             return;
         }
         if (!mk.nodeExists(sourcePath, lastRevision)) {
@@ -646,6 +656,13 @@ public class Indexer implements QueryInd
         for (Iterator<String> it = n.getChildNodeNames(Integer.MAX_VALUE); it.hasNext();)
{
             addRecursive(index, PathUtils.concat(path, it.next()));
         }
+        if (needFlush()) {
+            flushBuffer();
+        }
+    }
+
+    private boolean needFlush() {
+        return buffer != null && buffer.length() > MAX_BUFFER_LENGTH;
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/IndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/IndexTest.java?rev=1365005&r1=1365004&r2=1365005&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/IndexTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/IndexTest.java
Tue Jul 24 12:23:08 2012
@@ -240,7 +240,7 @@ public class IndexTest {
 
     static void print(MicroKernel mk, BTree tree) {
         String head = mk.getHeadRevision();
-        String t = mk.getNodes(Indexer.INDEX_CONFIG_ROOT, head, 100, 0, -1, null);
+        String t = mk.getNodes(Indexer.INDEX_CONFIG_PATH, head, 100, 0, -1, null);
         log(t);
         Cursor c = tree.findFirst("0");
         StringBuilder buff = new StringBuilder();

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PrefixIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PrefixIndexTest.java?rev=1365005&r1=1365004&r2=1365005&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PrefixIndexTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PrefixIndexTest.java
Tue Jul 24 12:23:08 2012
@@ -37,10 +37,10 @@ public class PrefixIndexTest {
         String head = mk.getHeadRevision();
 
         // meta data
-        String meta = mk.getNodes(Indexer.INDEX_CONFIG_ROOT, head, 1, 0, -1, null);
+        String meta = mk.getNodes(Indexer.INDEX_CONFIG_PATH, head, 1, 0, -1, null);
 
         Assert.assertEquals("{\":childNodeCount\":2,\"prefix@d:\":" +
-        		"{\":childNodeCount\":1,\":data\":{}},\":data\":{\":childNodeCount\":0}}", meta);
+                "{\":childNodeCount\":1,\":data\":{}},\":data\":{\":childNodeCount\":0}}",
meta);
 
         Assert.assertEquals("", getPathList(index, "d:1", head));
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PropertyIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PropertyIndexTest.java?rev=1365005&r1=1365004&r2=1365005&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PropertyIndexTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PropertyIndexTest.java
Tue Jul 24 12:23:08 2012
@@ -36,9 +36,9 @@ public class PropertyIndexTest {
         String head = mk.getHeadRevision();
 
         // meta data
-        String meta = mk.getNodes(Indexer.INDEX_CONFIG_ROOT, head, 1, 0, -1, null);
+        String meta = mk.getNodes(Indexer.INDEX_CONFIG_PATH, head, 1, 0, -1, null);
         Assert.assertEquals("{\":childNodeCount\":2,\":data\":{\":childNodeCount\":0}," +
-        		"\"property@id,unique\":{\":childNodeCount\":1,\":data\":{}}}", meta);
+                "\"property@id,unique\":{\":childNodeCount\":1,\":data\":{}}}", meta);
 
         String oldHead = head;
 



Mime
View raw message