jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1243889 - in /jackrabbit/sandbox/microkernel/src: main/java/org/apache/jackrabbit/mk/ main/java/org/apache/jackrabbit/mk/index/ main/java/org/apache/jackrabbit/mk/json/ main/java/org/apache/jackrabbit/mk/wrapper/ test/java/org/apache/jackr...
Date Tue, 14 Feb 2012 12:04:43 GMT
Author: thomasm
Date: Tue Feb 14 12:04:42 2012
New Revision: 1243889

URL: http://svn.apache.org/viewvc?rev=1243889&view=rev
Log:
The index wrapper no longer reads the journal that much (WIP).
Separate methods to reset a Jsop reader and writer.

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopReader.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopStream.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopTokenizer.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopWriter.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/IndexWrapper.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/JsopStreamTest.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/JsopTest.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java?rev=1243889&r1=1243888&r2=1243889&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
Tue Feb 14 12:04:42 2012
@@ -285,7 +285,7 @@ public class MicroKernelImpl implements 
                 // addedNodes & removedNodes now only contain information about moved
nodes
 
                 // re-build the diff in a 2nd pass, this time representing moves correctly
-                buff.reset();
+                buff.resetWriter();
 
                 // TODO refactor code, avoid duplication
 

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java?rev=1243889&r1=1243888&r2=1243889&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java
Tue Feb 14 12:04:42 2012
@@ -19,6 +19,7 @@ package org.apache.jackrabbit.mk.index;
 import org.apache.jackrabbit.mk.MicroKernelImpl;
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.json.JsopBuilder;
+import org.apache.jackrabbit.mk.json.JsopReader;
 import org.apache.jackrabbit.mk.json.JsopTokenizer;
 import org.apache.jackrabbit.mk.mem.NodeImpl;
 import org.apache.jackrabbit.mk.mem.NodeMap;
@@ -270,26 +271,44 @@ public class Indexer {
             } while (t.matches(','));
             String rev = map.get("id");
             if (!rev.equals(readRevision)) {
-                updateWith(map.get("changes"), lastRevision);
+                String jsop = map.get("changes");
+                JsopTokenizer tokenizer = new JsopTokenizer(jsop);
+                updateIndex("", tokenizer, lastRevision);
             }
             lastRevision = rev;
             t.read('}');
         } while (t.matches(','));
+        updateEnd(toRevision);
+    }
+
+    /**
+     * Finish updating the index.
+     *
+     * @param toRevision the new index revision
+     * @return the new head revision
+     */
+    public String updateEnd(String toRevision) {
         readRevision = toRevision;
         JsopBuilder jsop = new JsopBuilder();
         jsop.tag('^').key("rev").value(readRevision);
         buffer(jsop.toString());
         commitChanges();
+        return revision;
     }
 
