From 51019502ec5615718ae92aa50fb9d8127c6742a4 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Wed, 30 Sep 2015 10:02:06 +0200 Subject: [PATCH] Fixed potential race condition in DataTree --- implementations/onblocks/datatreestore/DataTree.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/implementations/onblocks/datatreestore/DataTree.cpp b/implementations/onblocks/datatreestore/DataTree.cpp index 90df408c..c3fb15bb 100644 --- a/implementations/onblocks/datatreestore/DataTree.cpp +++ b/implementations/onblocks/datatreestore/DataTree.cpp @@ -135,6 +135,7 @@ unique_ref DataTree::releaseRootNode() { //TODO Test numLeaves(), for example also two configurations with same number of bytes but different number of leaves (last leaf has 0 bytes) uint32_t DataTree::numLeaves() const { + shared_lock lock(_mutex); return _numLeaves(*_rootNode); } @@ -158,7 +159,7 @@ void DataTree::traverseLeaves(uint32_t beginIndex, uint32_t endIndex, functionlayout().maxChildrenPerInnerNode(), endIndex); - uint32_t numLeaves = this->numLeaves(); + uint32_t numLeaves = this->_numLeaves(*_rootNode); if (_rootNode->depth() < neededTreeDepth) { //TODO Test cases that actually increase it here by 0 level / 1 level / more than 1 level increaseTreeDepth(neededTreeDepth - _rootNode->depth()); @@ -185,7 +186,7 @@ void DataTree::traverseLeaves(uint32_t beginIndex, uint32_t endIndex, function> DataTree::getOrCreateChildren(DataInnerNode *node, children.emplace_back(std::move(*child)); } for (uint32_t childIndex = node->numChildren(); childIndex < end; ++childIndex) { + //TODO This creates each child with one chain to one leaf only, and then on the next lower level it + // has to create the children for the child. Would be faster to directly create full trees if necessary. children.emplace_back(addChildTo(node)); } ASSERT(children.size() == end-begin, "Number of children in the result is wrong");