changeset 284:49a5391df988

fix index update bug
author tatsuki
date Fri, 30 Dec 2016 07:18:54 +0900
parents 11285c2fbc8b
children 1a36841024f2
files src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/index/CreateIndexBenchMark.java src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/Node.java src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/TreeMap.java src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/rebuildNode.java src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/index/IndexUpdater.java src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/manager/DefaultTransactionManager.java src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/index/ParentIndexPutTest.java
diffstat 7 files changed, 33 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/index/CreateIndexBenchMark.java	Fri Dec 30 05:40:16 2016 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/index/CreateIndexBenchMark.java	Fri Dec 30 07:18:54 2016 +0900
@@ -27,28 +27,22 @@
         JungleTreeEditor editor = tree.getJungleTreeEditor();
         NodePath path = new DefaultNodePath();
         System.out.println("start create Tree");
-        createTree(editor, key, indexKey, 3, path);
+        createTree(editor, key, indexKey, 5, path);
         System.out.println("end create Tree");
         for (int i = 1; i <= 10; i++) {
             NodePath editNodePath = new DefaultNodePath();
-            //editNodePath = editNodePath.add(0).add(0).add(0).add(0).add(0).add(0).add(0).add(0).add(0);
-            editNodePath = editNodePath.add(0).add(0);
+            editNodePath = editNodePath.add(0).add(0).add(0).add(0).add(0);//.add(0).add(0).add(0).add(0);
             Long t1 = System.currentTimeMillis();
-            for (int j = 0; j < (20 * i); j++) {
-                System.out.println(j);
+            for (int j = 0; j < (100 * i); j++) {
                 editor = tree.getJungleTreeEditor();
-                System.out.println("edit前");
                 Either<Error, JungleTreeEditor> either = editor.putAttribute(editNodePath, "key", ByteBuffer.wrap("value".getBytes()));
-                System.out.println("edit後");
                 Assert.assertFalse(either.isA());
                 editor = either.b();
-                System.out.println("commit前");
                 either = editor.success();
-                System.out.println("commit後");
                 Assert.assertFalse(either.isA());
             }
             Long t2 = System.currentTimeMillis();
-            System.out.println("edit count = " + (i * 20) + " : time = " + (t2 - t1));
+            System.out.println("edit count = " + (i * 100) + " : time = " + (t2 - t1));
         }
     }
 }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/Node.java	Fri Dec 30 05:40:16 2016 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/Node.java	Fri Dec 30 07:18:54 2016 +0900
@@ -91,7 +91,7 @@
             } else { //Equal
                 rebuildNode = replaceNode(parent, ctr);
             }
-            if (parent == null)
+            if (parent == null || rebuildNode == null)
                 return rebuildNode;
             Node<K, V> node = rebuildNode.getNode();
             if (rebuildNode.rebuild()) {
@@ -106,7 +106,7 @@
 
             return new rebuildNode<>(false, newParent);
         }
-        return new rebuildNode<>(false,new EmptyNode<>());
+        return null;
     }
 
     @SuppressWarnings("unchecked")
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/TreeMap.java	Fri Dec 30 05:40:16 2016 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/TreeMap.java	Fri Dec 30 07:18:54 2016 +0900
@@ -61,7 +61,7 @@
         if (key == null)
             return this;
         rebuildNode<K,V> rootRebuildNode = root.delete(key, null, comparator, Rotate.N);
-        if (!rootRebuildNode.notEmpty())
+        if (rootRebuildNode == null)
             return this; // 削除するノードが無かった場合
         Node<K,V> root = rootRebuildNode.getNode();
         if (!root.isNotEmpty())
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/rebuildNode.java	Fri Dec 30 05:40:16 2016 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/rebuildNode.java	Fri Dec 30 07:18:54 2016 +0900
@@ -19,6 +19,6 @@
     }
 
     public Boolean notEmpty(){
-        return node != null;
+        return node.isNotEmpty();
     }
 }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/index/IndexUpdater.java	Fri Dec 30 05:40:16 2016 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/index/IndexUpdater.java	Fri Dec 30 07:18:54 2016 +0900
@@ -20,7 +20,9 @@
     public Pair<Index, ParentIndex> update(List<TreeNode> editedNodeList, Index index, ParentIndex parentIndex) {
         Index newIndex = index;
         ParentIndex newParentIndex = parentIndex;
-        delete(editedNodeList, parentIndex, newIndex, newParentIndex);
+        Pair<Index,ParentIndex> pair = delete(editedNodeList, parentIndex, newIndex, newParentIndex);
+        newIndex = pair.left();
+        newParentIndex = pair.right();
         return put(root, newIndex, newParentIndex);
     }
 
@@ -44,7 +46,6 @@
         return new Pair<Index,ParentIndex>(newIndex,newParentIndex);
     }
 
