Adapt to new blockstore (Blockstore::tryCreate returns optional<unique_ref<Block>> instead of unique_ptr<Block>)
This commit is contained in:
parent
5ea654445c
commit
7fc4115129
@ -20,7 +20,7 @@ DataInnerNode::DataInnerNode(DataNodeView view)
|
||||
DataInnerNode::~DataInnerNode() {
|
||||
}
|
||||
|
||||
unique_ref<DataInnerNode> DataInnerNode::InitializeNewNode(unique_ptr<Block> block, const DataNode &first_child) {
|
||||
unique_ref<DataInnerNode> DataInnerNode::InitializeNewNode(unique_ref<Block> block, const DataNode &first_child) {
|
||||
DataNodeView node(std::move(block));
|
||||
node.setDepth(first_child.depth() + 1);
|
||||
node.setSize(1);
|
||||
|
@ -11,7 +11,7 @@ namespace datanodestore {
|
||||
|
||||
class DataInnerNode: public DataNode {
|
||||
public:
|
||||
static cpputils::unique_ref<DataInnerNode> InitializeNewNode(std::unique_ptr<blockstore::Block> block, const DataNode &first_child_key);
|
||||
static cpputils::unique_ref<DataInnerNode> InitializeNewNode(cpputils::unique_ref<blockstore::Block> block, const DataNode &first_child_key);
|
||||
|
||||
DataInnerNode(DataNodeView block);
|
||||
virtual ~DataInnerNode();
|
||||
|
@ -21,7 +21,7 @@ DataLeafNode::DataLeafNode(DataNodeView view)
|
||||
DataLeafNode::~DataLeafNode() {
|
||||
}
|
||||
|
||||
unique_ref<DataLeafNode> DataLeafNode::InitializeNewNode(unique_ptr<Block> block) {
|
||||
unique_ref<DataLeafNode> DataLeafNode::InitializeNewNode(unique_ref<Block> block) {
|
||||
DataNodeView node(std::move(block));
|
||||
node.setDepth(0);
|
||||
node.setSize(0);
|
||||
|
@ -11,7 +11,7 @@ class DataInnerNode;
|
||||
|
||||
class DataLeafNode: public DataNode {
|
||||
public:
|
||||
static cpputils::unique_ref<DataLeafNode> InitializeNewNode(std::unique_ptr<blockstore::Block> block);
|
||||
static cpputils::unique_ref<DataLeafNode> InitializeNewNode(cpputils::unique_ref<blockstore::Block> block);
|
||||
|
||||
DataLeafNode(DataNodeView block);
|
||||
virtual ~DataLeafNode();
|
||||
|
@ -30,7 +30,8 @@ DataNodeStore::~DataNodeStore() {
|
||||
|
||||
unique_ref<DataNode> DataNodeStore::load(unique_ptr<Block> block) {
|
||||
assert(block->size() == _layout.blocksizeBytes());
|
||||
DataNodeView node(std::move(block));
|
||||
//TODO Don't use cpputils::nullcheck, but make the parameter a unique_ref
|
||||
DataNodeView node(cpputils::nullcheck(std::move(block)).value());
|
||||
|
||||
if (node.Depth() == 0) {
|
||||
return make_unique_ref<DataLeafNode>(std::move(node));
|
||||
@ -65,7 +66,8 @@ optional<unique_ref<DataNode>> DataNodeStore::load(const Key &key) {
|
||||
unique_ref<DataNode> DataNodeStore::createNewNodeAsCopyFrom(const DataNode &source) {
|
||||
assert(source.node().layout().blocksizeBytes() == _layout.blocksizeBytes()); // This might be violated if source is from a different DataNodeStore
|
||||
auto newBlock = blockstore::utils::copyToNewBlock(_blockstore.get(), source.node().block());
|
||||
return load(std::move(newBlock));
|
||||
//TODO Don't use to_unique_ptr
|
||||
return load(cpputils::to_unique_ptr(std::move(newBlock)));
|
||||
}
|
||||
|
||||
unique_ref<DataNode> DataNodeStore::overwriteNodeWith(unique_ref<DataNode> target, const DataNode &source) {
|
||||
@ -85,7 +87,8 @@ unique_ref<DataNode> DataNodeStore::overwriteNodeWith(unique_ref<DataNode> targe
|
||||
void DataNodeStore::remove(unique_ref<DataNode> node) {
|
||||
auto block = node->node().releaseBlock();
|
||||
cpputils::to_unique_ptr(std::move(node)).reset(); // Call destructor
|
||||
_blockstore->remove(std::move(block));
|
||||
//TODO Don't use to_unique_ptr
|
||||
_blockstore->remove(cpputils::to_unique_ptr(std::move(block)));
|
||||
}
|
||||
|
||||
uint64_t DataNodeStore::numNodes() const {
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include "../BlobStoreOnBlocks.h"
|
||||
#include "DataInnerNode_ChildEntry.h"
|
||||
|
||||
#include "messmer/cpp-utils/macros.h"
|
||||
#include <messmer/cpp-utils/pointer/unique_ref.h>
|
||||
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
@ -59,7 +59,7 @@ private:
|
||||
|
||||
class DataNodeView {
|
||||
public:
|
||||
DataNodeView(std::unique_ptr<blockstore::Block> block): _block(std::move(block)) {
|
||||
DataNodeView(cpputils::unique_ref<blockstore::Block> block): _block(std::move(block)) {
|
||||
}
|
||||
virtual ~DataNodeView() {}
|
||||
|
||||
@ -104,7 +104,7 @@ public:
|
||||
return DataNodeLayout(_block->size());
|
||||
}
|
||||
|
||||
std::unique_ptr<blockstore::Block> releaseBlock() {
|
||||
cpputils::unique_ref<blockstore::Block> releaseBlock() {
|
||||
return std::move(_block);
|
||||
}
|
||||
|
||||
@ -126,7 +126,7 @@ private:
|
||||
return (Type*)(((const int8_t*)_block->data())+offset);
|
||||
}
|
||||
|
||||
std::unique_ptr<blockstore::Block> _block;
|
||||
cpputils::unique_ref<blockstore::Block> _block;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(DataNodeView);
|
||||
|
||||
|
@ -135,7 +135,8 @@ TEST_F(DataInnerNodeTest, InitializesCorrectly) {
|
||||
|
||||
TEST_F(DataInnerNodeTest, ReinitializesCorrectly) {
|
||||
auto key = InitializeInnerNodeAddLeafReturnKey();
|
||||
auto node = DataInnerNode::InitializeNewNode(blockStore->load(key), *leaf);
|
||||
//TODO Don't use cpputils::nullcheck
|
||||
auto node = DataInnerNode::InitializeNewNode(cpputils::nullcheck(blockStore->load(key)).value(), *leaf);
|
||||
|
||||
EXPECT_EQ(1u, node->numChildren());
|
||||
EXPECT_EQ(leaf->key(), node->getChild(0)->key());
|
||||
|
@ -140,7 +140,8 @@ TEST_F(DataLeafNodeTest, InitializesCorrectly) {
|
||||
|
||||
TEST_F(DataLeafNodeTest, ReinitializesCorrectly) {
|
||||
auto key = InitializeLeafGrowAndReturnKey();
|
||||
auto leaf = DataLeafNode::InitializeNewNode(blockStore->load(key));
|
||||
//TODO Don't use nullcheck
|
||||
auto leaf = DataLeafNode::InitializeNewNode(cpputils::nullcheck(blockStore->load(key)).value());
|
||||
EXPECT_EQ(0u, leaf->numBytes());
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,8 @@ TEST_P(DataNodeViewDepthTest, DepthIsStored) {
|
||||
DataNodeView view(std::move(block));
|
||||
view.setDepth(GetParam());
|
||||
}
|
||||
DataNodeView view(blockStore->load(key));
|
||||
//TODO Don't use nullcheck
|
||||
DataNodeView view(cpputils::nullcheck(blockStore->load(key)).value());
|
||||
EXPECT_EQ(GetParam(), view.Depth());
|
||||
}
|
||||
|
||||
@ -55,7 +56,8 @@ TEST_P(DataNodeViewSizeTest, SizeIsStored) {
|
||||
DataNodeView view(std::move(block));
|
||||
view.setSize(GetParam());
|
||||
}
|
||||
DataNodeView view(blockStore->load(key));
|
||||
//TODO Don't use nullcheck
|
||||
DataNodeView view(cpputils::nullcheck(blockStore->load(key)).value());
|
||||
EXPECT_EQ(GetParam(), view.Size());
|
||||
}
|
||||
|
||||
@ -67,7 +69,8 @@ TEST_F(DataNodeViewTest, DataIsStored) {
|
||||
DataNodeView view(std::move(block));
|
||||
view.write(randomData.data(), 0, randomData.size());
|
||||
}
|
||||
DataNodeView view(blockStore->load(key));
|
||||
//TODO Don't use nullcheck
|
||||
DataNodeView view(cpputils::nullcheck(blockStore->load(key)).value());
|
||||
EXPECT_EQ(0, std::memcmp(view.data(), randomData.data(), randomData.size()));
|
||||
}
|
||||
|
||||
@ -76,12 +79,14 @@ TEST_F(DataNodeViewTest, HeaderAndBodyDontOverlap) {
|
||||
auto block = blockStore->create(Data(BLOCKSIZE_BYTES));
|
||||
auto key = block->key();
|
||||
{
|
||||
//TODO Don't use nullcheck
|
||||
DataNodeView view(std::move(block));
|
||||
view.setDepth(3);
|
||||
view.setSize(1000000000u);
|
||||
view.write(randomData.data(), 0, DATASIZE_BYTES);
|
||||
}
|
||||
DataNodeView view(blockStore->load(key));
|
||||
//TODO Don't use nullcheck
|
||||
DataNodeView view(cpputils::nullcheck(blockStore->load(key)).value());
|
||||
EXPECT_EQ(3, view.Depth());
|
||||
EXPECT_EQ(1000000000u, view.Size());
|
||||
EXPECT_EQ(0, std::memcmp(view.data(), randomData.data(), DATASIZE_BYTES));
|
||||
|
Loading…
x
Reference in New Issue
Block a user