From 3e0bf7dd25d77f6d45dfa4551c34d46266eb9c7a Mon Sep 17 00:00:00 2001 From: zztaki Date: Thu, 28 Dec 2023 00:08:22 +0800 Subject: [PATCH 1/2] Nit(tests): add some tests to pass CI Signed-off-by: zztaki --- test/client/client_metric_test.cpp | 5 +++++ test/client/libcbd_ext4_test.cpp | 3 +++ test/client/libcurve_client_unittest.cpp | 9 +++++++++ test/client/mock/mock_file_client.h | 1 + 4 files changed, 18 insertions(+) diff --git a/test/client/client_metric_test.cpp b/test/client/client_metric_test.cpp index 2f092fc79f..1f31eacb1f 100644 --- a/test/client/client_metric_test.cpp +++ b/test/client/client_metric_test.cpp @@ -383,5 +383,10 @@ TEST(MetricTest, MetricHelperTest) { ASSERT_NO_THROW(MetricHelper::IncremSlowRequestNum(nullptr)); } +TEST(MetricTest, CollectMetricsTest) { + InterfaceMetric interface("curve_client", "test"); + ASSERT_NO_THROW(CollectMetrics(&interface, 1, 1)); +} + } // namespace client } // namespace curve diff --git a/test/client/libcbd_ext4_test.cpp b/test/client/libcbd_ext4_test.cpp index a240a3fd77..c57ca2b5af 100644 --- a/test/client/libcbd_ext4_test.cpp +++ b/test/client/libcbd_ext4_test.cpp @@ -166,6 +166,9 @@ TEST(TestLibcbdExt4, AioReadWriteTest) { ret = cbd_lib_fini(); ASSERT_EQ(ret, 0); + + ret = cbd_lib_filesize("no_exist_file"); + ASSERT_EQ(ret, -1); } TEST(TestLibcbdExt4, IncreaseEpochTest) { diff --git a/test/client/libcurve_client_unittest.cpp b/test/client/libcurve_client_unittest.cpp index bd6ded108a..7563455a6f 100644 --- a/test/client/libcurve_client_unittest.cpp +++ b/test/client/libcurve_client_unittest.cpp @@ -210,6 +210,15 @@ TEST_F(CurveClientTest, TestAioWrite) { } } +TEST_F(CurveClientTest, TestIncreaseEpoch) { + { + EXPECT_CALL(*mockFileClient_, IncreaseEpoch(_)).Times(0); + + ASSERT_EQ(-LIBCURVE_ERROR::FAILED, + client_.IncreaseEpoch(kWrongFileName)); + } +} + } // namespace client } // namespace curve diff --git a/test/client/mock/mock_file_client.h b/test/client/mock/mock_file_client.h index 6a3e2f984a..6d78fc7dc9 100644 --- a/test/client/mock/mock_file_client.h +++ b/test/client/mock/mock_file_client.h @@ -56,6 +56,7 @@ class MockFileClient : public FileClient { MOCK_METHOD4(ReOpen, int(const std::string&, const std::string&, const UserInfo&, std::string*)); MOCK_METHOD3(Extend, int(const std::string&, const UserInfo&, uint64_t)); + MOCK_METHOD1(IncreaseEpoch, int(const std::string &)); }; } // namespace client From e1f772c9822fac084aaf0e1e182f056adc46472f Mon Sep 17 00:00:00 2001 From: zztaki Date: Thu, 28 Dec 2023 00:09:10 +0800 Subject: [PATCH 2/2] Perf(common): optimize cache promotion and demotion Signed-off-by: zztaki --- src/common/lru_cache.h | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/src/common/lru_cache.h b/src/common/lru_cache.h index 484e166a6b..7345af89c7 100644 --- a/src/common/lru_cache.h +++ b/src/common/lru_cache.h @@ -204,7 +204,7 @@ class LRUCache : public LRUCacheInterface { void Remove(const K &key) override; /* - * @brief Get the first key that $value = value + * @brief Get the first key that $value = value from lru tail to head * * @param[in] value * @param[out] key @@ -429,10 +429,7 @@ void LRUCache::RemoveLocked(const K &key) { template void LRUCache::MoveToFront( const typename std::list::iterator &elem) { - Item duplica{elem->key, elem->value}; - ll_.erase(elem); - ll_.push_front(duplica); - cache_[*(duplica.key)] = ll_.begin(); + ll_.splice(ll_.begin(), ll_, elem); } template @@ -699,16 +696,8 @@ bool SglLRUCache::MoveBack(const K &key) { if (iter == cache_.end()) { return false; } - // delete the old value - RemoveElement(iter->second); - // put new value at tail - ll_.push_back(key); - cache_[key] = --ll_.end(); - size_++; - if (cacheMetrics_ != nullptr) { - cacheMetrics_->UpdateAddToCacheCount(); - cacheMetrics_->UpdateAddToCacheBytes(KeyTraits::CountBytes(key)); - } + // move key to list tail + ll_.splice(ll_.end(), ll_, iter->second); return true; } @@ -806,10 +795,7 @@ void SglLRUCache::RemoveLocked(const K &key) { template void SglLRUCache::MoveToFront( const typename std::list::iterator &elem) { - K tmp = *elem; - ll_.erase(elem); - ll_.emplace_front(tmp); - cache_[tmp] = ll_.begin(); + ll_.splice(ll_.begin(), ll_, elem); } template