-    private void updateWith(String jsop, String lastRevision) {
-        JsopTokenizer t = new JsopTokenizer(jsop);
+    /**
+     * Update the index with the given changes.
+     *
+     * @param t the changes
+     * @param lastRevision
+     */
+    public void updateIndex(String rootPath, JsopReader t, String lastRevision) {
         while (true) {
             int r = t.read();
             if (r == JsopTokenizer.END) {
                 break;
             }
-            String path = t.readString();
+            String path = PathUtils.concat(rootPath, t.readString());
             switch (r) {
             case '+': {
                 t.read(':');
@@ -385,6 +404,7 @@ public class Indexer {
         if (!mk.nodeExists(nodePath, lastRevision)) {
             return;
         }
+        // TODO remove: support large trees
         String node = mk.getNodes(nodePath, lastRevision, Integer.MAX_VALUE, 0, Integer.MAX_VALUE);
         JsopTokenizer t = new JsopTokenizer(node);
         NodeMap map = new NodeMap();
@@ -418,6 +438,7 @@ public class Indexer {
         if (!mk.nodeExists(sourcePath, lastRevision)) {
             return;
         }
+        // TODO move: support large trees
         String node = mk.getNodes(sourcePath, lastRevision, Integer.MAX_VALUE, 0, Integer.MAX_VALUE);
         JsopTokenizer t = new JsopTokenizer(node);
         NodeMap map = new NodeMap();
@@ -442,6 +463,7 @@ public class Indexer {
         if (isInIndex(path)) {
             return;
         }
+        // TODO add: support large child node lists
         String node = mk.getNodes(path, readRevision, 0, 0, Integer.MAX_VALUE);
         JsopTokenizer t = new JsopTokenizer(node);
         NodeMap map = new NodeMap();

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java?rev=1243889&r1=1243888&r2=1243889&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java
Tue Feb 14 12:04:42 2012
@@ -33,7 +33,7 @@ public class JsopBuilder implements Jsop
     /**
      * Resets this instance.
      */
-    public void reset() {
+    public void resetWriter() {
         needComma = false;
         buff.setLength(0);
     }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopReader.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopReader.java?rev=1243889&r1=1243888&r2=1243889&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopReader.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopReader.java
Tue Feb 14 12:04:42 2012
@@ -32,4 +32,6 @@ public interface JsopReader {
 
     int getTokenType();
 
+    void resetReader();
+
 }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopStream.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopStream.java?rev=1243889&r1=1243888&r2=1243889&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopStream.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopStream.java
Tue Feb 14 12:04:42 2012
@@ -151,7 +151,11 @@ public class JsopStream implements JsopR
         return this;
     }
 
-    public void reset() {
+    public void resetReader() {
+        pos = 0;
+    }
+
+    public void resetWriter() {
         needComma = false;
         len = 0;
     }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopTokenizer.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopTokenizer.java?rev=1243889&r1=1243888&r2=1243889&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopTokenizer.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopTokenizer.java
Tue Feb 14 12:04:42 2012
@@ -50,6 +50,11 @@ public class JsopTokenizer implements Js
         this(json, 0);
     }
 
+    public void resetReader() {
+        pos = 0;
+        read();
+    }
+
     public String toString() {
         return jsop;
     }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopWriter.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopWriter.java?rev=1243889&r1=1243888&r2=1243889&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopWriter.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopWriter.java
Tue Feb 14 12:04:42 2012
@@ -42,7 +42,7 @@ public interface JsopWriter {
 
     JsopWriter newline();
 
-    void reset();
+    void resetWriter();
 
     void setLineLength(int i);
 

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/IndexWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/IndexWrapper.java?rev=1243889&r1=1243888&r2=1243889&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/IndexWrapper.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/IndexWrapper.java
Tue Feb 14 12:04:42 2012
@@ -86,7 +86,12 @@ public class IndexWrapper extends Wrappe
 
     public String commitStream(String rootPath, JsopReader jsonDiff, String revisionId, String
message) {
         if (!rootPath.startsWith(INDEX_PATH)) {
-            return mk.commitStream(rootPath, jsonDiff, revisionId, message);
+            String rev = mk.commitStream(rootPath, jsonDiff, revisionId, message);
+            jsonDiff.resetReader();
+            indexer.updateIndex(rootPath, jsonDiff, rev);
+            rev = mk.getHeadRevision();
+            rev = indexer.updateEnd(rev);
+            return rev;
         }
         JsopReader t = jsonDiff;
         while (true) {
@@ -104,7 +109,7 @@ public class IndexWrapper extends Wrappe
             case '+':
                 t.read(':');
                 t.read('{');
-                // parse bug ignore
+                // parse but ignore
                 NodeImpl.parse(map, t, 0);
                 path = PathUtils.relativize(INDEX_PATH, path);
                 if (path.startsWith(TYPE_PREFIX)) {

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/JsopStreamTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/JsopStreamTest.java?rev=1243889&r1=1243888&r2=1243889&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/JsopStreamTest.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/JsopStreamTest.java
Tue Feb 14 12:04:42 2012
@@ -31,7 +31,7 @@ public class JsopStreamTest extends Test
             for (int i = 0; i < 1000000; i++) {
                 w.value(s);
                 if (i % 100 == 0) {
-                    w.reset();
+                    w.resetWriter();
                 }
             }
             System.out.println(w.getClass() + ": " + timer.seconds());
@@ -57,15 +57,19 @@ public class JsopStreamTest extends Test
     }
 
     private void testRawValue(JsopReader s) {
-        assertFalse(s.matches('-'));
-        assertTrue(s.matches('+'));
-        assertEquals("x", s.read(JsopTokenizer.STRING));
-        s.read(':');
-        assertEquals("{", s.read('{'));
-        assertEquals("y", s.readString());
-        s.read(':');
-        assertEquals("[1,[],2]", s.readRawValue());
-        s.read('}');
+        for (int i = 0; i < 3; i++) {
+            assertFalse(s.matches('-'));
+            assertTrue(s.matches('+'));
+            assertEquals("x", s.read(JsopTokenizer.STRING));
+            s.read(':');
+            assertEquals("{", s.read('{'));
+            assertEquals("y", s.readString());
+            s.read(':');
+            assertEquals("[1,[],2]", s.readRawValue());
+            s.read('}');
+            s.read(JsopTokenizer.END);
+            s.resetReader();
+        }
     }
 
     public void testJsopReader() {
@@ -216,7 +220,7 @@ public class JsopStreamTest extends Test
                 "\"obj\":{\"boolean\":true,\"null\":null," +
                 "\"arr\":[[1,\"\\u001f ~ \\u007f \\u0080\",\"42\"],[]]},\"some\":\"more\"}",
json);
 
-        buff.reset();
+        buff.resetWriter();
         buff.array().
                 object().key("x").value("1").endObject().newline().
                 object().key("y").value("2").endObject().newline().

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/JsopTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/JsopTest.java?rev=1243889&r1=1243888&r2=1243889&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/JsopTest.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/json/JsopTest.java
Tue Feb 14 12:04:42 2012
@@ -309,7 +309,7 @@ public class JsopTest extends TestCase {
                 "\"obj\":{\"boolean\":true,\"null\":null," +
                 "\"arr\":[[1,\"\\u001f ~ \\u007f \\u0080\",\"42\"],[]]},\"some\":\"more\"}",
json);
 
-        buff.reset();
+        buff.resetWriter();
         buff.array().
                 object().key("x").value("1").endObject().newline().
                 object().key("y").value("2").endObject().newline().



Mime
View raw message