Fix test cases
This commit is contained in:
parent
0e1ec6829a
commit
92d0d073a5
4
implementations/caching/cache/QueueMap.h
vendored
4
implementations/caching/cache/QueueMap.h
vendored
@ -26,7 +26,9 @@ public:
|
|||||||
|
|
||||||
void push(const Key &key, Value value) {
|
void push(const Key &key, Value value) {
|
||||||
auto newEntry = _entries.emplace(std::piecewise_construct, std::forward_as_tuple(key), std::forward_as_tuple(_sentinel.prev, &_sentinel));
|
auto newEntry = _entries.emplace(std::piecewise_construct, std::forward_as_tuple(key), std::forward_as_tuple(_sentinel.prev, &_sentinel));
|
||||||
ASSERT(newEntry.second == true, "There is already an element with this key");
|
if (!newEntry.second) {
|
||||||
|
throw std::logic_error("There is already an element with this key");
|
||||||
|
}
|
||||||
newEntry.first->second.init(&newEntry.first->first, std::move(value));
|
newEntry.first->second.init(&newEntry.first->first, std::move(value));
|
||||||
//The following is ok, because std::unordered_map never invalidates pointers to its entries
|
//The following is ok, because std::unordered_map never invalidates pointers to its entries
|
||||||
_sentinel.prev->next = &newEntry.first->second;
|
_sentinel.prev->next = &newEntry.first->second;
|
||||||
|
@ -15,6 +15,8 @@ namespace ondisk {
|
|||||||
OnDiskBlockStore::OnDiskBlockStore(const boost::filesystem::path &rootdir)
|
OnDiskBlockStore::OnDiskBlockStore(const boost::filesystem::path &rootdir)
|
||||||
: _rootdir(rootdir) {}
|
: _rootdir(rootdir) {}
|
||||||
|
|
||||||
|
//TODO Do I have to lock tryCreate/remove and/or load? Or does ParallelAccessBlockStore take care of that?
|
||||||
|
|
||||||
optional<unique_ref<Block>> OnDiskBlockStore::tryCreate(const Key &key, Data data) {
|
optional<unique_ref<Block>> OnDiskBlockStore::tryCreate(const Key &key, Data data) {
|
||||||
//TODO Easier implementation? This is only so complicated because of the cast OnDiskBlock -> Block
|
//TODO Easier implementation? This is only so complicated because of the cast OnDiskBlock -> Block
|
||||||
auto result = std::move(OnDiskBlock::CreateOnDisk(_rootdir, key, std::move(data)));
|
auto result = std::move(OnDiskBlock::CreateOnDisk(_rootdir, key, std::move(data)));
|
||||||
|
@ -19,6 +19,7 @@ FakeBlockStore::FakeBlockStore()
|
|||||||
: _blocks(), _used_dataregions_for_blocks() {}
|
: _blocks(), _used_dataregions_for_blocks() {}
|
||||||
|
|
||||||
optional<unique_ref<Block>> FakeBlockStore::tryCreate(const Key &key, Data data) {
|
optional<unique_ref<Block>> FakeBlockStore::tryCreate(const Key &key, Data data) {
|
||||||
|
std::unique_lock<std::mutex> lock(_mutex);
|
||||||
auto insert_result = _blocks.emplace(key.ToString(), std::move(data));
|
auto insert_result = _blocks.emplace(key.ToString(), std::move(data));
|
||||||
|
|
||||||
if (!insert_result.second) {
|
if (!insert_result.second) {
|
||||||
@ -26,10 +27,15 @@ optional<unique_ref<Block>> FakeBlockStore::tryCreate(const Key &key, Data data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Return a copy of the stored data
|
//Return a copy of the stored data
|
||||||
return load(key);
|
return _load(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
optional<unique_ref<Block>> FakeBlockStore::load(const Key &key) {
|
optional<unique_ref<Block>> FakeBlockStore::load(const Key &key) {
|
||||||
|
std::unique_lock<std::mutex> lock(_mutex);
|
||||||
|
return _load(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
optional<unique_ref<Block>> FakeBlockStore::_load(const Key &key) {
|
||||||
//Return a copy of the stored data
|
//Return a copy of the stored data
|
||||||
string key_string = key.ToString();
|
string key_string = key.ToString();
|
||||||
try {
|
try {
|
||||||
@ -42,6 +48,7 @@ optional<unique_ref<Block>> FakeBlockStore::load(const Key &key) {
|
|||||||
void FakeBlockStore::remove(unique_ref<Block> block) {
|
void FakeBlockStore::remove(unique_ref<Block> block) {
|
||||||
Key key = block->key();
|
Key key = block->key();
|
||||||
cpputils::destruct(std::move(block));
|
cpputils::destruct(std::move(block));
|
||||||
|
std::unique_lock<std::mutex> lock(_mutex);
|
||||||
int numRemoved = _blocks.erase(key.ToString());
|
int numRemoved = _blocks.erase(key.ToString());
|
||||||
ASSERT(numRemoved == 1, "Block not found");
|
ASSERT(numRemoved == 1, "Block not found");
|
||||||
}
|
}
|
||||||
@ -53,6 +60,7 @@ unique_ref<Block> FakeBlockStore::makeFakeBlockFromData(const Key &key, const Da
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FakeBlockStore::updateData(const Key &key, const Data &data) {
|
void FakeBlockStore::updateData(const Key &key, const Data &data) {
|
||||||
|
std::unique_lock<std::mutex> lock(_mutex);
|
||||||
auto found = _blocks.find(key.ToString());
|
auto found = _blocks.find(key.ToString());
|
||||||
if (found == _blocks.end()) {
|
if (found == _blocks.end()) {
|
||||||
auto insertResult = _blocks.emplace(key.ToString(), data.copy());
|
auto insertResult = _blocks.emplace(key.ToString(), data.copy());
|
||||||
@ -65,6 +73,7 @@ void FakeBlockStore::updateData(const Key &key, const Data &data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint64_t FakeBlockStore::numBlocks() const {
|
uint64_t FakeBlockStore::numBlocks() const {
|
||||||
|
std::unique_lock<std::mutex> lock(_mutex);
|
||||||
return _blocks.size();
|
return _blocks.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,10 @@ private:
|
|||||||
//We want to avoid this for the reasons mentioned above (overflow data).
|
//We want to avoid this for the reasons mentioned above (overflow data).
|
||||||
std::vector<std::shared_ptr<cpputils::Data>> _used_dataregions_for_blocks;
|
std::vector<std::shared_ptr<cpputils::Data>> _used_dataregions_for_blocks;
|
||||||
|
|
||||||
|
mutable std::mutex _mutex;
|
||||||
|
|
||||||
cpputils::unique_ref<Block> makeFakeBlockFromData(const Key &key, const cpputils::Data &data, bool dirty);
|
cpputils::unique_ref<Block> makeFakeBlockFromData(const Key &key, const cpputils::Data &data, bool dirty);
|
||||||
|
boost::optional<cpputils::unique_ref<Block>> _load(const Key &key);
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(FakeBlockStore);
|
DISALLOW_COPY_AND_ASSIGN(FakeBlockStore);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user