From 97abbcebe4cc4928f2381134f6a09b90f06c2db8 Mon Sep 17 00:00:00 2001 From: Samarah Date: Thu, 8 Jun 2023 13:10:58 -0400 Subject: [PATCH] rgw/cache: This commit squashes the following commits related to list_entries cache api. RGW: Add list_entries method to CacheDriver and to Redis driver. RGW: Change CacheDriver::list_entries output type RGW: Update RedisDriver::list_entries and usage in D4N policy driver Signed-off-by: Samarah --- src/rgw/rgw_cache_driver.h | 1 + src/rgw/rgw_redis_driver.cc | 29 +++++++++++++++++++++++++++++ src/rgw/rgw_redis_driver.h | 1 + 3 files changed, 31 insertions(+) diff --git a/src/rgw/rgw_cache_driver.h b/src/rgw/rgw_cache_driver.h index a96b325610073..0fa1882b2e061 100644 --- a/src/rgw/rgw_cache_driver.h +++ b/src/rgw/rgw_cache_driver.h @@ -36,6 +36,7 @@ class CacheDriver { /* Entry */ virtual bool key_exists(const DoutPrefixProvider* dpp, const std::string& key) = 0; + virtual std::vector list_entries(const DoutPrefixProvider* dpp) = 0; virtual size_t get_num_entries(const DoutPrefixProvider* dpp) = 0; /* Partition */ diff --git a/src/rgw/rgw_redis_driver.cc b/src/rgw/rgw_redis_driver.cc index 371f3e72196a1..751eeedf6beef 100644 --- a/src/rgw/rgw_redis_driver.cc +++ b/src/rgw/rgw_redis_driver.cc @@ -75,6 +75,35 @@ bool RedisDriver::key_exists(const DoutPrefixProvider* dpp, const std::string& k return result; } +std::vector RedisDriver::list_entries(const DoutPrefixProvider* dpp) { + std::vector result; + + if (!client.is_connected()) + return {}; + +// try { + size_t cursor = 0; + const std::string pattern = "*:cache"; + + /* client.scan(cursor, pattern, [](cpp_redis::reply &reply) { + dout(0) << "Sam" << dendl; + if (!reply.is_null()) { + //result = reply.as_array(); + } + }); + client.sync_commit(std::chrono::milliseconds(1000)); +*/ +/* if (result.empty()) { + return {}; + } + } catch(std::exception &e) { + return {}; + } +*/ + dout(0) << "Sam: " << client.is_connected() << dendl; + return result; +} + size_t RedisDriver::get_num_entries(const DoutPrefixProvider* dpp) { int result = -1; diff --git a/src/rgw/rgw_redis_driver.h b/src/rgw/rgw_redis_driver.h index 01c623acb680f..06cddefb0c0cf 100644 --- a/src/rgw/rgw_redis_driver.h +++ b/src/rgw/rgw_redis_driver.h @@ -31,6 +31,7 @@ class RedisDriver : public CacheDriver { /* Entry */ virtual bool key_exists(const DoutPrefixProvider* dpp, const std::string& key) override; + virtual std::vector list_entries(const DoutPrefixProvider* dpp) override; virtual size_t get_num_entries(const DoutPrefixProvider* dpp) override; /* Partition */ -- 2.39.5