From fa604a7fc48b5df3430ae3825cd8dea337c44afa Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Sat, 13 Dec 2014 19:17:08 +0100 Subject: [PATCH] Move datanodestore classes into own c++ package and adapt BlobStoreOnBlocks to it --- .../implementations/onblocks/BlobOnBlocks.cpp | 23 ++++++------------ .../implementations/onblocks/BlobOnBlocks.h | 13 ++++------ .../onblocks/BlobStoreOnBlocks.cpp | 14 +++++++---- .../onblocks/BlobStoreOnBlocks.h | 10 ++++---- .../onblocks/datanodestore/DataInnerNode.cpp | 3 +++ .../onblocks/datanodestore/DataInnerNode.h | 6 +++-- .../onblocks/datanodestore/DataLeafNode.cpp | 3 +++ .../onblocks/datanodestore/DataLeafNode.h | 4 +++- .../onblocks/datanodestore/DataNode.cpp | 3 +++ .../onblocks/datanodestore/DataNode.h | 8 ++++--- .../onblocks/datanodestore/DataNodeStore.cpp | 2 ++ .../onblocks/datanodestore/DataNodeStore.h | 2 ++ .../onblocks/datanodestore/DataNodeView.h | 2 ++ src/blobstore/interface/Blob.h | 5 ---- src/blobstore/interface/BlobStore.h | 6 ++--- src/blobstore/utils/BlobWithKey.h | 24 ------------------- .../datanodestore/DataLeafNodeTest.cpp | 2 ++ .../datanodestore/DataNodeStoreTest.cpp | 2 ++ .../datanodestore/DataNodeViewTest.cpp | 1 + 19 files changed, 62 insertions(+), 71 deletions(-) delete mode 100644 src/blobstore/utils/BlobWithKey.h diff --git a/src/blobstore/implementations/onblocks/BlobOnBlocks.cpp b/src/blobstore/implementations/onblocks/BlobOnBlocks.cpp index f280c3ab..da32de1a 100644 --- a/src/blobstore/implementations/onblocks/BlobOnBlocks.cpp +++ b/src/blobstore/implementations/onblocks/BlobOnBlocks.cpp @@ -1,33 +1,24 @@ #include +#include "datanodestore/DataNode.h" + using std::unique_ptr; -using blockstore::Block; namespace blobstore { namespace onblocks { -BlobOnBlocks::BlobOnBlocks(unique_ptr rootblock) -: _rootblock(std::move(rootblock)) { +using datanodestore::DataNode; + +BlobOnBlocks::BlobOnBlocks(unique_ptr rootnode) +: _rootnode(std::move(rootnode)) { } BlobOnBlocks::~BlobOnBlocks() { } -void *BlobOnBlocks::data() { - return const_cast(const_cast(this)->data()); -} - -const void *BlobOnBlocks::data() const { - return _rootblock->data(); -} - -void BlobOnBlocks::flush() { - _rootblock->flush(); -} - size_t BlobOnBlocks::size() const { - return _rootblock->size(); + return _rootnode->numBytesInThisNode(); } } diff --git a/src/blobstore/implementations/onblocks/BlobOnBlocks.h b/src/blobstore/implementations/onblocks/BlobOnBlocks.h index 60ea9cc5..bf34bd82 100644 --- a/src/blobstore/implementations/onblocks/BlobOnBlocks.h +++ b/src/blobstore/implementations/onblocks/BlobOnBlocks.h @@ -3,27 +3,24 @@ #define BLOBSTORE_IMPLEMENTATIONS_ONBLOCKS_BLOBONBLOCKS_H_ #include "blobstore/interface/Blob.h" -#include "blockstore/interface/Block.h" #include namespace blobstore { namespace onblocks { +namespace datanodestore { +class DataNode; +} class BlobOnBlocks: public Blob { public: - BlobOnBlocks(std::unique_ptr rootblock); + BlobOnBlocks(std::unique_ptr rootnode); virtual ~BlobOnBlocks(); - void *data() override; - const void *data() const override; - - void flush() override; - size_t size() const override; private: - std::unique_ptr _rootblock; + std::unique_ptr _rootnode; }; } diff --git a/src/blobstore/implementations/onblocks/BlobStoreOnBlocks.cpp b/src/blobstore/implementations/onblocks/BlobStoreOnBlocks.cpp index 632868ff..5caa6752 100644 --- a/src/blobstore/implementations/onblocks/BlobStoreOnBlocks.cpp +++ b/src/blobstore/implementations/onblocks/BlobStoreOnBlocks.cpp @@ -1,29 +1,33 @@ #include "BlobStoreOnBlocks.h" #include "BlobOnBlocks.h" +#include "datanodestore/DataNodeStore.h" +#include "datanodestore/DataLeafNode.h" using std::unique_ptr; using std::make_unique; using blockstore::BlockStore; +using blockstore::Key; namespace blobstore { namespace onblocks { +using datanodestore::DataNodeStore; + BlobStoreOnBlocks::BlobStoreOnBlocks(unique_ptr blockStore) -: _blocks(std::move(blockStore)) { +: _nodes(make_unique(std::move(blockStore))) { } BlobStoreOnBlocks::~BlobStoreOnBlocks() { } -BlobWithKey BlobStoreOnBlocks::create(size_t size) { - auto block = _blocks->create(size); - return BlobWithKey(block.key, make_unique(std::move(block.block))); +unique_ptr BlobStoreOnBlocks::create() { + return make_unique(_nodes->createNewLeafNode()); } unique_ptr BlobStoreOnBlocks::load(const Key &key) { - return make_unique(_blocks->load(key)); + return make_unique(_nodes->load(key)); } } diff --git a/src/blobstore/implementations/onblocks/BlobStoreOnBlocks.h b/src/blobstore/implementations/onblocks/BlobStoreOnBlocks.h index da57124c..64e6062a 100644 --- a/src/blobstore/implementations/onblocks/BlobStoreOnBlocks.h +++ b/src/blobstore/implementations/onblocks/BlobStoreOnBlocks.h @@ -7,20 +7,22 @@ namespace blobstore { namespace onblocks { +namespace datanodestore { +class DataNodeStore; +} class BlobStoreOnBlocks: public BlobStore { public: - //Should be a multiple of 16. The DataNodeView classes have a header of 16 bytes and the block key length (inner data nodes store a list of block keys) is 16 bytes. static constexpr size_t BLOCKSIZE = 4096; BlobStoreOnBlocks(std::unique_ptr blockStore); virtual ~BlobStoreOnBlocks(); - BlobWithKey create(size_t size) override; - std::unique_ptr load(const Key &key) override; + std::unique_ptr create() override; + std::unique_ptr load(const blockstore::Key &key) override; private: - std::unique_ptr _blocks; + std::unique_ptr _nodes; }; } diff --git a/src/blobstore/implementations/onblocks/datanodestore/DataInnerNode.cpp b/src/blobstore/implementations/onblocks/datanodestore/DataInnerNode.cpp index 97ef9d8e..6e19e5cc 100644 --- a/src/blobstore/implementations/onblocks/datanodestore/DataInnerNode.cpp +++ b/src/blobstore/implementations/onblocks/datanodestore/DataInnerNode.cpp @@ -5,9 +5,11 @@ using std::unique_ptr; using blockstore::Block; using blockstore::Data; +using blockstore::Key; namespace blobstore { namespace onblocks { +namespace datanodestore { DataInnerNode::DataInnerNode(DataNodeView view, const Key &key, DataNodeStore *nodestorage) : DataNode(std::move(view), key, nodestorage) { @@ -109,3 +111,4 @@ void DataInnerNode::resize(uint64_t newsize_bytes) { } } +} diff --git a/src/blobstore/implementations/onblocks/datanodestore/DataInnerNode.h b/src/blobstore/implementations/onblocks/datanodestore/DataInnerNode.h index 50040d50..af9b1754 100644 --- a/src/blobstore/implementations/onblocks/datanodestore/DataInnerNode.h +++ b/src/blobstore/implementations/onblocks/datanodestore/DataInnerNode.h @@ -6,14 +6,15 @@ namespace blobstore { namespace onblocks { +namespace datanodestore { class DataInnerNode: public DataNode { public: - DataInnerNode(DataNodeView block, const Key &key, DataNodeStore *nodestorage); + DataInnerNode(DataNodeView block, const blockstore::Key &key, DataNodeStore *nodestorage); virtual ~DataInnerNode(); struct ChildEntry { - uint8_t key[Key::KEYLENGTH_BINARY]; + uint8_t key[blockstore::Key::KEYLENGTH_BINARY]; }; static constexpr uint32_t MAX_STORED_CHILDREN = DataNodeView::DATASIZE_BYTES / sizeof(ChildEntry); @@ -42,6 +43,7 @@ private: const ChildEntry *ChildContainingFirstByteAfterOffset(off_t offset) const; }; +} } } diff --git a/src/blobstore/implementations/onblocks/datanodestore/DataLeafNode.cpp b/src/blobstore/implementations/onblocks/datanodestore/DataLeafNode.cpp index f8d5f886..2379b5b6 100644 --- a/src/blobstore/implementations/onblocks/datanodestore/DataLeafNode.cpp +++ b/src/blobstore/implementations/onblocks/datanodestore/DataLeafNode.cpp @@ -3,9 +3,11 @@ using std::unique_ptr; using blockstore::Block; using blockstore::Data; +using blockstore::Key; namespace blobstore { namespace onblocks { +namespace datanodestore { DataLeafNode::DataLeafNode(DataNodeView view, const Key &key, DataNodeStore *nodestorage) : DataNode(std::move(view), key, nodestorage) { @@ -56,3 +58,4 @@ void DataLeafNode::resize(uint64_t newsize_bytes) { } } +} diff --git a/src/blobstore/implementations/onblocks/datanodestore/DataLeafNode.h b/src/blobstore/implementations/onblocks/datanodestore/DataLeafNode.h index d64947e5..de3fa93f 100644 --- a/src/blobstore/implementations/onblocks/datanodestore/DataLeafNode.h +++ b/src/blobstore/implementations/onblocks/datanodestore/DataLeafNode.h @@ -6,10 +6,11 @@ namespace blobstore { namespace onblocks { +namespace datanodestore { class DataLeafNode: public DataNode { public: - DataLeafNode(DataNodeView block, const Key &key, DataNodeStore *nodestorage); + DataLeafNode(DataNodeView block, const blockstore::Key &key, DataNodeStore *nodestorage); virtual ~DataLeafNode(); static constexpr uint32_t MAX_STORED_BYTES = DataNodeView::DATASIZE_BYTES; @@ -26,6 +27,7 @@ private: void fillDataWithZeroesFromTo(off_t begin, off_t end); }; +} } } diff --git a/src/blobstore/implementations/onblocks/datanodestore/DataNode.cpp b/src/blobstore/implementations/onblocks/datanodestore/DataNode.cpp index ea3b786f..eb9db335 100644 --- a/src/blobstore/implementations/onblocks/datanodestore/DataNode.cpp +++ b/src/blobstore/implementations/onblocks/datanodestore/DataNode.cpp @@ -5,6 +5,7 @@ #include using blockstore::Block; +using blockstore::Key; using std::unique_ptr; using std::make_unique; @@ -12,6 +13,7 @@ using std::runtime_error; namespace blobstore { namespace onblocks { +namespace datanodestore { DataNode::DataNode(DataNodeView node, const Key &key, DataNodeStore *nodestorage) : _key(key), _node(std::move(node)), _nodestorage(nodestorage) { @@ -46,3 +48,4 @@ uint8_t DataNode::depth() const { } } +} diff --git a/src/blobstore/implementations/onblocks/datanodestore/DataNode.h b/src/blobstore/implementations/onblocks/datanodestore/DataNode.h index e338e01c..ab488d2e 100644 --- a/src/blobstore/implementations/onblocks/datanodestore/DataNode.h +++ b/src/blobstore/implementations/onblocks/datanodestore/DataNode.h @@ -7,6 +7,7 @@ namespace blobstore { namespace onblocks { +namespace datanodestore { class DataNodeStore; class DataNode { @@ -19,12 +20,12 @@ public: virtual void resize(uint64_t newsize_bytes) = 0; virtual uint64_t numBytesInThisNode() const = 0; - const Key &key() const; + const blockstore::Key &key() const; uint8_t depth() const; protected: - DataNode(DataNodeView block, const Key &key, DataNodeStore *nodestorage); + DataNode(DataNodeView block, const blockstore::Key &key, DataNodeStore *nodestorage); DataNodeStore &storage(); const DataNodeStore &storage() const; @@ -33,7 +34,7 @@ protected: const DataNodeView &node() const; private: - Key _key; //TODO Remove this and make blockstore::Block store the key + blockstore::Key _key; //TODO Remove this and make blockstore::Block store the key DataNodeView _node; DataNodeStore *_nodestorage; @@ -42,6 +43,7 @@ private: } } +} #endif diff --git a/src/blobstore/implementations/onblocks/datanodestore/DataNodeStore.cpp b/src/blobstore/implementations/onblocks/datanodestore/DataNodeStore.cpp index 9cfab417..b257efb8 100644 --- a/src/blobstore/implementations/onblocks/datanodestore/DataNodeStore.cpp +++ b/src/blobstore/implementations/onblocks/datanodestore/DataNodeStore.cpp @@ -14,6 +14,7 @@ using std::runtime_error; namespace blobstore { namespace onblocks { +namespace datanodestore { DataNodeStore::DataNodeStore(unique_ptr blockstore) : _blockstore(std::move(blockstore)) { @@ -58,3 +59,4 @@ unique_ptr DataNodeStore::load(const Key &key) const { } } +} diff --git a/src/blobstore/implementations/onblocks/datanodestore/DataNodeStore.h b/src/blobstore/implementations/onblocks/datanodestore/DataNodeStore.h index 4741097e..5d39e53c 100644 --- a/src/blobstore/implementations/onblocks/datanodestore/DataNodeStore.h +++ b/src/blobstore/implementations/onblocks/datanodestore/DataNodeStore.h @@ -13,6 +13,7 @@ class Key; namespace blobstore { namespace onblocks { +namespace datanodestore { class DataNode; class DataLeafNode; class DataInnerNode; @@ -38,6 +39,7 @@ private: DISALLOW_COPY_AND_ASSIGN(DataNodeStore); }; +} } } diff --git a/src/blobstore/implementations/onblocks/datanodestore/DataNodeView.h b/src/blobstore/implementations/onblocks/datanodestore/DataNodeView.h index 4c2c42f4..c3eae041 100644 --- a/src/blobstore/implementations/onblocks/datanodestore/DataNodeView.h +++ b/src/blobstore/implementations/onblocks/datanodestore/DataNodeView.h @@ -12,6 +12,7 @@ namespace blobstore { namespace onblocks { +namespace datanodestore { class DataNodeView { public: @@ -83,6 +84,7 @@ private: }; +} } } diff --git a/src/blobstore/interface/Blob.h b/src/blobstore/interface/Blob.h index d2223099..b97b5336 100644 --- a/src/blobstore/interface/Blob.h +++ b/src/blobstore/interface/Blob.h @@ -10,11 +10,6 @@ class Blob { public: virtual ~Blob() {} - virtual void *data() = 0; - virtual const void *data() const = 0; - - virtual void flush() = 0; - virtual size_t size() const = 0; }; diff --git a/src/blobstore/interface/BlobStore.h b/src/blobstore/interface/BlobStore.h index 3940ba64..780fa091 100644 --- a/src/blobstore/interface/BlobStore.h +++ b/src/blobstore/interface/BlobStore.h @@ -3,10 +3,10 @@ #define FSPP_BLOBSTORE_BLOBSTORE_H_ #include "Blob.h" -#include "blobstore/utils/BlobWithKey.h" #include #include +#include "blockstore/utils/Key.h" namespace blobstore { @@ -14,10 +14,10 @@ class BlobStore { public: virtual ~BlobStore() {} - virtual BlobWithKey create(size_t size) = 0; + virtual std::unique_ptr create() = 0; //TODO Use boost::optional (if key doesn't exist) // Return nullptr if block with this key doesn't exists - virtual std::unique_ptr load(const Key &key) = 0; + virtual std::unique_ptr load(const blockstore::Key &key) = 0; //TODO Needed for performance? Or is deleting loaded blocks enough? //virtual void remove(const std::string &key) = 0; }; diff --git a/src/blobstore/utils/BlobWithKey.h b/src/blobstore/utils/BlobWithKey.h deleted file mode 100644 index 00635c00..00000000 --- a/src/blobstore/utils/BlobWithKey.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once -#ifndef BLOBSTORE_INTERFACE_BLOBWITHKEY_H_ -#define BLOBSTORE_INTERFACE_BLOBWITHKEY_H_ - -#include -#include -#include "fspp/utils/macros.h" -#include "blockstore/utils/Key.h" - -namespace blobstore { - -//TODO Use own key class to become independent from blockstore? -typedef blockstore::Key Key; - -struct BlobWithKey { - BlobWithKey(const Key &key_, std::unique_ptr blob_): key(key_), blob(std::move(blob_)) {} - - Key key; - std::unique_ptr blob; -}; - -} - -#endif diff --git a/src/test/blobstore/implementations/onblocks/datanodestore/DataLeafNodeTest.cpp b/src/test/blobstore/implementations/onblocks/datanodestore/DataLeafNodeTest.cpp index b1b8298b..7ae911e7 100644 --- a/src/test/blobstore/implementations/onblocks/datanodestore/DataLeafNodeTest.cpp +++ b/src/test/blobstore/implementations/onblocks/datanodestore/DataLeafNodeTest.cpp @@ -18,9 +18,11 @@ using std::string; using blockstore::BlockStore; using blockstore::BlockWithKey; using blockstore::Data; +using blockstore::Key; using blockstore::testfake::FakeBlockStore; using namespace blobstore; using namespace blobstore::onblocks; +using namespace blobstore::onblocks::datanodestore; #define EXPECT_IS_PTR_TYPE(Type, ptr) EXPECT_NE(nullptr, dynamic_cast(ptr)) << "Given pointer cannot be cast to the given type" diff --git a/src/test/blobstore/implementations/onblocks/datanodestore/DataNodeStoreTest.cpp b/src/test/blobstore/implementations/onblocks/datanodestore/DataNodeStoreTest.cpp index b9eb3a31..68a9938d 100644 --- a/src/test/blobstore/implementations/onblocks/datanodestore/DataNodeStoreTest.cpp +++ b/src/test/blobstore/implementations/onblocks/datanodestore/DataNodeStoreTest.cpp @@ -15,8 +15,10 @@ using std::string; using blockstore::BlockStore; using blockstore::testfake::FakeBlockStore; +using blockstore::Key; using namespace blobstore; using namespace blobstore::onblocks; +using namespace blobstore::onblocks::datanodestore; class DataNodeStoreTest: public Test { public: diff --git a/src/test/blobstore/implementations/onblocks/datanodestore/DataNodeViewTest.cpp b/src/test/blobstore/implementations/onblocks/datanodestore/DataNodeViewTest.cpp index 20a98581..f24ae6d4 100644 --- a/src/test/blobstore/implementations/onblocks/datanodestore/DataNodeViewTest.cpp +++ b/src/test/blobstore/implementations/onblocks/datanodestore/DataNodeViewTest.cpp @@ -17,6 +17,7 @@ using blockstore::BlockStore; using blockstore::testfake::FakeBlockStore; using namespace blobstore; using namespace blobstore::onblocks; +using namespace blobstore::onblocks::datanodestore; class DataNodeViewTest: public Test { public: