jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1236910 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk: model/ store/ store/util/
Date Fri, 27 Jan 2012 22:30:29 GMT
Author: stefan
Date: Fri Jan 27 22:30:28 2012
New Revision: 1236910

URL: http://svn.apache.org/viewvc?rev=1236910&view=rev
Log:
flat hierarchy support (WIP)

Added:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Binding.java
Removed:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/util/PersistentId.java
Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/AbstractNode.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesBucket.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/Node.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/StoredNode.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/IdFactory.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/util/Constants.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/util/Serializer.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/AbstractNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/AbstractNode.java?rev=1236910&r1=1236909&r2=1236910&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/AbstractNode.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/AbstractNode.java
Fri Jan 27 22:30:28 2012
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.mk.model;
 
+import org.apache.jackrabbit.mk.store.Binding;
 import org.apache.jackrabbit.mk.store.RevisionProvider;
 import org.apache.jackrabbit.mk.store.NotFoundException;
 import org.apache.jackrabbit.mk.util.AbstractRangeIterator;
@@ -206,4 +207,9 @@ public abstract class AbstractNode imple
             }
         }
     }
+    
+    public String serialize(Binding binding) throws Exception {
+        // todo implement
+        throw new Exception("not yet implemented") ;
+    }
 }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesBucket.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesBucket.java?rev=1236910&r1=1236909&r2=1236910&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesBucket.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesBucket.java
