Move datanodestore classes into own c++ package and adapt BlobStoreOnBlocks to it

This commit is contained in:
Sebastian Messmer 2014-12-13 19:17:08 +01:00
parent 7490e55d00
commit fa604a7fc4
19 changed files with 62 additions and 71 deletions

View File

@ -1,33 +1,24 @@
#include <blobstore/implementations/onblocks/BlobOnBlocks.h>
#include "datanodestore/DataNode.h"
using std::unique_ptr;
using blockstore::Block;
namespace blobstore {
namespace onblocks {
BlobOnBlocks::BlobOnBlocks(unique_ptr<Block> rootblock)
: _rootblock(std::move(rootblock)) {
using datanodestore::DataNode;
BlobOnBlocks::BlobOnBlocks(unique_ptr<DataNode> rootnode)
: _rootnode(std::move(rootnode)) {
}
BlobOnBlocks::~BlobOnBlocks() {
}
void *BlobOnBlocks::data() {
return const_cast<void*>(const_cast<const BlobOnBlocks*>(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();
}
}

View File

@ -3,27 +3,24 @@
#define BLOBSTORE_IMPLEMENTATIONS_ONBLOCKS_BLOBONBLOCKS_H_
#include "blobstore/interface/Blob.h"
#include "blockstore/interface/Block.h"
#include <memory>
namespace blobstore {
namespace onblocks {
namespace datanodestore {
class DataNode;
}
class BlobOnBlocks: public Blob {
public:
BlobOnBlocks(std::unique_ptr<blockstore::Block> rootblock);
BlobOnBlocks(std::unique_ptr<datanodestore::DataNode> rootnode);
virtual ~BlobOnBlocks();
void *data() override;
const void *data() const override;
void flush() override;
size_t size() const override;
private:
std::unique_ptr<blockstore::Block> _rootblock;
std::unique_ptr<datanodestore::DataNode> _rootnode;
};
}

View File

@ -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> blockStore)
: _blocks(std::move(blockStore)) {
: _nodes(make_unique<DataNodeStore>(std::move(blockStore))) {
}
BlobStoreOnBlocks::~BlobStoreOnBlocks() {
}
BlobWithKey BlobStoreOnBlocks::create(size_t size) {
auto block = _blocks->create(size);
return BlobWithKey(block.key, make_unique<BlobOnBlocks>(std::move(block.block)));
unique_ptr<Blob> BlobStoreOnBlocks::create() {
return make_unique<BlobOnBlocks>(_nodes->createNewLeafNode());
}
unique_ptr<Blob> BlobStoreOnBlocks::load(const Key &key) {
return make_unique<BlobOnBlocks>(_blocks->load(key));
return make_unique<BlobOnBlocks>(_nodes->load(key));
}
}

View File

@ -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::BlockStore> blockStore);
virtual ~BlobStoreOnBlocks();
BlobWithKey create(size_t size) override;
std::unique_ptr<Blob> load(const Key &key) override;
std::unique_ptr<Blob> create() override;
std::unique_ptr<Blob> load(const blockstore::Key &key) override;
private:
std::unique_ptr<blockstore::BlockStore> _blocks;
std::unique_ptr<datanodestore::DataNodeStore> _nodes;
};
}

View File

@ -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) {
}
}
}

View File

@ -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;
};
}
}
}

View File

@ -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) {
}
}
}

View File

@ -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);
};
}
}
}

View File

@ -5,6 +5,7 @@
#include <blobstore/implementations/onblocks/datanodestore/DataNodeStore.h>
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 {
}
}
}

View File

@ -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

View File

@ -14,6 +14,7 @@ using std::runtime_error;
namespace blobstore {
namespace onblocks {
namespace datanodestore {
DataNodeStore::DataNodeStore(unique_ptr<BlockStore> blockstore)
: _blockstore(std::move(blockstore)) {
@ -58,3 +59,4 @@ unique_ptr<const DataNode> DataNodeStore::load(const Key &key) const {
}
}
}

View File

@ -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);
};
}
}
}

View File

@ -12,6 +12,7 @@
namespace blobstore {
namespace onblocks {
namespace datanodestore {
class DataNodeView {
public:
@ -83,6 +84,7 @@ private:
};
}
}
}

View File

@ -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;
};

View File

@ -3,10 +3,10 @@
#define FSPP_BLOBSTORE_BLOBSTORE_H_
#include "Blob.h"
#include "blobstore/utils/BlobWithKey.h"
#include <string>
#include <memory>
#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<Blob> 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<Blob> load(const Key &key) = 0;
virtual std::unique_ptr<Blob> load(const blockstore::Key &key) = 0;
//TODO Needed for performance? Or is deleting loaded blocks enough?
//virtual void remove(const std::string &key) = 0;
};

View File

@ -1,24 +0,0 @@
#pragma once
#ifndef BLOBSTORE_INTERFACE_BLOBWITHKEY_H_
#define BLOBSTORE_INTERFACE_BLOBWITHKEY_H_
#include <blobstore/interface/Blob.h>
#include <memory>
#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> blob_): key(key_), blob(std::move(blob_)) {}
Key key;
std::unique_ptr<Blob> blob;
};
}
#endif

View File

@ -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<Type*>(ptr)) << "Given pointer cannot be cast to the given type"

View File

@ -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:

View File

@ -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: