Rename blockstore::Key -> blockstore::BlockId
This commit is contained in:
parent
10e11f67e2
commit
5458af7c52
@ -15,7 +15,7 @@ using cpputils::unique_ref;
|
||||
using cpputils::Data;
|
||||
using blobstore::onblocks::datanodestore::DataLeafNode;
|
||||
using blobstore::onblocks::datanodestore::DataNodeLayout;
|
||||
using blockstore::Key;
|
||||
using blockstore::BlockId;
|
||||
using blobstore::onblocks::datatreestore::LeafHandle;
|
||||
|
||||
namespace blobstore {
|
||||
@ -131,7 +131,7 @@ void BlobOnBlocks::write(const void *source, uint64_t offset, uint64_t count) {
|
||||
if (leafDataOffset == 0 && leafDataSize == leaf.nodeStore()->layout().maxBytesPerLeaf()) {
|
||||
Data leafData(leafDataSize);
|
||||
std::memcpy(leafData.data(), (uint8_t*)source + indexOfFirstLeafByte - offset, leafDataSize);
|
||||
leaf.nodeStore()->overwriteLeaf(leaf.key(), std::move(leafData));
|
||||
leaf.nodeStore()->overwriteLeaf(leaf.blockId(), std::move(leafData));
|
||||
} else {
|
||||
//TODO Simplify formula, make it easier to understand
|
||||
leaf.node()->write((uint8_t *) source + indexOfFirstLeafByte - offset + leafDataOffset, leafDataOffset,
|
||||
@ -152,8 +152,8 @@ void BlobOnBlocks::flush() {
|
||||
_datatree->flush();
|
||||
}
|
||||
|
||||
const Key &BlobOnBlocks::key() const {
|
||||
return _datatree->key();
|
||||
const BlockId &BlobOnBlocks::blockId() const {
|
||||
return _datatree->blockId();
|
||||
}
|
||||
|
||||
unique_ref<DataTreeRef> BlobOnBlocks::releaseTree() {
|
||||
|
@ -22,7 +22,7 @@ public:
|
||||
BlobOnBlocks(cpputils::unique_ref<parallelaccessdatatreestore::DataTreeRef> datatree);
|
||||
~BlobOnBlocks();
|
||||
|
||||
const blockstore::Key &key() const override;
|
||||
const blockstore::BlockId &blockId() const override;
|
||||
|
||||
uint64_t size() const override;
|
||||
void resize(uint64_t numBytes) override;
|
||||
|
@ -15,7 +15,7 @@ using cpputils::make_unique_ref;
|
||||
|
||||
using blockstore::BlockStore;
|
||||
using blockstore::parallelaccess::ParallelAccessBlockStore;
|
||||
using blockstore::Key;
|
||||
using blockstore::BlockId;
|
||||
using cpputils::dynamic_pointer_move;
|
||||
using boost::optional;
|
||||
using boost::none;
|
||||
@ -38,8 +38,8 @@ unique_ref<Blob> BlobStoreOnBlocks::create() {
|
||||
return make_unique_ref<BlobOnBlocks>(_dataTreeStore->createNewTree());
|
||||
}
|
||||
|
||||
optional<unique_ref<Blob>> BlobStoreOnBlocks::load(const Key &key) {
|
||||
auto tree = _dataTreeStore->load(key);
|
||||
optional<unique_ref<Blob>> BlobStoreOnBlocks::load(const BlockId &blockId) {
|
||||
auto tree = _dataTreeStore->load(blockId);
|
||||
if (tree == none) {
|
||||
return none;
|
||||
}
|
||||
@ -52,8 +52,8 @@ void BlobStoreOnBlocks::remove(unique_ref<Blob> blob) {
|
||||
_dataTreeStore->remove((*_blob)->releaseTree());
|
||||
}
|
||||
|
||||
void BlobStoreOnBlocks::remove(const Key &key) {
|
||||
_dataTreeStore->remove(key);
|
||||
void BlobStoreOnBlocks::remove(const BlockId &blockId) {
|
||||
_dataTreeStore->remove(blockId);
|
||||
}
|
||||
|
||||
uint64_t BlobStoreOnBlocks::virtualBlocksizeBytes() const {
|
||||
|
@ -20,10 +20,10 @@ public:
|
||||
~BlobStoreOnBlocks();
|
||||
|
||||
cpputils::unique_ref<Blob> create() override;
|
||||
boost::optional<cpputils::unique_ref<Blob>> load(const blockstore::Key &key) override;
|
||||
boost::optional<cpputils::unique_ref<Blob>> load(const blockstore::BlockId &blockId) override;
|
||||
|
||||
void remove(cpputils::unique_ref<Blob> blob) override;
|
||||
void remove(const blockstore::Key &key) override;
|
||||
void remove(const blockstore::BlockId &blockId) override;
|
||||
|
||||
//TODO Test blocksizeBytes/numBlocks/estimateSpaceForNumBlocksLeft
|
||||
//virtual means "space we can use" as opposed to "space it takes on the disk" (i.e. virtual is without headers, checksums, ...)
|
||||
|
@ -7,7 +7,7 @@ using blockstore::BlockStore;
|
||||
using cpputils::Data;
|
||||
using cpputils::unique_ref;
|
||||
using cpputils::make_unique_ref;
|
||||
using blockstore::Key;
|
||||
using blockstore::BlockId;
|
||||
using std::vector;
|
||||
|
||||
namespace blobstore {
|
||||
@ -25,25 +25,25 @@ DataInnerNode::DataInnerNode(DataNodeView view)
|
||||
DataInnerNode::~DataInnerNode() {
|
||||
}
|
||||
|
||||
unique_ref<DataInnerNode> DataInnerNode::InitializeNewNode(unique_ref<Block> block, const DataNodeLayout &layout, uint8_t depth, const vector<Key> &children) {
|
||||
unique_ref<DataInnerNode> DataInnerNode::InitializeNewNode(unique_ref<Block> block, const DataNodeLayout &layout, uint8_t depth, const vector<BlockId> &children) {
|
||||
ASSERT(children.size() >= 1, "An inner node must have at least one child");
|
||||
Data data = _serializeChildren(children);
|
||||
|
||||
return make_unique_ref<DataInnerNode>(DataNodeView::initialize(std::move(block), layout, DataNode::FORMAT_VERSION_HEADER, depth, children.size(), std::move(data)));
|
||||
}
|
||||
|
||||
unique_ref<DataInnerNode> DataInnerNode::CreateNewNode(BlockStore *blockStore, const DataNodeLayout &layout, uint8_t depth, const vector<Key> &children) {
|
||||
unique_ref<DataInnerNode> DataInnerNode::CreateNewNode(BlockStore *blockStore, const DataNodeLayout &layout, uint8_t depth, const vector<BlockId> &children) {
|
||||
ASSERT(children.size() >= 1, "An inner node must have at least one child");
|
||||
Data data = _serializeChildren(children);
|
||||
|
||||
return make_unique_ref<DataInnerNode>(DataNodeView::create(blockStore, layout, DataNode::FORMAT_VERSION_HEADER, depth, children.size(), std::move(data)));
|
||||
}
|
||||
|
||||
Data DataInnerNode::_serializeChildren(const vector<Key> &children) {
|
||||
Data DataInnerNode::_serializeChildren(const vector<BlockId> &children) {
|
||||
Data data(sizeof(ChildEntry) * children.size());
|
||||
uint32_t i = 0;
|
||||
for (const Key &child : children) {
|
||||
reinterpret_cast<ChildEntry*>(data.data())[i++].setKey(child);
|
||||
for (const BlockId &child : children) {
|
||||
reinterpret_cast<ChildEntry*>(data.data())[i++].setBlockId(child);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
@ -89,12 +89,12 @@ void DataInnerNode::addChild(const DataNode &child) {
|
||||
ASSERT(numChildren() < maxStoreableChildren(), "Adding more children than we can store");
|
||||
ASSERT(child.depth() == depth()-1, "The child that should be added has wrong depth");
|
||||
node().setSize(node().Size()+1);
|
||||
LastChild()->setKey(child.key());
|
||||
LastChild()->setBlockId(child.blockId());
|
||||
}
|
||||
|
||||
void DataInnerNode::removeLastChild() {
|
||||
ASSERT(node().Size() > 1, "There is no child to remove");
|
||||
LastChild()->setKey(Key::Null());
|
||||
LastChild()->setBlockId(BlockId::Null());
|
||||
node().setSize(node().Size()-1);
|
||||
}
|
||||
|
||||
|
@ -11,8 +11,8 @@ namespace datanodestore {
|
||||
|
||||
class DataInnerNode final: public DataNode {
|
||||
public:
|
||||
static cpputils::unique_ref<DataInnerNode> InitializeNewNode(cpputils::unique_ref<blockstore::Block> block, const DataNodeLayout &layout, uint8_t depth, const std::vector<blockstore::Key> &children);
|
||||
static cpputils::unique_ref<DataInnerNode> CreateNewNode(blockstore::BlockStore *blockStore, const DataNodeLayout &layout, uint8_t depth, const std::vector<blockstore::Key> &children);
|
||||
static cpputils::unique_ref<DataInnerNode> InitializeNewNode(cpputils::unique_ref<blockstore::Block> block, const DataNodeLayout &layout, uint8_t depth, const std::vector<blockstore::BlockId> &children);
|
||||
static cpputils::unique_ref<DataInnerNode> CreateNewNode(blockstore::BlockStore *blockStore, const DataNodeLayout &layout, uint8_t depth, const std::vector<blockstore::BlockId> &children);
|
||||
|
||||
DataInnerNode(DataNodeView block);
|
||||
~DataInnerNode();
|
||||
@ -26,7 +26,7 @@ public:
|
||||
|
||||
uint32_t numChildren() const;
|
||||
|
||||
void addChild(const DataNode &child_key);
|
||||
void addChild(const DataNode &child_blockId);
|
||||
|
||||
void removeLastChild();
|
||||
|
||||
@ -40,7 +40,7 @@ private:
|
||||
const ChildEntry *ChildrenBegin() const;
|
||||
const ChildEntry *ChildrenEnd() const;
|
||||
|
||||
static cpputils::Data _serializeChildren(const std::vector<blockstore::Key> &children);
|
||||
static cpputils::Data _serializeChildren(const std::vector<blockstore::BlockId> &children);
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(DataInnerNode);
|
||||
};
|
||||
|
@ -10,15 +10,15 @@ namespace datanodestore{
|
||||
|
||||
struct DataInnerNode_ChildEntry final {
|
||||
public:
|
||||
blockstore::Key key() const {
|
||||
return blockstore::Key::FromBinary(_keydata);
|
||||
blockstore::BlockId blockId() const {
|
||||
return blockstore::BlockId::FromBinary(_blockIdData);
|
||||
}
|
||||
private:
|
||||
void setKey(const blockstore::Key &key) {
|
||||
key.ToBinary(_keydata);
|
||||
void setBlockId(const blockstore::BlockId &blockId) {
|
||||
blockId.ToBinary(_blockIdData);
|
||||
}
|
||||
friend class DataInnerNode;
|
||||
uint8_t _keydata[blockstore::Key::BINARY_LENGTH];
|
||||
uint8_t _blockIdData[blockstore::BlockId::BINARY_LENGTH];
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(DataInnerNode_ChildEntry);
|
||||
};
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
using blockstore::Block;
|
||||
using cpputils::Data;
|
||||
using blockstore::Key;
|
||||
using blockstore::BlockId;
|
||||
using blockstore::BlockStore;
|
||||
using cpputils::unique_ref;
|
||||
using cpputils::make_unique_ref;
|
||||
@ -31,10 +31,10 @@ unique_ref<DataLeafNode> DataLeafNode::CreateNewNode(BlockStore *blockStore, con
|
||||
return make_unique_ref<DataLeafNode>(DataNodeView::create(blockStore, layout, DataNode::FORMAT_VERSION_HEADER, 0, size, std::move(data)));
|
||||
}
|
||||
|
||||
unique_ref<DataLeafNode> DataLeafNode::OverwriteNode(BlockStore *blockStore, const DataNodeLayout &layout, const Key &key, Data data) {
|
||||
unique_ref<DataLeafNode> DataLeafNode::OverwriteNode(BlockStore *blockStore, const DataNodeLayout &layout, const BlockId &blockId, Data data) {
|
||||
ASSERT(data.size() == layout.maxBytesPerLeaf(), "Data passed in is too large for one leaf.");
|
||||
uint32_t size = data.size();
|
||||
return make_unique_ref<DataLeafNode>(DataNodeView::overwrite(blockStore, layout, DataNode::FORMAT_VERSION_HEADER, 0, size, key, std::move(data)));
|
||||
return make_unique_ref<DataLeafNode>(DataNodeView::overwrite(blockStore, layout, DataNode::FORMAT_VERSION_HEADER, 0, size, blockId, std::move(data)));
|
||||
}
|
||||
|
||||
void DataLeafNode::read(void *target, uint64_t offset, uint64_t size) const {
|
||||
|
@ -12,7 +12,7 @@ class DataInnerNode;
|
||||
class DataLeafNode final: public DataNode {
|
||||
public:
|
||||
static cpputils::unique_ref<DataLeafNode> CreateNewNode(blockstore::BlockStore *blockStore, const DataNodeLayout &layout, cpputils::Data data);
|
||||
static cpputils::unique_ref<DataLeafNode> OverwriteNode(blockstore::BlockStore *blockStore, const DataNodeLayout &layout, const blockstore::Key &key, cpputils::Data data);
|
||||
static cpputils::unique_ref<DataLeafNode> OverwriteNode(blockstore::BlockStore *blockStore, const DataNodeLayout &layout, const blockstore::BlockId &blockId, cpputils::Data data);
|
||||
|
||||
DataLeafNode(DataNodeView block);
|
||||
~DataLeafNode();
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <blockstore/utils/BlockStoreUtils.h>
|
||||
|
||||
using blockstore::Block;
|
||||
using blockstore::Key;
|
||||
using blockstore::BlockId;
|
||||
|
||||
using std::runtime_error;
|
||||
using cpputils::unique_ref;
|
||||
@ -31,8 +31,8 @@ const DataNodeView &DataNode::node() const {
|
||||
return _node;
|
||||
}
|
||||
|
||||
const Key &DataNode::key() const {
|
||||
return _node.key();
|
||||
const BlockId &DataNode::blockId() const {
|
||||
return _node.blockId();
|
||||
}
|
||||
|
||||
uint8_t DataNode::depth() const {
|
||||
@ -43,7 +43,7 @@ unique_ref<DataInnerNode> DataNode::convertToNewInnerNode(unique_ref<DataNode> n
|
||||
auto block = node->_node.releaseBlock();
|
||||
blockstore::utils::fillWithZeroes(block.get());
|
||||
|
||||
return DataInnerNode::InitializeNewNode(std::move(block), layout, first_child.depth()+1, {first_child.key()});
|
||||
return DataInnerNode::InitializeNewNode(std::move(block), layout, first_child.depth()+1, {first_child.blockId()});
|
||||
}
|
||||
|
||||
void DataNode::flush() const {
|
||||
|
@ -15,7 +15,7 @@ class DataNode {
|
||||
public:
|
||||
virtual ~DataNode();
|
||||
|
||||
const blockstore::Key &key() const;
|
||||
const blockstore::BlockId &blockId() const;
|
||||
|
||||
uint8_t depth() const;
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
using blockstore::BlockStore;
|
||||
using blockstore::Block;
|
||||
using blockstore::Key;
|
||||
using blockstore::BlockId;
|
||||
using cpputils::Data;
|
||||
using cpputils::unique_ref;
|
||||
using cpputils::make_unique_ref;
|
||||
@ -41,7 +41,7 @@ unique_ref<DataNode> DataNodeStore::load(unique_ref<Block> block) {
|
||||
}
|
||||
}
|
||||
|
||||
unique_ref<DataInnerNode> DataNodeStore::createNewInnerNode(uint8_t depth, const vector<Key> &children) {
|
||||
unique_ref<DataInnerNode> DataNodeStore::createNewInnerNode(uint8_t depth, const vector<BlockId> &children) {
|
||||
ASSERT(children.size() >= 1, "Inner node must have at least one child");
|
||||
return DataInnerNode::CreateNewNode(_blockstore.get(), _layout, depth, children);
|
||||
}
|
||||
@ -50,12 +50,12 @@ unique_ref<DataLeafNode> DataNodeStore::createNewLeafNode(Data data) {
|
||||
return DataLeafNode::CreateNewNode(_blockstore.get(), _layout, std::move(data));
|
||||
}
|
||||
|
||||
unique_ref<DataLeafNode> DataNodeStore::overwriteLeaf(const Key &key, Data data) {
|
||||
return DataLeafNode::OverwriteNode(_blockstore.get(), _layout, key, std::move(data));
|
||||
unique_ref<DataLeafNode> DataNodeStore::overwriteLeaf(const BlockId &blockId, Data data) {
|
||||
return DataLeafNode::OverwriteNode(_blockstore.get(), _layout, blockId, std::move(data));
|
||||
}
|
||||
|
||||
optional<unique_ref<DataNode>> DataNodeStore::load(const Key &key) {
|
||||
auto block = _blockstore->load(key);
|
||||
optional<unique_ref<DataNode>> DataNodeStore::load(const BlockId &blockId) {
|
||||
auto block = _blockstore->load(blockId);
|
||||
if (block == none) {
|
||||
return none;
|
||||
} else {
|
||||
@ -80,13 +80,13 @@ unique_ref<DataNode> DataNodeStore::overwriteNodeWith(unique_ref<DataNode> targe
|
||||
}
|
||||
|
||||
void DataNodeStore::remove(unique_ref<DataNode> node) {
|
||||
Key key = node->key();
|
||||
BlockId blockId = node->blockId();
|
||||
cpputils::destruct(std::move(node));
|
||||
remove(key);
|
||||
remove(blockId);
|
||||
}
|
||||
|
||||
void DataNodeStore::remove(const Key &key) {
|
||||
_blockstore->remove(key);
|
||||
void DataNodeStore::remove(const BlockId &blockId) {
|
||||
_blockstore->remove(blockId);
|
||||
}
|
||||
|
||||
void DataNodeStore::removeSubtree(unique_ref<DataNode> node) {
|
||||
@ -99,23 +99,23 @@ void DataNodeStore::removeSubtree(unique_ref<DataNode> node) {
|
||||
auto inner = dynamic_pointer_move<DataInnerNode>(node);
|
||||
ASSERT(inner != none, "Is neither a leaf nor an inner node");
|
||||
for (uint32_t i = 0; i < (*inner)->numChildren(); ++i) {
|
||||
removeSubtree((*inner)->depth()-1, (*inner)->getChild(i)->key());
|
||||
removeSubtree((*inner)->depth()-1, (*inner)->getChild(i)->blockId());
|
||||
}
|
||||
remove(std::move(*inner));
|
||||
}
|
||||
|
||||
void DataNodeStore::removeSubtree(uint8_t depth, const Key &key) {
|
||||
void DataNodeStore::removeSubtree(uint8_t depth, const BlockId &blockId) {
|
||||
if (depth == 0) {
|
||||
remove(key);
|
||||
remove(blockId);
|
||||
} else {
|
||||
auto node = load(key);
|
||||
auto node = load(blockId);
|
||||
ASSERT(node != none, "Node for removeSubtree not found");
|
||||
|
||||
auto inner = dynamic_pointer_move<DataInnerNode>(*node);
|
||||
ASSERT(inner != none, "Is not an inner node, but depth was not zero");
|
||||
ASSERT((*inner)->depth() == depth, "Wrong depth given");
|
||||
for (uint32_t i = 0; i < (*inner)->numChildren(); ++i) {
|
||||
removeSubtree(depth-1, (*inner)->getChild(i)->key());
|
||||
removeSubtree(depth-1, (*inner)->getChild(i)->blockId());
|
||||
}
|
||||
remove(std::move(*inner));
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <memory>
|
||||
#include <cpp-utils/macros.h>
|
||||
#include "DataNodeView.h"
|
||||
#include <blockstore/utils/Key.h>
|
||||
#include <blockstore/utils/BlockId.h>
|
||||
|
||||
namespace blockstore{
|
||||
class Block;
|
||||
@ -28,21 +28,21 @@ public:
|
||||
|
||||
DataNodeLayout layout() const;
|
||||
|
||||
boost::optional<cpputils::unique_ref<DataNode>> load(const blockstore::Key &key);
|
||||
boost::optional<cpputils::unique_ref<DataNode>> load(const blockstore::BlockId &blockId);
|
||||
static cpputils::unique_ref<DataNode> load(cpputils::unique_ref<blockstore::Block> block);
|
||||
|
||||
cpputils::unique_ref<DataLeafNode> createNewLeafNode(cpputils::Data data);
|
||||
cpputils::unique_ref<DataInnerNode> createNewInnerNode(uint8_t depth, const std::vector<blockstore::Key> &children);
|
||||
cpputils::unique_ref<DataInnerNode> createNewInnerNode(uint8_t depth, const std::vector<blockstore::BlockId> &children);
|
||||
|
||||
cpputils::unique_ref<DataNode> createNewNodeAsCopyFrom(const DataNode &source);
|
||||
|
||||
cpputils::unique_ref<DataNode> overwriteNodeWith(cpputils::unique_ref<DataNode> target, const DataNode &source);
|
||||
|
||||
cpputils::unique_ref<DataLeafNode> overwriteLeaf(const blockstore::Key &key, cpputils::Data data);
|
||||
cpputils::unique_ref<DataLeafNode> overwriteLeaf(const blockstore::BlockId &blockId, cpputils::Data data);
|
||||
|
||||
void remove(cpputils::unique_ref<DataNode> node);
|
||||
void remove(const blockstore::Key &key);
|
||||
void removeSubtree(uint8_t depth, const blockstore::Key &key);
|
||||
void remove(const blockstore::BlockId &blockId);
|
||||
void removeSubtree(uint8_t depth, const blockstore::BlockId &blockId);
|
||||
void removeSubtree(cpputils::unique_ref<DataNode> node);
|
||||
|
||||
//TODO Test blocksizeBytes/numBlocks/estimateSpaceForNumBlocksLeft
|
||||
|
@ -81,10 +81,10 @@ public:
|
||||
return DataNodeView(std::move(block));
|
||||
}
|
||||
|
||||
static DataNodeView overwrite(blockstore::BlockStore *blockStore, const DataNodeLayout &layout, uint16_t formatVersion, uint8_t depth, uint32_t size, const blockstore::Key &key, cpputils::Data data) {
|
||||
static DataNodeView overwrite(blockstore::BlockStore *blockStore, const DataNodeLayout &layout, uint16_t formatVersion, uint8_t depth, uint32_t size, const blockstore::BlockId &blockId, cpputils::Data data) {
|
||||
ASSERT(data.size() <= layout.datasizeBytes(), "Data is too large for node");
|
||||
cpputils::Data serialized = _serialize(layout, formatVersion, depth, size, std::move(data));
|
||||
auto block = blockStore->overwrite(key, std::move(serialized));
|
||||
auto block = blockStore->overwrite(blockId, std::move(serialized));
|
||||
return DataNodeView(std::move(block));
|
||||
}
|
||||
|
||||
@ -145,8 +145,8 @@ public:
|
||||
return *_block;
|
||||
}
|
||||
|
||||
const blockstore::Key &key() const {
|
||||
return _block->key();
|
||||
const blockstore::BlockId &blockId() const {
|
||||
return _block->blockId();
|
||||
}
|
||||
|
||||
void flush() const {
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include <cpp-utils/assert/assert.h>
|
||||
#include "impl/LeafTraverser.h"
|
||||
|
||||
using blockstore::Key;
|
||||
using blockstore::BlockId;
|
||||
using blobstore::onblocks::datanodestore::DataNodeStore;
|
||||
using blobstore::onblocks::datanodestore::DataNode;
|
||||
using blobstore::onblocks::datanodestore::DataInnerNode;
|
||||
@ -40,14 +40,14 @@ namespace onblocks {
|
||||
namespace datatreestore {
|
||||
|
||||
DataTree::DataTree(DataNodeStore *nodeStore, unique_ref<DataNode> rootNode)
|
||||
: _mutex(), _nodeStore(nodeStore), _rootNode(std::move(rootNode)), _key(_rootNode->key()), _numLeavesCache(none) {
|
||||
: _mutex(), _nodeStore(nodeStore), _rootNode(std::move(rootNode)), _blockId(_rootNode->blockId()), _numLeavesCache(none) {
|
||||
}
|
||||
|
||||
DataTree::~DataTree() {
|
||||
}
|
||||
|
||||
const Key &DataTree::key() const {
|
||||
return _key;
|
||||
const BlockId &DataTree::blockId() const {
|
||||
return _blockId;
|
||||
}
|
||||
|
||||
void DataTree::flush() const {
|
||||
@ -89,7 +89,7 @@ uint32_t DataTree::_computeNumLeaves(const DataNode &node) const {
|
||||
|
||||
const DataInnerNode &inner = dynamic_cast<const DataInnerNode&>(node);
|
||||
uint64_t numLeavesInLeftChildren = (uint64_t)(inner.numChildren()-1) * leavesPerFullChild(inner);
|
||||
auto lastChild = _nodeStore->load(inner.LastChild()->key());
|
||||
auto lastChild = _nodeStore->load(inner.LastChild()->blockId());
|
||||
ASSERT(lastChild != none, "Couldn't load last child");
|
||||
uint64_t numLeavesInRightChild = _computeNumLeaves(**lastChild);
|
||||
|
||||
@ -138,7 +138,7 @@ uint64_t DataTree::_numStoredBytes(const DataNode &root) const {
|
||||
|
||||
const DataInnerNode &inner = dynamic_cast<const DataInnerNode&>(root);
|
||||
uint64_t numBytesInLeftChildren = (inner.numChildren()-1) * leavesPerFullChild(inner) * _nodeStore->layout().maxBytesPerLeaf();
|
||||
auto lastChild = _nodeStore->load(inner.LastChild()->key());
|
||||
auto lastChild = _nodeStore->load(inner.LastChild()->blockId());
|
||||
ASSERT(lastChild != none, "Couldn't load last child");
|
||||
uint64_t numBytesInRightChild = _numStoredBytes(**lastChild);
|
||||
|
||||
@ -172,7 +172,7 @@ void DataTree::resizeNumBytes(uint64_t newNumBytes) {
|
||||
ASSERT(neededChildrenForRightBorderNode <= node->numChildren(), "Node has too few children");
|
||||
// All children to the right of the new right-border-node are removed including their subtree.
|
||||
while(node->numChildren() > neededChildrenForRightBorderNode) {
|
||||
_nodeStore->removeSubtree(node->depth()-1, node->LastChild()->key());
|
||||
_nodeStore->removeSubtree(node->depth()-1, node->LastChild()->blockId());
|
||||
node->removeLastChild();
|
||||
}
|
||||
};
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include "../datanodestore/DataNodeView.h"
|
||||
//TODO Replace with C++14 once std::shared_mutex is supported
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
#include <blockstore/utils/Key.h>
|
||||
#include <blockstore/utils/BlockId.h>
|
||||
#include "LeafHandle.h"
|
||||
|
||||
namespace blobstore {
|
||||
@ -27,7 +27,7 @@ public:
|
||||
DataTree(datanodestore::DataNodeStore *nodeStore, cpputils::unique_ref<datanodestore::DataNode> rootNode);
|
||||
~DataTree();
|
||||
|
||||
const blockstore::Key &key() const;
|
||||
const blockstore::BlockId &blockId() const;
|
||||
//Returning uint64_t, because calculations handling this probably need to be done in 64bit to support >4GB blobs.
|
||||
uint64_t maxBytesPerLeaf() const;
|
||||
|
||||
@ -48,7 +48,7 @@ private:
|
||||
mutable boost::shared_mutex _mutex;
|
||||
datanodestore::DataNodeStore *_nodeStore;
|
||||
cpputils::unique_ref<datanodestore::DataNode> _rootNode;
|
||||
blockstore::Key _key; // Key is stored in a member variable, since _rootNode is nullptr while traversing, but we still want to be able to return the key.
|
||||
blockstore::BlockId _blockId; // BlockId is stored in a member variable, since _rootNode is nullptr while traversing, but we still want to be able to return the blockId.
|
||||
mutable boost::optional<uint32_t> _numLeavesCache;
|
||||
|
||||
cpputils::unique_ref<datanodestore::DataNode> releaseRootNode();
|
||||
|
@ -22,8 +22,8 @@ DataTreeStore::DataTreeStore(unique_ref<DataNodeStore> nodeStore)
|
||||
DataTreeStore::~DataTreeStore() {
|
||||
}
|
||||
|
||||
optional<unique_ref<DataTree>> DataTreeStore::load(const blockstore::Key &key) {
|
||||
auto node = _nodeStore->load(key);
|
||||
optional<unique_ref<DataTree>> DataTreeStore::load(const blockstore::BlockId &blockId) {
|
||||
auto node = _nodeStore->load(blockId);
|
||||
if (node == none) {
|
||||
return none;
|
||||
}
|
||||
@ -39,8 +39,8 @@ void DataTreeStore::remove(unique_ref<DataTree> tree) {
|
||||
_nodeStore->removeSubtree(tree->releaseRootNode());
|
||||
}
|
||||
|
||||
void DataTreeStore::remove(const blockstore::Key &key) {
|
||||
auto tree = load(key);
|
||||
void DataTreeStore::remove(const blockstore::BlockId &blockId) {
|
||||
auto tree = load(blockId);
|
||||
ASSERT(tree != none, "Tree to remove not found");
|
||||
remove(std::move(*tree));
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <memory>
|
||||
#include <cpp-utils/macros.h>
|
||||
#include <cpp-utils/pointer/unique_ref.h>
|
||||
#include <blockstore/utils/Key.h>
|
||||
#include <blockstore/utils/BlockId.h>
|
||||
#include <boost/optional.hpp>
|
||||
#include "../datanodestore/DataNodeStore.h"
|
||||
|
||||
@ -19,12 +19,12 @@ public:
|
||||
DataTreeStore(cpputils::unique_ref<datanodestore::DataNodeStore> nodeStore);
|
||||
~DataTreeStore();
|
||||
|
||||
boost::optional<cpputils::unique_ref<DataTree>> load(const blockstore::Key &key);
|
||||
boost::optional<cpputils::unique_ref<DataTree>> load(const blockstore::BlockId &blockId);
|
||||
|
||||
cpputils::unique_ref<DataTree> createNewTree();
|
||||
|
||||
void remove(cpputils::unique_ref<DataTree> tree);
|
||||
void remove(const blockstore::Key &key);
|
||||
void remove(const blockstore::BlockId &blockId);
|
||||
|
||||
//TODO Test blocksizeBytes/numBlocks/estimateSpaceForNumBlocksLeft
|
||||
uint64_t virtualBlocksizeBytes() const;
|
||||
|
@ -8,24 +8,24 @@ using boost::none;
|
||||
using cpputils::dynamic_pointer_move;
|
||||
using blobstore::onblocks::datanodestore::DataLeafNode;
|
||||
using blobstore::onblocks::datanodestore::DataNodeStore;
|
||||
using blockstore::Key;
|
||||
using blockstore::BlockId;
|
||||
|
||||
namespace blobstore {
|
||||
namespace onblocks {
|
||||
namespace datatreestore {
|
||||
|
||||
LeafHandle::LeafHandle(DataNodeStore *nodeStore, const Key &key)
|
||||
: _nodeStore(nodeStore), _key(key), _leaf(cpputils::null<DataLeafNode>()) {
|
||||
LeafHandle::LeafHandle(DataNodeStore *nodeStore, const BlockId &blockId)
|
||||
: _nodeStore(nodeStore), _blockId(blockId), _leaf(cpputils::null<DataLeafNode>()) {
|
||||
}
|
||||
|
||||
LeafHandle::LeafHandle(DataNodeStore *nodeStore, DataLeafNode *node)
|
||||
: _nodeStore(nodeStore), _key(node->key()),
|
||||
: _nodeStore(nodeStore), _blockId(node->blockId()),
|
||||
_leaf(WithoutOwnership<DataLeafNode>(node)) {
|
||||
}
|
||||
|
||||
DataLeafNode *LeafHandle::node() {
|
||||
if (_leaf.get() == nullptr) {
|
||||
auto loaded = _nodeStore->load(_key);
|
||||
auto loaded = _nodeStore->load(_blockId);
|
||||
ASSERT(loaded != none, "Leaf not found");
|
||||
auto leaf = dynamic_pointer_move<DataLeafNode>(*loaded);
|
||||
ASSERT(leaf != none, "Loaded leaf is not leaf node");
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#include <cpp-utils/macros.h>
|
||||
#include <cpp-utils/pointer/optional_ownership_ptr.h>
|
||||
#include <blockstore/utils/Key.h>
|
||||
#include <blockstore/utils/BlockId.h>
|
||||
|
||||
namespace blobstore {
|
||||
namespace onblocks {
|
||||
@ -16,12 +16,12 @@ namespace blobstore {
|
||||
|
||||
class LeafHandle final {
|
||||
public:
|
||||
LeafHandle(datanodestore::DataNodeStore *nodeStore, const blockstore::Key &key);
|
||||
LeafHandle(datanodestore::DataNodeStore *nodeStore, const blockstore::BlockId &blockId);
|
||||
LeafHandle(datanodestore::DataNodeStore *nodeStore, datanodestore::DataLeafNode *node);
|
||||
LeafHandle(LeafHandle &&rhs) = default;
|
||||
|
||||
const blockstore::Key &key() {
|
||||
return _key;
|
||||
const blockstore::BlockId &blockId() {
|
||||
return _blockId;
|
||||
}
|
||||
|
||||
datanodestore::DataLeafNode *node();
|
||||
@ -32,7 +32,7 @@ namespace blobstore {
|
||||
|
||||
private:
|
||||
datanodestore::DataNodeStore *_nodeStore;
|
||||
blockstore::Key _key;
|
||||
blockstore::BlockId _blockId;
|
||||
cpputils::optional_ownership_ptr<datanodestore::DataLeafNode> _leaf;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(LeafHandle);
|
||||
|
@ -78,11 +78,11 @@ namespace blobstore {
|
||||
return DataNode::convertToNewInnerNode(std::move(root), _nodeStore->layout(), *copyOfOldRoot);
|
||||
}
|
||||
|
||||
void LeafTraverser::_traverseExistingSubtree(const blockstore::Key &key, uint8_t depth, uint32_t beginIndex, uint32_t endIndex, uint32_t leafOffset, bool isLeftBorderOfTraversal, bool isRightBorderNode, bool growLastLeaf, function<void (uint32_t index, bool isRightBorderLeaf, LeafHandle leaf)> onExistingLeaf, function<Data (uint32_t index)> onCreateLeaf, function<void (DataInnerNode *node)> onBacktrackFromSubtree) {
|
||||
void LeafTraverser::_traverseExistingSubtree(const blockstore::BlockId &blockId, uint8_t depth, uint32_t beginIndex, uint32_t endIndex, uint32_t leafOffset, bool isLeftBorderOfTraversal, bool isRightBorderNode, bool growLastLeaf, function<void (uint32_t index, bool isRightBorderLeaf, LeafHandle leaf)> onExistingLeaf, function<Data (uint32_t index)> onCreateLeaf, function<void (DataInnerNode *node)> onBacktrackFromSubtree) {
|
||||
if (depth == 0) {
|
||||
ASSERT(beginIndex <= 1 && endIndex <= 1,
|
||||
"If root node is a leaf, the (sub)tree has only one leaf - access indices must be 0 or 1.");
|
||||
LeafHandle leafHandle(_nodeStore, key);
|
||||
LeafHandle leafHandle(_nodeStore, blockId);
|
||||
if (growLastLeaf) {
|
||||
if (leafHandle.node()->numBytes() != _nodeStore->layout().maxBytesPerLeaf()) {
|
||||
leafHandle.node()->resize(_nodeStore->layout().maxBytesPerLeaf());
|
||||
@ -92,9 +92,9 @@ namespace blobstore {
|
||||
onExistingLeaf(leafOffset, isRightBorderNode, std::move(leafHandle));
|
||||
}
|
||||
} else {
|
||||
auto node = _nodeStore->load(key);
|
||||
auto node = _nodeStore->load(blockId);
|
||||
if (node == none) {
|
||||
throw std::runtime_error("Couldn't find child node " + key.ToString());
|
||||
throw std::runtime_error("Couldn't find child node " + blockId.ToString());
|
||||
}
|
||||
|
||||
auto inner = dynamic_pointer_move<DataInnerNode>(*node);
|
||||
@ -122,9 +122,9 @@ namespace blobstore {
|
||||
// we still have to descend to the last old child to fill it with leaves and grow the last old leaf.
|
||||
if (isLeftBorderOfTraversal && beginChild >= numChildren) {
|
||||
ASSERT(numChildren > 0, "Node doesn't have children.");
|
||||
auto childKey = root->getChild(numChildren-1)->key();
|
||||
auto childBlockId = root->getChild(numChildren-1)->blockId();
|
||||
uint32_t childOffset = (numChildren-1) * leavesPerChild;
|
||||
_traverseExistingSubtree(childKey, root->depth()-1, leavesPerChild, leavesPerChild, childOffset, true, false, true,
|
||||
_traverseExistingSubtree(childBlockId, root->depth()-1, leavesPerChild, leavesPerChild, childOffset, true, false, true,
|
||||
[] (uint32_t /*index*/, bool /*isRightBorderNode*/, LeafHandle /*leaf*/) {ASSERT(false, "We don't actually traverse any leaves.");},
|
||||
[] (uint32_t /*index*/) -> Data {ASSERT(false, "We don't actually traverse any leaves.");},
|
||||
[] (DataInnerNode* /*node*/) {ASSERT(false, "We don't actually traverse any leaves.");});
|
||||
@ -132,7 +132,7 @@ namespace blobstore {
|
||||
|
||||
// Traverse existing children
|
||||
for (uint32_t childIndex = beginChild; childIndex < std::min(endChild, numChildren); ++childIndex) {
|
||||
auto childKey = root->getChild(childIndex)->key();
|
||||
auto childBlockId = root->getChild(childIndex)->blockId();
|
||||
uint32_t childOffset = childIndex * leavesPerChild;
|
||||
uint32_t localBeginIndex = utils::maxZeroSubtraction(beginIndex, childOffset);
|
||||
uint32_t localEndIndex = std::min(leavesPerChild, endIndex - childOffset);
|
||||
@ -140,7 +140,7 @@ namespace blobstore {
|
||||
bool isLastExistingChild = (childIndex == numChildren - 1);
|
||||
bool isLastChild = isLastExistingChild && (numChildren == endChild);
|
||||
ASSERT(localEndIndex <= leavesPerChild, "We don't want the child to add a tree level because it doesn't have enough space for the traversal.");
|
||||
_traverseExistingSubtree(childKey, root->depth()-1, localBeginIndex, localEndIndex, leafOffset + childOffset, isLeftBorderOfTraversal && isFirstChild,
|
||||
_traverseExistingSubtree(childBlockId, root->depth()-1, localBeginIndex, localEndIndex, leafOffset + childOffset, isLeftBorderOfTraversal && isFirstChild,
|
||||
isRightBorderNode && isLastChild, shouldGrowLastExistingLeaf && isLastExistingChild, onExistingLeaf, onCreateLeaf, onBacktrackFromSubtree);
|
||||
}
|
||||
|
||||
@ -175,7 +175,7 @@ namespace blobstore {
|
||||
uint32_t beginChild = beginIndex/leavesPerChild;
|
||||
uint32_t endChild = utils::ceilDivision(endIndex, leavesPerChild);
|
||||
|
||||
vector<blockstore::Key> children;
|
||||
vector<blockstore::BlockId> children;
|
||||
children.reserve(endChild);
|
||||
// TODO Remove redundancy of following two for loops by using min/max for calculating the parameters of the recursive call.
|
||||
// Create gap children (i.e. children before the traversal but after the current size)
|
||||
@ -185,7 +185,7 @@ namespace blobstore {
|
||||
[] (uint32_t /*index*/)->Data {ASSERT(false, "We're only creating gap leaves here, not traversing any.");},
|
||||
[] (DataInnerNode* /*node*/) {});
|
||||
ASSERT(child->depth() == depth-1, "Created child node has wrong depth");
|
||||
children.push_back(child->key());
|
||||
children.push_back(child->blockId());
|
||||
}
|
||||
// Create new children that are traversed
|
||||
for(uint32_t childIndex = beginChild; childIndex < endChild; ++childIndex) {
|
||||
@ -194,7 +194,7 @@ namespace blobstore {
|
||||
uint32_t localEndIndex = std::min(leavesPerChild, endIndex - childOffset);
|
||||
auto child = _createNewSubtree(localBeginIndex, localEndIndex, leafOffset + childOffset, depth - 1, onCreateLeaf, onBacktrackFromSubtree);
|
||||
ASSERT(child->depth() == depth-1, "Created child node has wrong depth");
|
||||
children.push_back(child->key());
|
||||
children.push_back(child->blockId());
|
||||
}
|
||||
|
||||
ASSERT(children.size() > 0, "No children created");
|
||||
@ -221,7 +221,7 @@ namespace blobstore {
|
||||
unique_ref<DataNode> LeafTraverser::_whileRootHasOnlyOneChildReplaceRootWithItsChild(unique_ref<DataNode> root) {
|
||||
DataInnerNode *inner = dynamic_cast<DataInnerNode*>(root.get());
|
||||
if (inner != nullptr && inner->numChildren() == 1) {
|
||||
auto newRoot = _whileRootHasOnlyOneChildRemoveRootReturnChild(inner->getChild(0)->key());
|
||||
auto newRoot = _whileRootHasOnlyOneChildRemoveRootReturnChild(inner->getChild(0)->blockId());
|
||||
auto result = _nodeStore->overwriteNodeWith(std::move(root), *newRoot);
|
||||
_nodeStore->remove(std::move(newRoot));
|
||||
return result;
|
||||
@ -230,14 +230,14 @@ namespace blobstore {
|
||||
}
|
||||
}
|
||||
|
||||
unique_ref<DataNode> LeafTraverser::_whileRootHasOnlyOneChildRemoveRootReturnChild(const blockstore::Key &key) {
|
||||
auto current = _nodeStore->load(key);
|
||||
unique_ref<DataNode> LeafTraverser::_whileRootHasOnlyOneChildRemoveRootReturnChild(const blockstore::BlockId &blockId) {
|
||||
auto current = _nodeStore->load(blockId);
|
||||
ASSERT(current != none, "Node not found");
|
||||
auto inner = dynamic_pointer_move<DataInnerNode>(*current);
|
||||
if (inner == none) {
|
||||
return std::move(*current);
|
||||
} else if ((*inner)->numChildren() == 1) {
|
||||
auto result = _whileRootHasOnlyOneChildRemoveRootReturnChild((*inner)->getChild(0)->key());
|
||||
auto result = _whileRootHasOnlyOneChildRemoveRootReturnChild((*inner)->getChild(0)->blockId());
|
||||
_nodeStore->remove(std::move(*inner));
|
||||
return result;
|
||||
} else {
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <cpp-utils/macros.h>
|
||||
#include <cpp-utils/pointer/unique_ref.h>
|
||||
#include <cpp-utils/data/Data.h>
|
||||
#include <blockstore/utils/Key.h>
|
||||
#include <blockstore/utils/BlockId.h>
|
||||
#include "blobstore/implementations/onblocks/datatreestore/LeafHandle.h"
|
||||
|
||||
namespace blobstore {
|
||||
@ -45,7 +45,7 @@ namespace blobstore {
|
||||
std::function<void (uint32_t index, bool isRightBorderLeaf, LeafHandle leaf)> onExistingLeaf,
|
||||
std::function<cpputils::Data (uint32_t index)> onCreateLeaf,
|
||||
std::function<void (datanodestore::DataInnerNode *node)> onBacktrackFromSubtree);
|
||||
void _traverseExistingSubtree(const blockstore::Key &key, uint8_t depth, uint32_t beginIndex, uint32_t endIndex, uint32_t leafOffset, bool isLeftBorderOfTraversal, bool isRightBorderNode, bool growLastLeaf,
|
||||
void _traverseExistingSubtree(const blockstore::BlockId &blockId, uint8_t depth, uint32_t beginIndex, uint32_t endIndex, uint32_t leafOffset, bool isLeftBorderOfTraversal, bool isRightBorderNode, bool growLastLeaf,
|
||||
std::function<void (uint32_t index, bool isRightBorderLeaf, LeafHandle leaf)> onExistingLeaf,
|
||||
std::function<cpputils::Data (uint32_t index)> onCreateLeaf,
|
||||
std::function<void (datanodestore::DataInnerNode *node)> onBacktrackFromSubtree);
|
||||
@ -56,7 +56,7 @@ namespace blobstore {
|
||||
uint32_t _maxLeavesForTreeDepth(uint8_t depth) const;
|
||||
std::function<cpputils::Data (uint32_t index)> _createMaxSizeLeaf() const;
|
||||
cpputils::unique_ref<datanodestore::DataNode> _whileRootHasOnlyOneChildReplaceRootWithItsChild(cpputils::unique_ref<datanodestore::DataNode> root);
|
||||
cpputils::unique_ref<datanodestore::DataNode> _whileRootHasOnlyOneChildRemoveRootReturnChild(const blockstore::Key &key);
|
||||
cpputils::unique_ref<datanodestore::DataNode> _whileRootHasOnlyOneChildRemoveRootReturnChild(const blockstore::BlockId &blockId);
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(LeafTraverser);
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "algorithms.h"
|
||||
#include <cpp-utils/pointer/cast.h>
|
||||
#include <blockstore/utils/Key.h>
|
||||
#include <blockstore/utils/BlockId.h>
|
||||
|
||||
#include "../../datanodestore/DataInnerNode.h"
|
||||
#include "../../datanodestore/DataNodeStore.h"
|
||||
@ -13,7 +13,7 @@ using cpputils::unique_ref;
|
||||
using blobstore::onblocks::datanodestore::DataInnerNode;
|
||||
using blobstore::onblocks::datanodestore::DataNode;
|
||||
using blobstore::onblocks::datanodestore::DataNodeStore;
|
||||
using blockstore::Key;
|
||||
using blockstore::BlockId;
|
||||
using boost::optional;
|
||||
using boost::none;
|
||||
|
||||
@ -23,8 +23,8 @@ namespace datatreestore {
|
||||
namespace algorithms {
|
||||
|
||||
optional<unique_ref<DataInnerNode>> getLastChildAsInnerNode(DataNodeStore *nodeStore, const DataInnerNode &node) {
|
||||
Key key = node.LastChild()->key();
|
||||
auto lastChild = nodeStore->load(key);
|
||||
BlockId blockId = node.LastChild()->blockId();
|
||||
auto lastChild = nodeStore->load(blockId);
|
||||
ASSERT(lastChild != none, "Couldn't load last child");
|
||||
return dynamic_pointer_move<DataInnerNode>(*lastChild);
|
||||
}
|
||||
|
@ -10,12 +10,12 @@ namespace blobstore {
|
||||
namespace onblocks {
|
||||
namespace parallelaccessdatatreestore {
|
||||
|
||||
class DataTreeRef final: public parallelaccessstore::ParallelAccessStore<datatreestore::DataTree, DataTreeRef, blockstore::Key>::ResourceRefBase {
|
||||
class DataTreeRef final: public parallelaccessstore::ParallelAccessStore<datatreestore::DataTree, DataTreeRef, blockstore::BlockId>::ResourceRefBase {
|
||||
public:
|
||||
DataTreeRef(datatreestore::DataTree *baseTree): _baseTree(baseTree) {}
|
||||
|
||||
const blockstore::Key &key() const {
|
||||
return _baseTree->key();
|
||||
const blockstore::BlockId &blockId() const {
|
||||
return _baseTree->blockId();
|
||||
}
|
||||
|
||||
uint64_t maxBytesPerLeaf() const {
|
||||
|
@ -9,7 +9,7 @@ using cpputils::make_unique_ref;
|
||||
using boost::optional;
|
||||
|
||||
using blobstore::onblocks::datatreestore::DataTreeStore;
|
||||
using blockstore::Key;
|
||||
using blockstore::BlockId;
|
||||
|
||||
namespace blobstore {
|
||||
namespace onblocks {
|
||||
@ -26,23 +26,23 @@ ParallelAccessDataTreeStore::ParallelAccessDataTreeStore(unique_ref<DataTreeStor
|
||||
ParallelAccessDataTreeStore::~ParallelAccessDataTreeStore() {
|
||||
}
|
||||
|
||||
optional<unique_ref<DataTreeRef>> ParallelAccessDataTreeStore::load(const blockstore::Key &key) {
|
||||
return _parallelAccessStore.load(key);
|
||||
optional<unique_ref<DataTreeRef>> ParallelAccessDataTreeStore::load(const blockstore::BlockId &blockId) {
|
||||
return _parallelAccessStore.load(blockId);
|
||||
}
|
||||
|
||||
unique_ref<DataTreeRef> ParallelAccessDataTreeStore::createNewTree() {
|
||||
auto dataTree = _dataTreeStore->createNewTree();
|
||||
Key key = dataTree->key();
|
||||
return _parallelAccessStore.add(key, std::move(dataTree));
|
||||
BlockId blockId = dataTree->blockId();
|
||||
return _parallelAccessStore.add(blockId, std::move(dataTree));
|
||||
}
|
||||
|
||||
void ParallelAccessDataTreeStore::remove(unique_ref<DataTreeRef> tree) {
|
||||
Key key = tree->key();
|
||||
return _parallelAccessStore.remove(key, std::move(tree));
|
||||
BlockId blockId = tree->blockId();
|
||||
return _parallelAccessStore.remove(blockId, std::move(tree));
|
||||
}
|
||||
|
||||
void ParallelAccessDataTreeStore::remove(const Key &key) {
|
||||
return _parallelAccessStore.remove(key);
|
||||
void ParallelAccessDataTreeStore::remove(const BlockId &blockId) {
|
||||
return _parallelAccessStore.remove(blockId);
|
||||
}
|
||||
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <cpp-utils/macros.h>
|
||||
#include <blockstore/utils/Key.h>
|
||||
#include <blockstore/utils/BlockId.h>
|
||||
#include <parallelaccessstore/ParallelAccessStore.h>
|
||||
#include "../datatreestore/DataTreeStore.h"
|
||||
|
||||
@ -20,12 +20,12 @@ public:
|
||||
ParallelAccessDataTreeStore(cpputils::unique_ref<datatreestore::DataTreeStore> dataTreeStore);
|
||||
~ParallelAccessDataTreeStore();
|
||||
|
||||
boost::optional<cpputils::unique_ref<DataTreeRef>> load(const blockstore::Key &key);
|
||||
boost::optional<cpputils::unique_ref<DataTreeRef>> load(const blockstore::BlockId &blockId);
|
||||
|
||||
cpputils::unique_ref<DataTreeRef> createNewTree();
|
||||
|
||||
void remove(cpputils::unique_ref<DataTreeRef> tree);
|
||||
void remove(const blockstore::Key &key);
|
||||
void remove(const blockstore::BlockId &blockId);
|
||||
|
||||
//TODO Test blocksizeBytes/numBlocks/estimateSpaceForNumBlocksLeft
|
||||
uint64_t virtualBlocksizeBytes() const;
|
||||
@ -34,7 +34,7 @@ public:
|
||||
|
||||
private:
|
||||
cpputils::unique_ref<datatreestore::DataTreeStore> _dataTreeStore;
|
||||
parallelaccessstore::ParallelAccessStore<datatreestore::DataTree, DataTreeRef, blockstore::Key> _parallelAccessStore;
|
||||
parallelaccessstore::ParallelAccessStore<datatreestore::DataTree, DataTreeRef, blockstore::BlockId> _parallelAccessStore;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ParallelAccessDataTreeStore);
|
||||
};
|
||||
|
@ -11,22 +11,22 @@ namespace blobstore {
|
||||
namespace onblocks {
|
||||
namespace parallelaccessdatatreestore {
|
||||
|
||||
class ParallelAccessDataTreeStoreAdapter final: public parallelaccessstore::ParallelAccessBaseStore<datatreestore::DataTree, blockstore::Key> {
|
||||
class ParallelAccessDataTreeStoreAdapter final: public parallelaccessstore::ParallelAccessBaseStore<datatreestore::DataTree, blockstore::BlockId> {
|
||||
public:
|
||||
ParallelAccessDataTreeStoreAdapter(datatreestore::DataTreeStore *baseDataTreeStore)
|
||||
:_baseDataTreeStore(std::move(baseDataTreeStore)) {
|
||||
}
|
||||
|
||||
boost::optional<cpputils::unique_ref<datatreestore::DataTree>> loadFromBaseStore(const blockstore::Key &key) override {
|
||||
return _baseDataTreeStore->load(key);
|
||||
boost::optional<cpputils::unique_ref<datatreestore::DataTree>> loadFromBaseStore(const blockstore::BlockId &blockId) override {
|
||||
return _baseDataTreeStore->load(blockId);
|
||||
}
|
||||
|
||||
void removeFromBaseStore(cpputils::unique_ref<datatreestore::DataTree> dataTree) override {
|
||||
return _baseDataTreeStore->remove(std::move(dataTree));
|
||||
}
|
||||
|
||||
void removeFromBaseStore(const blockstore::Key &key) override {
|
||||
return _baseDataTreeStore->remove(key);
|
||||
void removeFromBaseStore(const blockstore::BlockId &blockId) override {
|
||||
return _baseDataTreeStore->remove(blockId);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <cstdint>
|
||||
#include <blockstore/utils/Key.h>
|
||||
#include <blockstore/utils/BlockId.h>
|
||||
#include <cpp-utils/data/Data.h>
|
||||
|
||||
namespace blobstore {
|
||||
@ -13,8 +13,8 @@ class Blob {
|
||||
public:
|
||||
virtual ~Blob() {}
|
||||
|
||||
//TODO Use own Key class for blobstore
|
||||
virtual const blockstore::Key &key() const = 0;
|
||||
//TODO Use own Id class for blobstore
|
||||
virtual const blockstore::BlockId &blockId() const = 0;
|
||||
|
||||
virtual uint64_t size() const = 0;
|
||||
virtual void resize(uint64_t numBytes) = 0;
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
#include <blockstore/utils/Key.h>
|
||||
#include <blockstore/utils/BlockId.h>
|
||||
#include <cpp-utils/pointer/unique_ref.h>
|
||||
|
||||
namespace blobstore {
|
||||
@ -17,9 +17,9 @@ public:
|
||||
virtual ~BlobStore() {}
|
||||
|
||||
virtual cpputils::unique_ref<Blob> create() = 0;
|
||||
virtual boost::optional<cpputils::unique_ref<Blob>> load(const blockstore::Key &key) = 0;
|
||||
virtual boost::optional<cpputils::unique_ref<Blob>> load(const blockstore::BlockId &blockId) = 0;
|
||||
virtual void remove(cpputils::unique_ref<Blob> blob) = 0;
|
||||
virtual void remove(const blockstore::Key &key) = 0;
|
||||
virtual void remove(const blockstore::BlockId &blockId) = 0;
|
||||
|
||||
virtual uint64_t numBlocks() const = 0;
|
||||
virtual uint64_t estimateSpaceForNumBlocksLeft() const = 0;
|
||||
|
@ -1,7 +1,7 @@
|
||||
project (blockstore)
|
||||
|
||||
set(SOURCES
|
||||
utils/Key.cpp
|
||||
utils/BlockId.cpp
|
||||
utils/IdWrapper.cpp
|
||||
utils/BlockStoreUtils.cpp
|
||||
utils/FileDoesntExistException.cpp
|
||||
@ -27,7 +27,7 @@ set(SOURCES
|
||||
implementations/low2highlevel/LowToHighLevelBlockStore.cpp
|
||||
implementations/integrity/IntegrityBlockStore2.cpp
|
||||
implementations/integrity/KnownBlockVersions.cpp
|
||||
implementations/integrity/ClientIdAndBlockKey.cpp
|
||||
implementations/integrity/ClientIdAndBlockId.cpp
|
||||
implementations/integrity/IntegrityViolationError.cpp
|
||||
implementations/mock/MockBlockStore.cpp
|
||||
implementations/mock/MockBlock.cpp
|
||||
|
@ -22,17 +22,17 @@ using std::mutex;
|
||||