Create dedicated Key class for addressing blocks
This commit is contained in:
parent
48cc8eeff0
commit
0b2b527b4d
@ -22,7 +22,7 @@ BlobWithKey BlobStoreOnBlocks::create(size_t size) {
|
||||
return BlobWithKey(block.key, make_unique<BlobOnBlocks>(std::move(block.block)));
|
||||
}
|
||||
|
||||
unique_ptr<Blob> BlobStoreOnBlocks::load(const std::string &key) {
|
||||
unique_ptr<Blob> BlobStoreOnBlocks::load(const Key &key) {
|
||||
return make_unique<BlobOnBlocks>(_blocks->load(key));
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ public:
|
||||
virtual ~BlobStoreOnBlocks();
|
||||
|
||||
BlobWithKey create(size_t size) override;
|
||||
std::unique_ptr<Blob> load(const std::string &key) override;
|
||||
std::unique_ptr<Blob> load(const Key &key) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<blockstore::BlockStore> _blocks;
|
||||
|
@ -17,7 +17,7 @@ public:
|
||||
virtual BlobWithKey create(size_t size) = 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 std::string &key) = 0;
|
||||
virtual std::unique_ptr<Blob> load(const Key &key) = 0;
|
||||
//TODO Needed for performance? Or is deleting loaded blocks enough?
|
||||
//virtual void remove(const std::string &key) = 0;
|
||||
};
|
||||
|
@ -5,13 +5,17 @@
|
||||
#include <blobstore/interface/Blob.h>
|
||||
#include <memory>
|
||||
#include "fspp/utils/macros.h"
|
||||
#include "blockstore/utils/Key.h"
|
||||
|
||||
namespace blobstore {
|
||||
|
||||
struct BlobWithKey {
|
||||
BlobWithKey(const std::string &key_, std::unique_ptr<Blob> blob_): key(key_), blob(std::move(blob_)) {}
|
||||
//TODO Use own key class to become independent from blockstore?
|
||||
typedef blockstore::Key Key;
|
||||
|
||||
std::string 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;
|
||||
};
|
||||
|
||||
|
@ -26,7 +26,7 @@ public:
|
||||
|
||||
TEST_F(DataNodeTest, InitializeNewLeafNodeCreatesLeafNodeObject) {
|
||||
auto block = blockStore->create(BlobStoreOnBlocks::BLOCKSIZE);
|
||||
string key = block.key;
|
||||
Key key = block.key;
|
||||
auto leafNode = DataNode::initializeNewLeafNode(std::move(block.block));
|
||||
|
||||
EXPECT_IS_PTR_TYPE(DataLeafNode, leafNode.get());
|
||||
@ -34,7 +34,7 @@ TEST_F(DataNodeTest, InitializeNewLeafNodeCreatesLeafNodeObject) {
|
||||
|
||||
TEST_F(DataNodeTest, InitializeNewInnerNodeCreatesInnerNodeObject) {
|
||||
auto block = blockStore->create(BlobStoreOnBlocks::BLOCKSIZE);
|
||||
string key = block.key;
|
||||
Key key = block.key;
|
||||
auto innerNode = DataNode::initializeNewInnerNode(std::move(block.block));
|
||||
|
||||
EXPECT_IS_PTR_TYPE(DataInnerNode, innerNode.get());
|
||||
@ -42,7 +42,7 @@ TEST_F(DataNodeTest, InitializeNewInnerNodeCreatesInnerNodeObject) {
|
||||
|
||||
TEST_F(DataNodeTest, LeafNodeIsRecognizedAfterStoreAndLoad) {
|
||||
auto block = blockStore->create(BlobStoreOnBlocks::BLOCKSIZE);
|
||||
string key = block.key;
|
||||
Key key = block.key;
|
||||
auto node = DataNode::initializeNewLeafNode(std::move(block.block));
|
||||
node->flush();
|
||||
|
||||
@ -53,7 +53,7 @@ TEST_F(DataNodeTest, LeafNodeIsRecognizedAfterStoreAndLoad) {
|
||||
|
||||
TEST_F(DataNodeTest, InnerNodeIsRecognizedAfterStoreAndLoad) {
|
||||
auto block = blockStore->create(BlobStoreOnBlocks::BLOCKSIZE);
|
||||
string key = block.key;
|
||||
Key key = block.key;
|
||||
auto node = DataNode::initializeNewInnerNode(std::move(block.block));
|
||||
node->flush();
|
||||
|
||||
@ -64,7 +64,7 @@ TEST_F(DataNodeTest, InnerNodeIsRecognizedAfterStoreAndLoad) {
|
||||
|
||||
TEST_F(DataNodeTest, DataNodeCrashesOnLoadIfMagicNumberIsWrong) {
|
||||
auto block = blockStore->create(BlobStoreOnBlocks::BLOCKSIZE);
|
||||
string key = block.key;
|
||||
Key key = block.key;
|
||||
DataNode::NodeHeader* header = (DataNode::NodeHeader*)block.block->data();
|
||||
header->magicNumber = 0xFF; // this is an invalid magic number
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user