Renamed old Caching2BlockStore to new CachingBlockStore

This commit is contained in:
Sebastian Messmer 2015-04-16 14:10:44 +02:00
parent 248fd0f5cc
commit 9fa6b041eb
12 changed files with 38 additions and 37 deletions

View File

@ -7,7 +7,7 @@ using std::lock_guard;
using std::pair;
namespace blockstore {
namespace caching2 {
namespace caching {
constexpr uint32_t Cache::MAX_ENTRIES;

View File

@ -1,15 +1,15 @@
#pragma once
#ifndef MESSMER_BLOCKSTORE_IMPLEMENTATIONS_CACHING2_CACHE_H_
#define MESSMER_BLOCKSTORE_IMPLEMENTATIONS_CACHING2_CACHE_H_
#ifndef MESSMER_BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHE_H_
#define MESSMER_BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHE_H_
#include "../../interface/Block.h"
#include "CacheEntry.h"
#include "QueueMap.h"
#include "../../interface/Block.h"
#include <memory>
#include <mutex>
namespace blockstore {
namespace caching2 {
namespace caching {
//TODO Test
//TODO Also throw blocks out after a timeout

View File

@ -1,6 +1,6 @@
#pragma once
#ifndef MESSMER_BLOCKSTORE_IMPLEMENTATIONS_CACHING2_CACHEENTRY_H_
#define MESSMER_BLOCKSTORE_IMPLEMENTATIONS_CACHING2_CACHEENTRY_H_
#ifndef MESSMER_BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHEENTRY_H_
#define MESSMER_BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHEENTRY_H_
#include <ctime>
#include <memory>
@ -8,7 +8,7 @@
namespace blockstore {
class Block;
namespace caching2 {
namespace caching {
class CacheEntry {
public:

View File

@ -1,13 +1,13 @@
#include "CachedBlock.h"
#include "Caching2BlockStore.h"
#include "CachingBlockStore.h"
using std::unique_ptr;
using std::make_unique;
namespace blockstore {
namespace caching2 {
namespace caching {
CachedBlock::CachedBlock(std::unique_ptr<Block> baseBlock, Caching2BlockStore *blockStore)
CachedBlock::CachedBlock(std::unique_ptr<Block> baseBlock, CachingBlockStore *blockStore)
:Block(baseBlock->key()),
_blockStore(blockStore),
_baseBlock(std::move(baseBlock)) {

View File

@ -8,13 +8,13 @@
#include <memory>
namespace blockstore {
namespace caching2 {
class Caching2BlockStore;
namespace caching {
class CachingBlockStore;
class CachedBlock: public Block {
public:
//TODO Storing key twice (in parent class and in object pointed to). Once would be enough.
CachedBlock(std::unique_ptr<Block> baseBlock, Caching2BlockStore *blockStore);
CachedBlock(std::unique_ptr<Block> baseBlock, CachingBlockStore *blockStore);
virtual ~CachedBlock();
const void *data() const override;
@ -27,7 +27,7 @@ public:
std::unique_ptr<Block> releaseBlock();
private:
Caching2BlockStore *_blockStore;
CachingBlockStore *_blockStore;
std::unique_ptr<Block> _baseBlock;
DISALLOW_COPY_AND_ASSIGN(CachedBlock);

View File

@ -1,5 +1,5 @@
#include "Caching2BlockStore.h"
#include "CachedBlock.h"
#include "CachingBlockStore.h"
#include "../../interface/Block.h"
#include <algorithm>
@ -10,13 +10,13 @@ using std::make_unique;
using cpputils::dynamic_pointer_move;
namespace blockstore {
namespace caching2 {
namespace caching {
Caching2BlockStore::Caching2BlockStore(std::unique_ptr<BlockStore> baseBlockStore)
CachingBlockStore::CachingBlockStore(std::unique_ptr<BlockStore> baseBlockStore)
:_baseBlockStore(std::move(baseBlockStore)) {
}
unique_ptr<Block> Caching2BlockStore::create(size_t size) {
unique_ptr<Block> CachingBlockStore::create(size_t size) {
//TODO Also cache this and only write back in the destructor?
// When writing back is done efficiently in the base store (e.g. only one safe-to-disk, not one in the create() and then one in the save(), this is not supported by the current BlockStore interface),
// then the base store could actually directly create a block in the create() call, OnDiskBlockStore wouldn't have to avoid file creation in the create() call for performance reasons and I could also adapt the OnDiskBlockStore test cases and remove a lot of flush() calls there because then blocks are loadable directly after the create call() without a flush.
@ -24,7 +24,7 @@ unique_ptr<Block> Caching2BlockStore::create(size_t size) {
return make_unique<CachedBlock>(_baseBlockStore->create(size), this);
}
unique_ptr<Block> Caching2BlockStore::load(const Key &key) {
unique_ptr<Block> CachingBlockStore::load(const Key &key) {
auto block = _cache.pop(key);
if (block.get() != nullptr) {
return make_unique<CachedBlock>(std::move(block), this);
@ -36,15 +36,15 @@ unique_ptr<Block> Caching2BlockStore::load(const Key &key) {
return make_unique<CachedBlock>(std::move(block), this);
}
void Caching2BlockStore::remove(std::unique_ptr<Block> block) {
void CachingBlockStore::remove(std::unique_ptr<Block> block) {
return _baseBlockStore->remove(std::move(dynamic_pointer_move<CachedBlock>(block)->releaseBlock()));
}
uint64_t Caching2BlockStore::numBlocks() const {
uint64_t CachingBlockStore::numBlocks() const {
return _baseBlockStore->numBlocks();
}
void Caching2BlockStore::release(unique_ptr<Block> block) {
void CachingBlockStore::release(unique_ptr<Block> block) {
_cache.push(std::move(block));
}

View File

@ -1,18 +1,18 @@
#pragma once
#ifndef BLOCKSTORE_IMPLEMENTATIONS_CACHING2_CACHINGBLOCKSTORE_H_
#define BLOCKSTORE_IMPLEMENTATIONS_CACHING2_CACHINGBLOCKSTORE_H_
#ifndef BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHINGBLOCKSTORE_H_
#define BLOCKSTORE_IMPLEMENTATIONS_CACHING_CACHINGBLOCKSTORE_H_
#include "../../interface/BlockStore.h"
#include "Cache.h"
#include "../../interface/BlockStore.h"
namespace blockstore {
namespace caching2 {
namespace caching {
//TODO Rename this to CachingBlockStore and the other one to something else
//TODO Check that this blockstore allows parallel destructing of blocks (otherwise we won't encrypt blocks in parallel)
class Caching2BlockStore: public BlockStore {
class CachingBlockStore: public BlockStore {
public:
Caching2BlockStore(std::unique_ptr<BlockStore> baseBlockStore);
CachingBlockStore(std::unique_ptr<BlockStore> baseBlockStore);
std::unique_ptr<Block> create(size_t size) override;
std::unique_ptr<Block> load(const Key &key) override;
@ -25,7 +25,7 @@ private:
std::unique_ptr<BlockStore> _baseBlockStore;
Cache _cache;
DISALLOW_COPY_AND_ASSIGN(Caching2BlockStore);
DISALLOW_COPY_AND_ASSIGN(CachingBlockStore);
};
}

View File

@ -4,9 +4,10 @@
#include <memory>
#include <map>
#include <cassert>
namespace blockstore {
namespace caching2 {
namespace caching {
//TODO Test
//TODO Move to utils

View File

@ -1,23 +1,23 @@
#include "../../../implementations/caching2/Caching2BlockStore.h"
#include "../../../implementations/caching/CachingBlockStore.h"
#include "../../../implementations/testfake/FakeBlockStore.h"
#include "../../testutils/BlockStoreTest.h"
#include "google/gtest/gtest.h"
using blockstore::BlockStore;
using blockstore::caching2::Caching2BlockStore;
using blockstore::caching::CachingBlockStore;
using blockstore::testfake::FakeBlockStore;
using std::unique_ptr;
using std::make_unique;
class Caching2BlockStoreTestFixture: public BlockStoreTestFixture {
class CachingBlockStoreTestFixture: public BlockStoreTestFixture {
public:
unique_ptr<BlockStore> createBlockStore() override {
return make_unique<Caching2BlockStore>(make_unique<FakeBlockStore>());
return make_unique<CachingBlockStore>(make_unique<FakeBlockStore>());
}
};
INSTANTIATE_TYPED_TEST_CASE_P(Caching2, BlockStoreTest, Caching2BlockStoreTestFixture);
INSTANTIATE_TYPED_TEST_CASE_P(Caching, BlockStoreTest, CachingBlockStoreTestFixture);
//TODO Add specific tests for the blockstore

View File

@ -18,6 +18,6 @@ public:
}
};
INSTANTIATE_TYPED_TEST_CASE_P(Caching, BlockStoreTest, ParallelAccessBlockStoreTestFixture);
INSTANTIATE_TYPED_TEST_CASE_P(ParallelAccess, BlockStoreTest, ParallelAccessBlockStoreTestFixture);
//TODO Add specific tests ensuring that loading the same block twice doesn't load it twice from the underlying blockstore