Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
Signed-off-by: iceseer <iceseer@gmail.com>
  • Loading branch information
iceseer committed Jun 23, 2022
1 parent 2589298 commit d5b0ee8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
34 changes: 20 additions & 14 deletions irohad/ametsuchi/impl/database_cache/cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
#define AMETSUCHI_DATABASE_CACHE_HPP

#include <algorithm>
#include <deque>
#include <string>
#include <unordered_map>
#include <vector>
#include <deque>

#include "common/common.hpp"
#include "common/radix_tree.hpp"
Expand All @@ -32,7 +32,8 @@ namespace iroha::ametsuchi {
/// Should be merged from X = N to X = 0.
/// std::optional represents that value can be deleted.
/// Uses stack representation of layers.
std::deque<std::unique_ptr<iroha::RadixTree<std::optional<Type>>>> intermediate_cache_;
std::deque<std::unique_ptr<iroha::RadixTree<std::optional<Type>>>>
intermediate_cache_;

auto cachebleSearch(std::string_view key) const {
auto it = std::lower_bound(
Expand All @@ -49,7 +50,8 @@ namespace iroha::ametsuchi {
}

void pushLayer() {
intermediate_cache_.emplace_back(std::make_unique<iroha::RadixTree<std::optional<Type>>>());
intermediate_cache_.emplace_back(
std::make_unique<iroha::RadixTree<std::optional<Type>>>());
}

/// Remove last layer except first one.
Expand All @@ -63,14 +65,11 @@ namespace iroha::ametsuchi {
pushLayer();
}

void mergeMove(
std::unique_ptr<iroha::RadixTree<std::optional<Type>>> &from,
std::unique_ptr<iroha::RadixTree<std::optional<Type>>> &to
) {
void mergeMove(std::unique_ptr<iroha::RadixTree<std::optional<Type>>> &from,
std::unique_ptr<iroha::RadixTree<std::optional<Type>>> &to) {
from->filterEnumerate(
nullptr, 0ul, [&](std::string_view key, std::optional<Type> *value) {
to->template insert(
key.data(), key.size(), std::move(*value));
to->template insert(key.data(), key.size(), std::move(*value));
});
}

Expand Down Expand Up @@ -109,7 +108,9 @@ namespace iroha::ametsuchi {
checkStates();

/// Search in intermediate layers at first
for (auto it = intermediate_cache_.rbegin(); it != intermediate_cache_.rend(); ++it)
for (auto it = intermediate_cache_.rbegin();
it != intermediate_cache_.rend();
++it)
if (auto *ptr = (*it)->find(key.data(), key.size()))
return *ptr ? std::forward<Func>(func)(**ptr) : false;

Expand All @@ -127,7 +128,8 @@ namespace iroha::ametsuchi {
assert(isCacheable(key));

/// insert to the last layer.
intermediate_cache_.back()->template insert(key.data(), key.size(), value);
intermediate_cache_.back()->template insert(
key.data(), key.size(), value);
}

void setCommit(std::string_view key, std::string_view const &value) {
Expand All @@ -138,7 +140,8 @@ namespace iroha::ametsuchi {
assert(c->find(key.data(), key.size()) == nullptr);
}

/// Since this data is present in database, we store it directly in database representation.
/// Since this data is present in database, we store it directly in
/// database representation.
db_representation_cache_->template insert(key.data(), key.size(), value);
}

Expand All @@ -148,7 +151,8 @@ namespace iroha::ametsuchi {
assert(isCacheable(key));

/// Insert erase state in last layer.
return intermediate_cache_.back()->template insert(key.data(), key.size(), std::nullopt);
return intermediate_cache_.back()->template insert(
key.data(), key.size(), std::nullopt);
}

void filterDelete(std::string_view filter) {
Expand Down Expand Up @@ -215,7 +219,9 @@ namespace iroha::ametsuchi {
/// Commits all data from intermediate layers to DB representation
for (auto &it : intermediate_cache_)
it->filterEnumerate(
nullptr, 0ul, [&](std::string_view key, std::optional<Type> *value) {
nullptr,
0ul,
[&](std::string_view key, std::optional<Type> *value) {
if (*value)
db_representation_cache_->template insert(
key.data(), key.size(), std::move(**value));
Expand Down
12 changes: 5 additions & 7 deletions test/module/irohad/ametsuchi/rocksdb_common_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,14 @@ class RocksDBTest : public ::testing::Test {
std::string const value5_ = "vaLUe5";
};

#define KEY_EXIST_WITH_VALUE(K,V) \
ASSERT_TRUE(dbc.get(K, [](auto const &value){ \
assert(value == V); \
return true; \
#define KEY_EXIST_WITH_VALUE(K, V) \
ASSERT_TRUE(dbc.get(K, [](auto const &value) { \
assert(value == V); \
return true; \
}))

#define KEY_NOT_EXIST(K) \
ASSERT_FALSE(dbc.get(K, [](auto const &){ \
return true; \
}))
ASSERT_FALSE(dbc.get(K, [](auto const &) { return true; }))

TEST_F(RocksDBTest, DatabaseCacheSimpleTest) {
iroha::ametsuchi::DatabaseCache<std::string> dbc;
Expand Down

0 comments on commit d5b0ee8

Please sign in to comment.