From d5b0ee8d2d37e14a0ad7f4ad54906291fb62a73f Mon Sep 17 00:00:00 2001 From: iceseer Date: Thu, 23 Jun 2022 10:46:53 +0300 Subject: [PATCH] formatting Signed-off-by: iceseer --- .../ametsuchi/impl/database_cache/cache.hpp | 34 +++++++++++-------- .../irohad/ametsuchi/rocksdb_common_test.cpp | 12 +++---- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/irohad/ametsuchi/impl/database_cache/cache.hpp b/irohad/ametsuchi/impl/database_cache/cache.hpp index 4534f1ae3c4..50f17861bee 100644 --- a/irohad/ametsuchi/impl/database_cache/cache.hpp +++ b/irohad/ametsuchi/impl/database_cache/cache.hpp @@ -7,10 +7,10 @@ #define AMETSUCHI_DATABASE_CACHE_HPP #include +#include #include #include #include -#include #include "common/common.hpp" #include "common/radix_tree.hpp" @@ -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>>> intermediate_cache_; + std::deque>>> + intermediate_cache_; auto cachebleSearch(std::string_view key) const { auto it = std::lower_bound( @@ -49,7 +50,8 @@ namespace iroha::ametsuchi { } void pushLayer() { - intermediate_cache_.emplace_back(std::make_unique>>()); + intermediate_cache_.emplace_back( + std::make_unique>>()); } /// Remove last layer except first one. @@ -63,14 +65,11 @@ namespace iroha::ametsuchi { pushLayer(); } - void mergeMove( - std::unique_ptr>> &from, - std::unique_ptr>> &to - ) { + void mergeMove(std::unique_ptr>> &from, + std::unique_ptr>> &to) { from->filterEnumerate( nullptr, 0ul, [&](std::string_view key, std::optional *value) { - to->template insert( - key.data(), key.size(), std::move(*value)); + to->template insert(key.data(), key.size(), std::move(*value)); }); } @@ -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)(**ptr) : false; @@ -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) { @@ -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); } @@ -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) { @@ -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 *value) { + nullptr, + 0ul, + [&](std::string_view key, std::optional *value) { if (*value) db_representation_cache_->template insert( key.data(), key.size(), std::move(**value)); diff --git a/test/module/irohad/ametsuchi/rocksdb_common_test.cpp b/test/module/irohad/ametsuchi/rocksdb_common_test.cpp index 645fa0c3313..ac039af945b 100644 --- a/test/module/irohad/ametsuchi/rocksdb_common_test.cpp +++ b/test/module/irohad/ametsuchi/rocksdb_common_test.cpp @@ -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 dbc;