-static int count = 0;
     private Pair<Index,ParentIndex> delete(List<TreeNode> editedNodeList, ParentIndex parentIndex, Index newIndex, ParentIndex newParentIndex) {
         for (TreeNode node : editedNodeList) {
             newParentIndex = newParentIndex.deleteAllChildren(node);
@@ -52,8 +53,6 @@
             if (parentOp.isPresent())
                 newIndex = newIndex.delete(node);
             while (parentOp.isPresent()) {
-                count ++;
-                System.out.println(count);
                 TreeNode parent = parentOp.get();
                 ParentIndex tmp = newParentIndex.deleteAllChildren(parent);
                 if (tmp.equals(newParentIndex))
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/manager/DefaultTransactionManager.java	Fri Dec 30 05:40:16 2016 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/manager/DefaultTransactionManager.java	Fri Dec 30 07:18:54 2016 +0900
@@ -66,8 +66,10 @@
         Index index = tip.getIndex();
         ParentIndex parentIndex = tip.getParentIndex();
         InterfaceTraverser traverser = new InterfaceTraverser(newRoot, index, parentIndex, true);
+        //System.out.println("start");
         traverser.updateIndex(editNodeList);
         //traverser.createIndex();
+        //System.out.println("end");
         TreeContext newTreeContext = new DefaultTreeContext(newRoot, tip, list, uuid, _treeName, nextRevision, traverser);
 
         if (repository.compareAndSet(newTreeContext.prev(), newTreeContext)) {
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/index/ParentIndexPutTest.java	Fri Dec 30 05:40:16 2016 +0900
+++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/index/ParentIndexPutTest.java	Fri Dec 30 07:18:54 2016 +0900
@@ -38,27 +38,28 @@
         JungleTree tree = jungle.getTreeByName("tree");
         JungleTreeEditor editor = tree.getJungleTreeEditor();
         NodePath path = new DefaultNodePath();
-        createTree(editor,key,indexKey,2,path);
+        createTree(editor,key,indexKey,3,path);
         TreeNode oldTreeRoot = tree.getRootNode();
         ParentIndex parentIndex = tree.getParentIndex();
         JungleNodeIterator iterator = new JungleNodeIterator(oldTreeRoot);
-        Assert.assertTrue(iterator.hasNext());
-        TreeNode node = iterator.next();
-        Assert.assertEquals(oldTreeRoot,node); //初めはrootなのでParentIndexは存在しない
         while(iterator.hasNext()){
-            TreeNode child = iterator.next();
-            Optional<TreeNode> parentOp = parentIndex.get(child);
-            Assert.assertTrue(parentOp.isPresent());
-            System.out.println(parentOp.get());
-        }
+            TreeNode parent = iterator.next();
+            Children children = parent.getChildren();
+            for (TreeNode child : children) {
+                Optional<TreeNode> parentOp = parentIndex.get(child);
+                Assert.assertTrue(parentOp.isPresent());
+                TreeNode parentIndexGetNode = parentOp.get();
+                Assert.assertEquals(parent,parentIndexGetNode);
+            }
+       }
 
         JungleTreeEditor editor2 = tree.getJungleTreeEditor();
-        path = path.add(0).add(0);//.add(2);
+        path = path.add(0).add(0).add(2);
         Either<Error, JungleTreeEditor> either = editor2.putAttribute(path,addAttributeKey, ByteBuffer.wrap("value".getBytes()) );
         Assert.assertFalse(either.isA());
         JungleTreeEditor editor3 = either.b();
         NodePath path2 = new DefaultNodePath();
-        path2 = path2.add(1).add(1);//.add(2);
+        path2 = path2.add(1).add(1).add(2);
         Either<Error, JungleTreeEditor> either2 = editor3.putAttribute(path2,addAttributeKey, ByteBuffer.wrap("value".getBytes()) );
         Assert.assertFalse(either2.isA());
         JungleTreeEditor editor4 = either2.b();
@@ -68,16 +69,16 @@
         TreeNode newTreeRoot = tree.getRootNode();
         ParentIndex newTreeParentIndex = tree.getParentIndex();
         iterator = new JungleNodeIterator(newTreeRoot);
-        Assert.assertTrue(iterator.hasNext());
-        node = iterator.next();
-        Assert.assertEquals(newTreeRoot,node);
         while(iterator.hasNext()){
-            TreeNode child = iterator.next();
-            Optional<TreeNode> parentOp = newTreeParentIndex.get(child);
-            Assert.assertTrue(parentOp.isPresent());
-            System.out.println(parentOp.get());
+            TreeNode parent = iterator.next();
+            Children children = parent.getChildren();
+            for (TreeNode child : children) {
+                Optional<TreeNode> parentOp = newTreeParentIndex.get(child);
+                Assert.assertTrue(parentOp.isPresent());
+                TreeNode parentIndexGetNode = parentOp.get();
+                Assert.assertEquals(parent,parentIndexGetNode);
+            }
         }
-
         List<TreeNode> deletedNodeList = new LinkedList<>();
         deletedNodeList = getDeletedNodeList(deletedNodeList,oldTreeRoot,path);
         deletedNodeList = getDeletedNodeList(deletedNodeList,oldTreeRoot,path2);