Fri Jan 27 22:30:28 2012
@@ -23,7 +23,7 @@ import java.util.HashMap;
  */
 public class ChildNodeEntriesBucket extends ChildNodeEntriesInlined {
 
-    ChildNodeEntriesBucket() {
+    public ChildNodeEntriesBucket() {
         // using stock HashMap since keeping insertion-order is not required
         entries = new HashMap<String, ChildNodeEntry>();
     }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/Node.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/Node.java?rev=1236910&r1=1236909&r2=1236910&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/Node.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/Node.java
Fri Jan 27 22:30:28 2012
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.mk.model;
 
+import org.apache.jackrabbit.mk.store.Binding;
 import org.apache.jackrabbit.mk.store.RevisionProvider;
 import org.apache.jackrabbit.mk.store.NotFoundException;
 
@@ -43,4 +44,6 @@ public interface Node {
     Node getNode(String relPath, RevisionProvider provider) throws NotFoundException, Exception;
 
     void diff(Node other, NodeDiffHandler handler);
+    
+    String serialize(Binding binding) throws Exception;
 }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/StoredNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/StoredNode.java?rev=1236910&r1=1236909&r2=1236910&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/StoredNode.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/StoredNode.java
Fri Jan 27 22:30:28 2012
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.mk.model;
 
+import org.apache.jackrabbit.mk.store.Binding;
 import org.apache.jackrabbit.mk.store.RevisionProvider;
 import org.apache.jackrabbit.mk.store.NotFoundException;
 import org.apache.jackrabbit.mk.util.UnmodifiableIterator;
@@ -31,6 +32,11 @@ public class StoredNode extends Abstract
 
     private final String id;
 
+    public static StoredNode deserialize(String id, Binding binding) throws Exception {
+        // todo implement
+        throw new Exception("not yet implemented");
+    }
+
     public StoredNode(String id, Map<String, String> properties, Iterator<ChildNodeEntry>
cneIt) {
         this.id = id;
         this.properties.putAll(properties);

Added: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Binding.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Binding.java?rev=1236910&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Binding.java
(added)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/Binding.java
Fri Jan 27 22:30:28 2012
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.mk.store;
+
+import java.util.Map;
+
+/**
+ *
+ */
+public interface Binding {
+    
+    void write(String name, String value) throws Exception;
+    void write(String name, long value) throws Exception;
+    void write(String name, int value) throws Exception;
+    void write(String name, Map<String, String> col) throws Exception;
+    
+    String readString(String name) throws Exception;
+    long readLong(String name) throws Exception;
+    int readInt(String name) throws Exception;
+    void read(String name, Map<String, String> col) throws Exception;
+}

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/IdFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/IdFactory.java?rev=1236910&r1=1236909&r2=1236910&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/IdFactory.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/IdFactory.java
Fri Jan 27 22:30:28 2012
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.mk.store;
 
 import java.security.MessageDigest;
 
+import org.apache.jackrabbit.mk.model.ChildNodeEntriesBucket;
 import org.apache.jackrabbit.mk.model.Commit;
 import org.apache.jackrabbit.mk.model.Node;
 import org.apache.jackrabbit.mk.util.AscendingClock;
@@ -30,15 +31,27 @@ abstract class IdFactory {
     /**
      * Create a new node id for some node.
      * 
-     * @param commit commit
+     * @param node node
      * @param serialized serialized data 
-     * @return raw revision id as byte array
+     * @return raw node id as byte array
      * @throws Exception if an error occurs
      */
     public byte[] createNodeId(Node node, byte[] serialized) throws Exception {
         return digest(serialized);
     }
-    
+
+    /**
+     * Create a new bucket id for some bucket.
+     *
+     * @param bucket bucket
+     * @param serialized serialized data
+     * @return raw bucket id as byte array
+     * @throws Exception if an error occurs
+     */
+    public byte[] createBucketId(ChildNodeEntriesBucket bucket, byte[] serialized) throws
Exception {
+        return digest(serialized);
+    }
+
     /**
      * Create a new revision id for some commit.
      * 

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java?rev=1236910&r1=1236909&r2=1236910&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/MongoPersistenceManager.java
Fri Jan 27 22:30:28 2012
@@ -55,6 +55,7 @@ public class MongoPersistenceManager ext
     private static final String HEAD_COLLECTION = "head";
     private static final String NODES_COLLECTION = "nodes";
     private static final String COMMITS_COLLECTION = "commits";
+    private static final String BUCKETS_COLLECTION = "buckets";
     private static final String ID_FIELD = ":id";
     private static final String DATA_FIELD = ":data";
     private static final String PROPERTIES_OBJECT = ":props";
@@ -64,6 +65,7 @@ public class MongoPersistenceManager ext
     private DB db;
     private DBCollection nodes;
     private DBCollection commits;
+    private DBCollection buckets;
     private GridFS fs;
 
     @Override
@@ -89,6 +91,11 @@ public class MongoPersistenceManager ext
                 new BasicDBObject(ID_FIELD, 1),
                 new BasicDBObject("unique", true));
 
+        buckets = db.getCollection(BUCKETS_COLLECTION);
+        buckets.ensureIndex(
+                new BasicDBObject(ID_FIELD, 1),
+                new BasicDBObject("unique", true));
+
         fs = new GridFS(db);
     }
 
@@ -168,7 +175,7 @@ public class MongoPersistenceManager ext
             BasicDBObject children = new BasicDBObject();
             while (it.hasNext()) {
                 ChildNodeEntry cne = it.next();
-                children.put(cne.getName(), cne.getId());
+                children.put(encodeName(cne.getName()), cne.getId());
             }
             nodeObject = new BasicDBObject(ID_FIELD, id)
                     .append(PROPERTIES_OBJECT, new BasicDBObject(encodeKeys(node.getProperties())))
@@ -271,14 +278,55 @@ public class MongoPersistenceManager ext
 
     @Override
     protected ChildNodeEntriesBucket readCNEBucket(String id) throws NotFoundException, Exception
{
-        // todo implement
-        return null;
+        BasicDBObject key = new BasicDBObject();
+        if (BINARY_FORMAT) {
+            key.put(ID_FIELD, StringUtils.convertHexToBytes(id));
+        } else {
+            key.put(ID_FIELD, id);
+        }
+        DBObject bucketObject = buckets.findOne(key);
+        if (bucketObject != null) {
+            if (BINARY_FORMAT) {
+                byte[] bytes = (byte[]) bucketObject.get(DATA_FIELD);
+                return Serializer.fromBytes(id, bytes, ChildNodeEntriesBucket.class);
+            } else {
+                ChildNodeEntriesBucket bucket = new ChildNodeEntriesBucket();
+                for (String name : bucketObject.keySet()) {
+                    if (!name.equals(ID_FIELD)) {
+                        bucket.add(new ChildNodeEntry(decodeName(name), (String) bucketObject.get(name)));
+                    }
+                }
+                return bucket;
+            }
+        } else {
+            throw new NotFoundException(id);
+        }
     }
 
     @Override
     protected String writeCNEBucket(ChildNodeEntriesBucket bucket) throws Exception {
-        // todo implement
-        return null;
+        byte[] bytes = Serializer.toBytes(bucket);
+        byte[] key = idFactory.createBucketId(bucket, bytes);
+        String id = StringUtils.convertBytesToHex(key);
+
+        BasicDBObject bucketObject;
+        if (BINARY_FORMAT) {
+            bucketObject = new BasicDBObject(ID_FIELD, key).append(DATA_FIELD, bytes);
+        } else {
+            bucketObject = new BasicDBObject(ID_FIELD, id);
+            Iterator<ChildNodeEntry> it = bucket.getEntries(0, -1);
+            while (it.hasNext()) {
+                ChildNodeEntry cne = it.next();
+                bucketObject.append(encodeName(cne.getName()), cne.getId());
+            }
+        }
+        try {
+            buckets.insert(bucketObject);
+        } catch (MongoException.DuplicateKey ignore) {
+            // fall through
+        }
+
+        return id;
     }
 
     //-------------------------------------------------------< implementation >

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/util/Constants.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/util/Constants.java?rev=1236910&r1=1236909&r2=1236910&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/util/Constants.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/util/Constants.java
Fri Jan 27 22:30:28 2012
@@ -21,13 +21,10 @@ package org.apache.jackrabbit.mk.store.u
  */
 public interface Constants {
 
-    static final String[] TYPE_NAMES = {"node", "nodetree", "fatnode", "fatnodepart", "commit",
"blob"};
-
-    static final int ANY = -1;
     static final int NODE = 0;
     static final int NODE_TREE = 1;
     static final int FAT_NODE = 2;
-    static final int FAT_NODE_PART = 3;
+    static final int FAT_NODE_BUCKET = 3;
     static final int COMMIT = 4;
     static final int BLOB = 5;
 }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/util/Serializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/util/Serializer.java?rev=1236910&r1=1236909&r2=1236910&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/util/Serializer.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/util/Serializer.java
Fri Jan 27 22:30:28 2012
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.mk.store.util;
 
+import org.apache.jackrabbit.mk.model.ChildNodeEntriesBucket;
 import org.apache.jackrabbit.mk.model.ChildNodeEntry;
 import org.apache.jackrabbit.mk.model.Commit;
 import org.apache.jackrabbit.mk.model.StoredCommit;
@@ -139,4 +140,38 @@ public class Serializer {
         return new StoredCommit(id, "".equals(parentId) ? null : parentId, commitTS, rootNodeId,
"".equals(msg) ? null : msg);
     }
 
+    //---------------------------------------------------------------< Commit >
+
+    public static byte[] toBytes(ChildNodeEntriesBucket bucket) {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        try {
+            out.write(Constants.FAT_NODE_BUCKET);
+            IOUtils.writeVarInt(out, bucket.getCount());
+            for (Iterator<ChildNodeEntry> it = bucket.getEntries(0, -1); it.hasNext();
) {
+                ChildNodeEntry entry = it.next();
+                IOUtils.writeString(out, entry.getName());
+                IOUtils.writeString(out, entry.getId());
+            }
+            out.close();
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+
+        return out.toByteArray();
+    }
+
+    public static ChildNodeEntriesBucket fromBytes(String id, byte[] bytes, Class<ChildNodeEntriesBucket>
type) throws Exception {
+        ByteArrayInputStream in = new ByteArrayInputStream(bytes);
+        if (in.read() != Constants.FAT_NODE_BUCKET) {
+            throw new Exception("unknown data format");
+        }
+        int count = IOUtils.readVarInt(in);
+        ChildNodeEntriesBucket bucket = new ChildNodeEntriesBucket();
+        while (count-- > 0) {
+            String name = IOUtils.readString(in);
+            String value = IOUtils.readString(in);
+            bucket.add(new ChildNodeEntry(name, value));
+        }
+        return bucket;
+    }
 }



Mime
View raw message