From dd2c96e3636f616d5dc1b148588c94fe79458fae Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Sat, 24 Jan 2015 22:27:14 +0100 Subject: [PATCH] Since blocks now store their keys, we don't need to store it somewhere else. --- .../onblocks/datanodestore/DataInnerNode.cpp | 4 +- .../onblocks/datanodestore/DataInnerNode.h | 2 +- .../onblocks/datanodestore/DataLeafNode.cpp | 4 +- .../onblocks/datanodestore/DataLeafNode.h | 2 +- .../onblocks/datanodestore/DataNode.cpp | 8 ++-- .../onblocks/datanodestore/DataNode.h | 3 +- .../onblocks/datanodestore/DataNodeStore.cpp | 14 +++--- .../onblocks/datanodestore/DataNodeStore.h | 2 +- .../onblocks/datanodestore/DataNodeView.h | 4 ++ .../datanodestore/DataLeafNodeTest.cpp | 1 - .../datanodestore/DataNodeStoreTest.cpp | 4 +- .../datanodestore/DataNodeViewTest.cpp | 44 ++++++++++--------- 12 files changed, 49 insertions(+), 43 deletions(-) diff --git a/src/blobstore/implementations/onblocks/datanodestore/DataInnerNode.cpp b/src/blobstore/implementations/onblocks/datanodestore/DataInnerNode.cpp index d562bdc8..07730a69 100644 --- a/src/blobstore/implementations/onblocks/datanodestore/DataInnerNode.cpp +++ b/src/blobstore/implementations/onblocks/datanodestore/DataInnerNode.cpp @@ -11,8 +11,8 @@ namespace blobstore { namespace onblocks { namespace datanodestore { -DataInnerNode::DataInnerNode(DataNodeView view, const Key &key) -: DataNode(std::move(view), key) { +DataInnerNode::DataInnerNode(DataNodeView view) +: DataNode(std::move(view)) { } DataInnerNode::~DataInnerNode() { diff --git a/src/blobstore/implementations/onblocks/datanodestore/DataInnerNode.h b/src/blobstore/implementations/onblocks/datanodestore/DataInnerNode.h index 6f5d2432..75b114fa 100644 --- a/src/blobstore/implementations/onblocks/datanodestore/DataInnerNode.h +++ b/src/blobstore/implementations/onblocks/datanodestore/DataInnerNode.h @@ -10,7 +10,7 @@ namespace datanodestore { class DataInnerNode: public DataNode { public: - DataInnerNode(DataNodeView block, const blockstore::Key &key); + DataInnerNode(DataNodeView block); virtual ~DataInnerNode(); struct ChildEntry { diff --git a/src/blobstore/implementations/onblocks/datanodestore/DataLeafNode.cpp b/src/blobstore/implementations/onblocks/datanodestore/DataLeafNode.cpp index b15d5a37..0c6f9740 100644 --- a/src/blobstore/implementations/onblocks/datanodestore/DataLeafNode.cpp +++ b/src/blobstore/implementations/onblocks/datanodestore/DataLeafNode.cpp @@ -11,8 +11,8 @@ namespace blobstore { namespace onblocks { namespace datanodestore { -DataLeafNode::DataLeafNode(DataNodeView view, const Key &key) -: DataNode(std::move(view), key) { +DataLeafNode::DataLeafNode(DataNodeView view) +: DataNode(std::move(view)) { assert(numBytes() <= MAX_STORED_BYTES); } diff --git a/src/blobstore/implementations/onblocks/datanodestore/DataLeafNode.h b/src/blobstore/implementations/onblocks/datanodestore/DataLeafNode.h index 5983b82e..7b3d0c83 100644 --- a/src/blobstore/implementations/onblocks/datanodestore/DataLeafNode.h +++ b/src/blobstore/implementations/onblocks/datanodestore/DataLeafNode.h @@ -11,7 +11,7 @@ class DataInnerNode; class DataLeafNode: public DataNode { public: - DataLeafNode(DataNodeView block, const blockstore::Key &key); + DataLeafNode(DataNodeView block); virtual ~DataLeafNode(); static constexpr uint32_t MAX_STORED_BYTES = DataNodeView::DATASIZE_BYTES; diff --git a/src/blobstore/implementations/onblocks/datanodestore/DataNode.cpp b/src/blobstore/implementations/onblocks/datanodestore/DataNode.cpp index 2694029d..fb711e36 100644 --- a/src/blobstore/implementations/onblocks/datanodestore/DataNode.cpp +++ b/src/blobstore/implementations/onblocks/datanodestore/DataNode.cpp @@ -14,8 +14,8 @@ namespace blobstore { namespace onblocks { namespace datanodestore { -DataNode::DataNode(DataNodeView node, const Key &key) -: _key(key), _node(std::move(node)) { +DataNode::DataNode(DataNodeView node) +: _node(std::move(node)) { } DataNode::~DataNode() { @@ -30,7 +30,7 @@ const DataNodeView &DataNode::node() const { } const Key &DataNode::key() const { - return _key; + return _node.key(); } uint8_t DataNode::depth() const { @@ -42,7 +42,7 @@ unique_ptr DataNode::convertToNewInnerNode(unique_ptr n auto block = node->_node.releaseBlock(); std::memset(block->data(), 0, block->size()); - auto innerNode = make_unique(DataNodeView(std::move(block)), key); + auto innerNode = make_unique(DataNodeView(std::move(block))); innerNode->InitializeNewNode(first_child); return innerNode; } diff --git a/src/blobstore/implementations/onblocks/datanodestore/DataNode.h b/src/blobstore/implementations/onblocks/datanodestore/DataNode.h index 2308fe26..b5f67965 100644 --- a/src/blobstore/implementations/onblocks/datanodestore/DataNode.h +++ b/src/blobstore/implementations/onblocks/datanodestore/DataNode.h @@ -22,14 +22,13 @@ public: static std::unique_ptr convertToNewInnerNode(std::unique_ptr node, const DataNode &first_child); protected: - DataNode(DataNodeView block, const blockstore::Key &key); + DataNode(DataNodeView block); DataNodeView &node(); const DataNodeView &node() const; friend class DataNodeStore; private: - blockstore::Key _key; //TODO Remove this and make blockstore::Block store the key DataNodeView _node; DISALLOW_COPY_AND_ASSIGN(DataNode); diff --git a/src/blobstore/implementations/onblocks/datanodestore/DataNodeStore.cpp b/src/blobstore/implementations/onblocks/datanodestore/DataNodeStore.cpp index f76239e4..f85eb43c 100644 --- a/src/blobstore/implementations/onblocks/datanodestore/DataNodeStore.cpp +++ b/src/blobstore/implementations/onblocks/datanodestore/DataNodeStore.cpp @@ -24,13 +24,13 @@ DataNodeStore::DataNodeStore(unique_ptr blockstore) DataNodeStore::~DataNodeStore() { } -unique_ptr DataNodeStore::load(unique_ptr block, const Key &key) { +unique_ptr DataNodeStore::load(unique_ptr block) { DataNodeView node(std::move(block)); if (*node.Depth() == 0) { - return unique_ptr(new DataLeafNode(std::move(node), key)); + return unique_ptr(new DataLeafNode(std::move(node))); } else if (*node.Depth() <= MAX_DEPTH) { - return unique_ptr(new DataInnerNode(std::move(node), key)); + return unique_ptr(new DataInnerNode(std::move(node))); } else { throw runtime_error("Tree is to deep. Data corruption?"); } @@ -38,25 +38,25 @@ unique_ptr DataNodeStore::load(unique_ptr block, const Key &key unique_ptr DataNodeStore::createNewInnerNode(const DataNode &first_child) { auto block = _blockstore->create(DataNodeView::BLOCKSIZE_BYTES); - auto newNode = make_unique(std::move(block.block), block.key); + auto newNode = make_unique(std::move(block)); newNode->InitializeNewNode(first_child); return std::move(newNode); } unique_ptr DataNodeStore::createNewLeafNode() { auto block = _blockstore->create(DataNodeView::BLOCKSIZE_BYTES); - auto newNode = make_unique(std::move(block.block), block.key); + auto newNode = make_unique(std::move(block)); newNode->InitializeNewNode(); return std::move(newNode); } unique_ptr DataNodeStore::load(const Key &key) { - return load(_blockstore->load(key), key); + return load(_blockstore->load(key)); } unique_ptr DataNodeStore::createNewNodeAsCopyFrom(const DataNode &source) { auto newBlock = blockstore::utils::copyToNewBlock(_blockstore.get(), source.node().block()); - return load(std::move(newBlock.block), newBlock.key); + return load(std::move(newBlock)); } } diff --git a/src/blobstore/implementations/onblocks/datanodestore/DataNodeStore.h b/src/blobstore/implementations/onblocks/datanodestore/DataNodeStore.h index 43749f73..f54a7399 100644 --- a/src/blobstore/implementations/onblocks/datanodestore/DataNodeStore.h +++ b/src/blobstore/implementations/onblocks/datanodestore/DataNodeStore.h @@ -33,7 +33,7 @@ public: std::unique_ptr createNewNodeAsCopyFrom(const DataNode &source); private: - std::unique_ptr load(std::unique_ptr block, const blockstore::Key &key); + std::unique_ptr load(std::unique_ptr block); std::unique_ptr _blockstore; diff --git a/src/blobstore/implementations/onblocks/datanodestore/DataNodeView.h b/src/blobstore/implementations/onblocks/datanodestore/DataNodeView.h index 97617da5..90004654 100644 --- a/src/blobstore/implementations/onblocks/datanodestore/DataNodeView.h +++ b/src/blobstore/implementations/onblocks/datanodestore/DataNodeView.h @@ -80,6 +80,10 @@ public: return *_block; } + const blockstore::Key &key() const { + return _block->key(); + } + private: template const Type *GetOffset() const { diff --git a/src/test/blobstore/implementations/onblocks/datanodestore/DataLeafNodeTest.cpp b/src/test/blobstore/implementations/onblocks/datanodestore/DataLeafNodeTest.cpp index 6cda64c3..388ce7be 100644 --- a/src/test/blobstore/implementations/onblocks/datanodestore/DataLeafNodeTest.cpp +++ b/src/test/blobstore/implementations/onblocks/datanodestore/DataLeafNodeTest.cpp @@ -21,7 +21,6 @@ using std::string; using fspp::dynamic_pointer_move; using blockstore::BlockStore; -using blockstore::BlockWithKey; using blockstore::Data; using blockstore::Key; using blockstore::testfake::FakeBlockStore; diff --git a/src/test/blobstore/implementations/onblocks/datanodestore/DataNodeStoreTest.cpp b/src/test/blobstore/implementations/onblocks/datanodestore/DataNodeStoreTest.cpp index de3dd4b1..41a4270d 100644 --- a/src/test/blobstore/implementations/onblocks/datanodestore/DataNodeStoreTest.cpp +++ b/src/test/blobstore/implementations/onblocks/datanodestore/DataNodeStoreTest.cpp @@ -70,9 +70,9 @@ TEST_F(DataNodeStoreTest, InnerNodeWithDepth2IsRecognizedAfterStoreAndLoad) { TEST_F(DataNodeStoreTest, DataNodeCrashesOnLoadIfDepthIsTooHigh) { auto block = blockStore->create(BlobStoreOnBlocks::BLOCKSIZE); - Key key = block.key; + Key key = block->key(); { - DataNodeView view(std::move(block.block)); + DataNodeView view(std::move(block)); *view.Depth() = DataNodeStore::MAX_DEPTH + 1; } diff --git a/src/test/blobstore/implementations/onblocks/datanodestore/DataNodeViewTest.cpp b/src/test/blobstore/implementations/onblocks/datanodestore/DataNodeViewTest.cpp index f4ae3cc3..36098af7 100644 --- a/src/test/blobstore/implementations/onblocks/datanodestore/DataNodeViewTest.cpp +++ b/src/test/blobstore/implementations/onblocks/datanodestore/DataNodeViewTest.cpp @@ -30,11 +30,12 @@ INSTANTIATE_TEST_CASE_P(DataNodeViewDepthTest, DataNodeViewDepthTest, Values(0, TEST_P(DataNodeViewDepthTest, DepthIsStored) { auto block = blockStore->create(BlobStoreOnBlocks::BLOCKSIZE); + auto key = block->key(); { - DataNodeView view(std::move(block.block)); + DataNodeView view(std::move(block)); *view.Depth() = GetParam(); } - DataNodeView view(blockStore->load(block.key)); + DataNodeView view(blockStore->load(key)); EXPECT_EQ(GetParam(), *view.Depth()); } @@ -44,35 +45,38 @@ INSTANTIATE_TEST_CASE_P(DataNodeViewSizeTest, DataNodeViewSizeTest, Values(0, 50 TEST_P(DataNodeViewSizeTest, SizeIsStored) { auto block = blockStore->create(BlobStoreOnBlocks::BLOCKSIZE); + auto key = block->key(); { - DataNodeView view(std::move(block.block)); + DataNodeView view(std::move(block)); *view.Size() = GetParam(); } - DataNodeView view(blockStore->load(block.key)); + DataNodeView view(blockStore->load(key)); EXPECT_EQ(GetParam(), *view.Size()); } TEST_F(DataNodeViewTest, DataIsStored) { DataBlockFixture randomData(DataNodeView::DATASIZE_BYTES); auto block = blockStore->create(DataNodeView::BLOCKSIZE_BYTES); + auto key = block->key(); { - DataNodeView view(std::move(block.block)); + DataNodeView view(std::move(block)); std::memcpy(view.DataBegin(), randomData.data(), randomData.size()); } - DataNodeView view(blockStore->load(block.key)); + DataNodeView view(blockStore->load(key)); EXPECT_EQ(0, std::memcmp(view.DataBegin(), randomData.data(), randomData.size())); } TEST_F(DataNodeViewTest, HeaderAndBodyDontOverlap) { DataBlockFixture randomData(DataNodeView::DATASIZE_BYTES); auto block = blockStore->create(BlobStoreOnBlocks::BLOCKSIZE); + auto key = block->key(); { - DataNodeView view(std::move(block.block)); + DataNodeView view(std::move(block)); *view.Depth() = 3; *view.Size() = 1000000000u; std::memcpy(view.DataBegin(), randomData.data(), DataNodeView::DATASIZE_BYTES); } - DataNodeView view(blockStore->load(block.key)); + DataNodeView view(blockStore->load(key)); EXPECT_EQ(3, *view.Depth()); EXPECT_EQ(1000000000u, *view.Size()); EXPECT_EQ(0, std::memcmp(view.DataBegin(), randomData.data(), DataNodeView::DATASIZE_BYTES)); @@ -80,32 +84,32 @@ TEST_F(DataNodeViewTest, HeaderAndBodyDontOverlap) { TEST_F(DataNodeViewTest, DataBeginWorksWithOneByteEntries) { auto block = blockStore->create(BlobStoreOnBlocks::BLOCKSIZE); - uint8_t *blockBegin = (uint8_t*)block.block->data(); - DataNodeView view(std::move(block.block)); + uint8_t *blockBegin = (uint8_t*)block->data(); + DataNodeView view(std::move(block)); EXPECT_EQ(blockBegin+view.HEADERSIZE_BYTES, view.DataBegin()); } TEST_F(DataNodeViewTest, DataBeginWorksWithEightByteEntries) { auto block = blockStore->create(BlobStoreOnBlocks::BLOCKSIZE); - uint8_t *blockBegin = (uint8_t*)block.block->data(); - DataNodeView view(std::move(block.block)); + uint8_t *blockBegin = (uint8_t*)block->data(); + DataNodeView view(std::move(block)); EXPECT_EQ(blockBegin+view.HEADERSIZE_BYTES, (uint8_t*)view.DataBegin()); } TEST_F(DataNodeViewTest, DataEndWorksWithOneByteEntries) { auto block = blockStore->create(BlobStoreOnBlocks::BLOCKSIZE); - uint8_t *blockBegin = (uint8_t*)block.block->data(); - DataNodeView view(std::move(block.block)); + uint8_t *blockBegin = (uint8_t*)block->data(); + DataNodeView view(std::move(block)); EXPECT_EQ(blockBegin+view.BLOCKSIZE_BYTES, view.DataEnd()); } TEST_F(DataNodeViewTest, DataEndWorksWithEightByteEntries) { auto block = blockStore->create(BlobStoreOnBlocks::BLOCKSIZE); - uint8_t *blockBegin = (uint8_t*)block.block->data(); - DataNodeView view(std::move(block.block)); + uint8_t *blockBegin = (uint8_t*)block->data(); + DataNodeView view(std::move(block)); EXPECT_EQ(blockBegin+view.BLOCKSIZE_BYTES, (uint8_t*)view.DataEnd()); } @@ -120,16 +124,16 @@ BOOST_STATIC_ASSERT_MSG(DataNodeView::DATASIZE_BYTES % sizeof(SizedDataEntry) != TEST_F(DataNodeViewTest, DataBeginWorksWithStructEntries) { auto block = blockStore->create(BlobStoreOnBlocks::BLOCKSIZE); - uint8_t *blockBegin = (uint8_t*)block.block->data(); - DataNodeView view(std::move(block.block)); + uint8_t *blockBegin = (uint8_t*)block->data(); + DataNodeView view(std::move(block)); EXPECT_EQ(blockBegin+view.HEADERSIZE_BYTES, (uint8_t*)view.DataBegin()); } TEST_F(DataNodeViewTest, DataEndWorksWithStructByteEntries) { auto block = blockStore->create(BlobStoreOnBlocks::BLOCKSIZE); - uint8_t *blockBegin = (uint8_t*)block.block->data(); - DataNodeView view(std::move(block.block)); + uint8_t *blockBegin = (uint8_t*)block->data(); + DataNodeView view(std::move(block)); unsigned int numFittingEntries = view.DATASIZE_BYTES / sizeof(SizedDataEntry);