From da0efd80c5ca7aa89bb6294d861b1228f278bf9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Me=C3=9Fmer?= Date: Thu, 2 Apr 2015 02:59:43 -0400 Subject: [PATCH] Rename SynchronizedBlockStore -> CachingBlockStore --- .../CachedBlockRef.cpp | 8 +++--- .../CachedBlockRef.h | 8 +++--- .../CachingBlockStore.cpp} | 20 +++++++-------- .../CachingBlockStore.h} | 9 +++---- .../caching/CachingBlockStoreTest.cpp | 25 +++++++++++++++++++ .../SynchronizedBlockStoreTest.cpp | 23 ----------------- 6 files changed, 47 insertions(+), 46 deletions(-) rename implementations/{synchronized => caching}/CachedBlockRef.cpp (76%) rename implementations/{synchronized => caching}/CachedBlockRef.h (78%) rename implementations/{synchronized/SynchronizedBlockStore.cpp => caching/CachingBlockStore.cpp} (73%) rename implementations/{synchronized/SynchronizedBlockStore.h => caching/CachingBlockStore.h} (82%) create mode 100644 test/implementations/caching/CachingBlockStoreTest.cpp delete mode 100644 test/implementations/synchronized/SynchronizedBlockStoreTest.cpp diff --git a/implementations/synchronized/CachedBlockRef.cpp b/implementations/caching/CachedBlockRef.cpp similarity index 76% rename from implementations/synchronized/CachedBlockRef.cpp rename to implementations/caching/CachedBlockRef.cpp index d2d7bb59..927577ea 100644 --- a/implementations/synchronized/CachedBlockRef.cpp +++ b/implementations/caching/CachedBlockRef.cpp @@ -1,14 +1,14 @@ -#include "CachedBlockRef.h" -#include "SynchronizedBlockStore.h" +#include +#include using std::shared_ptr; using std::make_unique; using std::function; namespace blockstore { -namespace synchronized { +namespace caching { -CachedBlockRef::CachedBlockRef(Block *baseBlock, SynchronizedBlockStore *blockStore) +CachedBlockRef::CachedBlockRef(Block *baseBlock, CachingBlockStore *blockStore) //TODO We store key twice here - once in OpenBlock, once in the underlying baseBlock. // Should we move that to make CachedBlockRef::key() call _baseBlock.key()? :Block(baseBlock->key()), diff --git a/implementations/synchronized/CachedBlockRef.h b/implementations/caching/CachedBlockRef.h similarity index 78% rename from implementations/synchronized/CachedBlockRef.h rename to implementations/caching/CachedBlockRef.h index d48ebe11..c9077d49 100644 --- a/implementations/synchronized/CachedBlockRef.h +++ b/implementations/caching/CachedBlockRef.h @@ -8,12 +8,12 @@ #include namespace blockstore { -namespace synchronized { -class SynchronizedBlockStore; +namespace caching { +class CachingBlockStore; class CachedBlockRef: public Block { public: - CachedBlockRef(Block *baseBlock, SynchronizedBlockStore *blockStore); + CachedBlockRef(Block *baseBlock, CachingBlockStore *blockStore); virtual ~CachedBlockRef(); const void *data() const override; @@ -25,7 +25,7 @@ public: private: Block *_baseBlock; - SynchronizedBlockStore *_blockStore; + CachingBlockStore *_blockStore; DISALLOW_COPY_AND_ASSIGN(CachedBlockRef); }; diff --git a/implementations/synchronized/SynchronizedBlockStore.cpp b/implementations/caching/CachingBlockStore.cpp similarity index 73% rename from implementations/synchronized/SynchronizedBlockStore.cpp rename to implementations/caching/CachingBlockStore.cpp index f0984b2f..27bf51eb 100644 --- a/implementations/synchronized/SynchronizedBlockStore.cpp +++ b/implementations/caching/CachingBlockStore.cpp @@ -1,5 +1,5 @@ -#include "CachedBlockRef.h" -#include "SynchronizedBlockStore.h" +#include +#include #include using std::unique_ptr; @@ -10,26 +10,26 @@ using std::lock_guard; using std::promise; namespace blockstore { -namespace synchronized { +namespace caching { -SynchronizedBlockStore::SynchronizedBlockStore(unique_ptr baseBlockStore) +CachingBlockStore::CachingBlockStore(unique_ptr baseBlockStore) : _baseBlockStore(std::move(baseBlockStore)), _openBlocks() { } -unique_ptr SynchronizedBlockStore::create(size_t size) { +unique_ptr CachingBlockStore::create(size_t size) { auto block = _baseBlockStore->create(size); lock_guard lock(_mutex); return _addOpenBlock(std::move(block)); } -unique_ptr SynchronizedBlockStore::_addOpenBlock(unique_ptr block) { +unique_ptr CachingBlockStore::_addOpenBlock(unique_ptr block) { auto insertResult = _openBlocks.emplace(block->key(), std::move(block)); assert(true == insertResult.second); return make_unique(insertResult.first->second.getReference(), this); } -unique_ptr SynchronizedBlockStore::load(const Key &key) { +unique_ptr CachingBlockStore::load(const Key &key) { lock_guard lock(_mutex); auto found = _openBlocks.find(key); if (found == _openBlocks.end()) { @@ -43,7 +43,7 @@ unique_ptr SynchronizedBlockStore::load(const Key &key) { } } -void SynchronizedBlockStore::release(const Block *block) { +void CachingBlockStore::release(const Block *block) { lock_guard lock(_mutex); Key key = block->key(); auto found = _openBlocks.find(key); @@ -58,7 +58,7 @@ void SynchronizedBlockStore::release(const Block *block) { } } -void SynchronizedBlockStore::remove(unique_ptr block) { +void CachingBlockStore::remove(unique_ptr block) { auto insertResult = _blocksToRemove.emplace(block->key(), promise>()); assert(true == insertResult.second); block.reset(); @@ -69,7 +69,7 @@ void SynchronizedBlockStore::remove(unique_ptr block) { _baseBlockStore->remove(std::move(blockToRemove)); } -uint64_t SynchronizedBlockStore::numBlocks() const { +uint64_t CachingBlockStore::numBlocks() const { return _baseBlockStore->numBlocks(); } diff --git a/implementations/synchronized/SynchronizedBlockStore.h b/implementations/caching/CachingBlockStore.h similarity index 82% rename from implementations/synchronized/SynchronizedBlockStore.h rename to implementations/caching/CachingBlockStore.h index 74800a9f..dbfcc990 100644 --- a/implementations/synchronized/SynchronizedBlockStore.h +++ b/implementations/caching/CachingBlockStore.h @@ -11,12 +11,11 @@ #include "../../interface/BlockStore.h" namespace blockstore { -namespace synchronized { +namespace caching { -//TODO Rename to CachingBlockStore or something else -class SynchronizedBlockStore: public BlockStore { +class CachingBlockStore: public BlockStore { public: - SynchronizedBlockStore(std::unique_ptr baseBlockStore); + CachingBlockStore(std::unique_ptr baseBlockStore); std::unique_ptr create(size_t size) override; std::unique_ptr load(const Key &key) override; @@ -45,7 +44,7 @@ private: std::unique_ptr _addOpenBlock(std::unique_ptr block); - DISALLOW_COPY_AND_ASSIGN(SynchronizedBlockStore); + DISALLOW_COPY_AND_ASSIGN(CachingBlockStore); }; } diff --git a/test/implementations/caching/CachingBlockStoreTest.cpp b/test/implementations/caching/CachingBlockStoreTest.cpp new file mode 100644 index 00000000..de5e418c --- /dev/null +++ b/test/implementations/caching/CachingBlockStoreTest.cpp @@ -0,0 +1,25 @@ +#include "../../../implementations/caching/CachingBlockStore.h" +#include "../../../implementations/testfake/FakeBlockStore.h" +#include "../../testutils/BlockStoreTest.h" +#include "google/gtest/gtest.h" + + +using blockstore::BlockStore; +using blockstore::caching::CachingBlockStore; +using blockstore::testfake::FakeBlockStore; + +using std::unique_ptr; +using std::make_unique; + +class CachingBlockStoreTestFixture: public BlockStoreTestFixture { +public: + unique_ptr createBlockStore() override { + return make_unique(make_unique()); + } +}; + +INSTANTIATE_TYPED_TEST_CASE_P(Caching, BlockStoreTest, CachingBlockStoreTestFixture); + +//TODO Add specific tests ensuring that +// (a) loading the same block twice doesn't load it twice from the underlying blockstore +// (b) ... cache tests diff --git a/test/implementations/synchronized/SynchronizedBlockStoreTest.cpp b/test/implementations/synchronized/SynchronizedBlockStoreTest.cpp deleted file mode 100644 index c6334cc7..00000000 --- a/test/implementations/synchronized/SynchronizedBlockStoreTest.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "../../../implementations/synchronized/SynchronizedBlockStore.h" -#include "../../../implementations/testfake/FakeBlockStore.h" -#include "../../testutils/BlockStoreTest.h" -#include "google/gtest/gtest.h" - - -using blockstore::BlockStore; -using blockstore::synchronized::SynchronizedBlockStore; -using blockstore::testfake::FakeBlockStore; - -using std::unique_ptr; -using std::make_unique; - -class SynchronizedBlockStoreTestFixture: public BlockStoreTestFixture { -public: - unique_ptr createBlockStore() override { - return make_unique(make_unique()); - } -}; - -INSTANTIATE_TYPED_TEST_CASE_P(Synchronized, BlockStoreTest, SynchronizedBlockStoreTestFixture); - -//TODO Add specific tests ensuring that the access to the underlying blockstore is synchronized