# HG changeset patch # User tatsuki # Date 1483049934 -32400 # Node ID 49a5391df9882a9dc3d34dabe4629d205d993942 # Parent 11285c2fbc8b0f8c3baa22a5088128349dd057a6 fix index update bug diff -r 11285c2fbc8b -r 49a5391df988 src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/index/CreateIndexBenchMark.java --- 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 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)); } } } diff -r 11285c2fbc8b -r 49a5391df988 src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/Node.java --- 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 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") diff -r 11285c2fbc8b -r 49a5391df988 src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/TreeMap.java --- 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 rootRebuildNode = root.delete(key, null, comparator, Rotate.N); - if (!rootRebuildNode.notEmpty()) + if (rootRebuildNode == null) return this; // 削除するノードが無かった場合 Node root = rootRebuildNode.getNode(); if (!root.isNotEmpty()) diff -r 11285c2fbc8b -r 49a5391df988 src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/rebuildNode.java --- 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(); } } diff -r 11285c2fbc8b -r 49a5391df988 src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/index/IndexUpdater.java --- 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 update(List editedNodeList, Index index, ParentIndex parentIndex) { Index newIndex = index; ParentIndex newParentIndex = parentIndex; - delete(editedNodeList, parentIndex, newIndex, newParentIndex); + Pair pair = delete(editedNodeList, parentIndex, newIndex, newParentIndex); + newIndex = pair.left(); + newParentIndex = pair.right(); return put(root, newIndex, newParentIndex); } @@ -44,7 +46,6 @@ return new Pair(newIndex,newParentIndex); } -static int count = 0; private Pair delete(List 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)) diff -r 11285c2fbc8b -r 49a5391df988 src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/manager/DefaultTransactionManager.java --- 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)) { diff -r 11285c2fbc8b -r 49a5391df988 src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/index/ParentIndexPutTest.java --- 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 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 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 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 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 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 parentOp = newTreeParentIndex.get(child); + Assert.assertTrue(parentOp.isPresent()); + TreeNode parentIndexGetNode = parentOp.get(); + Assert.assertEquals(parent,parentIndexGetNode); + } } - List deletedNodeList = new LinkedList<>(); deletedNodeList = getDeletedNodeList(deletedNodeList,oldTreeRoot,path); deletedNodeList = getDeletedNodeList(deletedNodeList,oldTreeRoot,path2);