diff --git a/biicode.conf b/biicode.conf index 017c222c..b92f1d3a 100644 --- a/biicode.conf +++ b/biicode.conf @@ -4,6 +4,7 @@ google/gmock: 2 google/gtest: 10 messmer/blockstore: 1 + messmer/cachingstore: 0 messmer/cmake: 3 messmer/cpp-utils: 2 diff --git a/implementations/onblocks/BlobOnBlocks.cpp b/implementations/onblocks/BlobOnBlocks.cpp index 94e1fc64..45a98369 100644 --- a/implementations/onblocks/BlobOnBlocks.cpp +++ b/implementations/onblocks/BlobOnBlocks.cpp @@ -1,6 +1,6 @@ #include "BlobOnBlocks.h" -#include "datatreestore/DataTree.h" +#include "cachingdatatreestore/CachedDataTreeRef.h" #include "datanodestore/DataLeafNode.h" #include "utils/Math.h" #include @@ -14,9 +14,9 @@ using blockstore::Key; namespace blobstore { namespace onblocks { -using datatreestore::DataTree; +using cachingdatatreestore::CachedDataTreeRef; -BlobOnBlocks::BlobOnBlocks(unique_ptr datatree) +BlobOnBlocks::BlobOnBlocks(unique_ptr datatree) : _datatree(std::move(datatree)) { } @@ -79,7 +79,7 @@ Key BlobOnBlocks::key() const { return _datatree->key(); } -unique_ptr BlobOnBlocks::releaseTree() { +unique_ptr BlobOnBlocks::releaseTree() { return std::move(_datatree); } diff --git a/implementations/onblocks/BlobOnBlocks.h b/implementations/onblocks/BlobOnBlocks.h index ed5f3f44..bcc2f124 100644 --- a/implementations/onblocks/BlobOnBlocks.h +++ b/implementations/onblocks/BlobOnBlocks.h @@ -11,13 +11,13 @@ namespace onblocks { namespace datanodestore { class DataLeafNode; } -namespace datatreestore { -class DataTree; +namespace cachingdatatreestore { +class CachedDataTreeRef; } class BlobOnBlocks: public Blob { public: - BlobOnBlocks(std::unique_ptr datatree); + BlobOnBlocks(std::unique_ptr datatree); virtual ~BlobOnBlocks(); blockstore::Key key() const override; @@ -29,14 +29,14 @@ public: uint64_t tryRead(void *target, uint64_t offset, uint64_t size) const override; void write(const void *source, uint64_t offset, uint64_t size) override; - std::unique_ptr releaseTree(); + std::unique_ptr releaseTree(); private: void traverseLeaves(uint64_t offsetBytes, uint64_t sizeBytes, std::function) const; void resizeIfSmallerThan(uint64_t neededSize); - std::unique_ptr _datatree; + std::unique_ptr _datatree; }; } diff --git a/implementations/onblocks/BlobStoreOnBlocks.cpp b/implementations/onblocks/BlobStoreOnBlocks.cpp index b3465bf8..da536c1f 100644 --- a/implementations/onblocks/BlobStoreOnBlocks.cpp +++ b/implementations/onblocks/BlobStoreOnBlocks.cpp @@ -3,6 +3,8 @@ #include "datanodestore/DataNodeStore.h" #include "datatreestore/DataTreeStore.h" #include "datatreestore/DataTree.h" +#include "cachingdatatreestore/CachingDataTreeStore.h" +#include "cachingdatatreestore/CachedDataTreeRef.h" #include "BlobStoreOnBlocks.h" #include "BlobOnBlocks.h" #include @@ -20,9 +22,10 @@ namespace onblocks { using datanodestore::DataNodeStore; using datatreestore::DataTreeStore; +using cachingdatatreestore::CachingDataTreeStore; BlobStoreOnBlocks::BlobStoreOnBlocks(unique_ptr blockStore, uint32_t blocksizeBytes) -: _dataTreeStore(make_unique(make_unique(make_unique(std::move(blockStore)), blocksizeBytes))) { +: _dataTreeStore(make_unique(make_unique(make_unique(make_unique(std::move(blockStore)), blocksizeBytes)))) { } BlobStoreOnBlocks::~BlobStoreOnBlocks() { diff --git a/implementations/onblocks/BlobStoreOnBlocks.h b/implementations/onblocks/BlobStoreOnBlocks.h index 6ea4721e..0b970278 100644 --- a/implementations/onblocks/BlobStoreOnBlocks.h +++ b/implementations/onblocks/BlobStoreOnBlocks.h @@ -7,8 +7,8 @@ namespace blobstore { namespace onblocks { -namespace datatreestore { -class DataTreeStore; +namespace cachingdatatreestore { +class CachingDataTreeStore; } class BlobStoreOnBlocks: public BlobStore { @@ -22,7 +22,7 @@ public: void remove(std::unique_ptr blob) override; private: - std::unique_ptr _dataTreeStore; + std::unique_ptr _dataTreeStore; }; } diff --git a/implementations/onblocks/cachingdatatreestore/CachedDataTreeRef.cpp b/implementations/onblocks/cachingdatatreestore/CachedDataTreeRef.cpp new file mode 100644 index 00000000..e2207424 --- /dev/null +++ b/implementations/onblocks/cachingdatatreestore/CachedDataTreeRef.cpp @@ -0,0 +1 @@ +#include "CachedDataTreeRef.h" diff --git a/implementations/onblocks/cachingdatatreestore/CachedDataTreeRef.h b/implementations/onblocks/cachingdatatreestore/CachedDataTreeRef.h new file mode 100644 index 00000000..f0347147 --- /dev/null +++ b/implementations/onblocks/cachingdatatreestore/CachedDataTreeRef.h @@ -0,0 +1,47 @@ +#pragma once +#ifndef MESSMER_BLOBSTORE_IMPLEMENTATIONS_ONBLOCKS_CACHINGDATATREESTORE_DATATREEREF_H_ +#define MESSMER_BLOBSTORE_IMPLEMENTATIONS_ONBLOCKS_CACHINGDATATREESTORE_DATATREEREF_H_ + +#include "../datatreestore/DataTree.h" +#include + +namespace blobstore { +namespace onblocks { +namespace cachingdatatreestore { + +class CachedDataTreeRef: public cachingstore::CachingStore::CachedResource { +public: + CachedDataTreeRef(datatreestore::DataTree *baseTree): _baseTree(baseTree) {} + + const blockstore::Key &key() const { + return _baseTree->key(); + } + + uint32_t maxBytesPerLeaf() const { + return _baseTree->maxBytesPerLeaf(); + } + + void traverseLeaves(uint32_t beginIndex, uint32_t endIndex, std::function func) const { + return const_cast(_baseTree)->traverseLeaves(beginIndex, endIndex, func); + } + + void traverseLeaves(uint32_t beginIndex, uint32_t endIndex, std::function func) { + return _baseTree->traverseLeaves(beginIndex, endIndex, func); + } + + void resizeNumBytes(uint64_t newNumBytes) { + return _baseTree->resizeNumBytes(newNumBytes); + } + + uint64_t numStoredBytes() const { + return _baseTree->numStoredBytes(); + } +private: + datatreestore::DataTree *_baseTree; +}; + +} +} +} + +#endif diff --git a/implementations/onblocks/cachingdatatreestore/CachingDataTreeStore.cpp b/implementations/onblocks/cachingdatatreestore/CachingDataTreeStore.cpp new file mode 100644 index 00000000..00d3caad --- /dev/null +++ b/implementations/onblocks/cachingdatatreestore/CachingDataTreeStore.cpp @@ -0,0 +1,43 @@ +#include "CachingDataTreeStore.h" +#include "../datanodestore/DataNodeStore.h" +#include "../datanodestore/DataLeafNode.h" +#include "CachingDataTreeStoreAdapter.h" +#include "CachedDataTreeRef.h" + +using std::unique_ptr; +using std::make_unique; + +using blobstore::onblocks::datatreestore::DataTreeStore; +using blockstore::Key; + +namespace blobstore { +namespace onblocks { +using datatreestore::DataTreeStore; +using datatreestore::DataTree; +namespace cachingdatatreestore { + +CachingDataTreeStore::CachingDataTreeStore(unique_ptr dataTreeStore) + : _dataTreeStore(std::move(dataTreeStore)), _cachingStore(make_unique(_dataTreeStore.get())) { +} + +CachingDataTreeStore::~CachingDataTreeStore() { +} + +unique_ptr CachingDataTreeStore::load(const blockstore::Key &key) { + return _cachingStore.load(key); +} + +unique_ptr CachingDataTreeStore::createNewTree() { + auto dataTree = _dataTreeStore->createNewTree(); + Key key = dataTree->key(); + return _cachingStore.add(key, std::move(dataTree)); +} + +void CachingDataTreeStore::remove(unique_ptr tree) { + Key key = tree->key(); + return _cachingStore.remove(key, std::move(tree)); +} + +} +} +} diff --git a/implementations/onblocks/cachingdatatreestore/CachingDataTreeStore.h b/implementations/onblocks/cachingdatatreestore/CachingDataTreeStore.h new file mode 100644 index 00000000..aa66dabf --- /dev/null +++ b/implementations/onblocks/cachingdatatreestore/CachingDataTreeStore.h @@ -0,0 +1,43 @@ +#pragma once +#ifndef BLOBSTORE_IMPLEMENTATIONS_ONBLOCKS_CACHINGDATATREESTORE_CACHINGDATATREESTORE_H_ +#define BLOBSTORE_IMPLEMENTATIONS_ONBLOCKS_CACHINGDATATREESTORE_CACHINGDATATREESTORE_H_ + +#include +#include +#include + +namespace blockstore{ +class Key; +} +namespace blobstore { +namespace onblocks { +namespace datatreestore { +class DataTreeStore; +class DataTree; +} +namespace cachingdatatreestore { +class CachedDataTreeRef; + +class CachingDataTreeStore { +public: + CachingDataTreeStore(std::unique_ptr dataTreeStore); + virtual ~CachingDataTreeStore(); + + std::unique_ptr load(const blockstore::Key &key); + + std::unique_ptr createNewTree(); + + void remove(std::unique_ptr tree); + +private: + std::unique_ptr _dataTreeStore; + cachingstore::CachingStore _cachingStore; + + DISALLOW_COPY_AND_ASSIGN(CachingDataTreeStore); +}; + +} +} +} + +#endif diff --git a/implementations/onblocks/cachingdatatreestore/CachingDataTreeStoreAdapter.cpp b/implementations/onblocks/cachingdatatreestore/CachingDataTreeStoreAdapter.cpp new file mode 100644 index 00000000..8e7ed20d --- /dev/null +++ b/implementations/onblocks/cachingdatatreestore/CachingDataTreeStoreAdapter.cpp @@ -0,0 +1 @@ +#include "CachingDataTreeStoreAdapter.h" diff --git a/implementations/onblocks/cachingdatatreestore/CachingDataTreeStoreAdapter.h b/implementations/onblocks/cachingdatatreestore/CachingDataTreeStoreAdapter.h new file mode 100644 index 00000000..3aaeb86e --- /dev/null +++ b/implementations/onblocks/cachingdatatreestore/CachingDataTreeStoreAdapter.h @@ -0,0 +1,37 @@ +#ifndef MESSMER_BLOBSTORE_IMPLEMENTATIONS_ONBLOCKS_CACHINGDATATREESTORE_CACHINGDATATREESTOREADAPTER_H_ +#define MESSMER_BLOBSTORE_IMPLEMENTATIONS_ONBLOCKS_CACHINGDATATREESTORE_CACHINGDATATREESTOREADAPTER_H_ + +#include +#include +#include "../datatreestore/DataTreeStore.h" +#include "../datatreestore/DataTree.h" + +namespace blobstore { +namespace onblocks { +namespace cachingdatatreestore { + +class CachingDataTreeStoreAdapter: public cachingstore::CachingBaseStore { +public: + CachingDataTreeStoreAdapter(datatreestore::DataTreeStore *baseDataTreeStore) + :_baseDataTreeStore(std::move(baseDataTreeStore)) { + } + + std::unique_ptr loadFromBaseStore(const blockstore::Key &key) override { + return _baseDataTreeStore->load(key); + } + + void removeFromBaseStore(std::unique_ptr dataTree) override { + return _baseDataTreeStore->remove(std::move(dataTree)); + } + +private: + datatreestore::DataTreeStore *_baseDataTreeStore; + + DISALLOW_COPY_AND_ASSIGN(CachingDataTreeStoreAdapter); +}; + +} +} +} + +#endif diff --git a/implementations/onblocks/datatreestore/DataTreeStore.h b/implementations/onblocks/datatreestore/DataTreeStore.h index b40f23b2..02772aab 100644 --- a/implementations/onblocks/datatreestore/DataTreeStore.h +++ b/implementations/onblocks/datatreestore/DataTreeStore.h @@ -3,7 +3,7 @@ #define BLOBSTORE_IMPLEMENTATIONS_ONBLOCKS_DATATREESTORE_DATATREESTORE_H_ #include -#include "messmer/cpp-utils/macros.h" +#include namespace blockstore{ class Key;