From 364f7c54fca704542d80ee107c1bdb21fd7631d3 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Fri, 10 Jan 2014 10:46:11 -0800 Subject: [PATCH] rgw: move some code around, no actual changes Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_quota.cc | 194 +++++++++++++++++++++---------------------- 1 file changed, 97 insertions(+), 97 deletions(-) diff --git a/src/rgw/rgw_quota.cc b/src/rgw/rgw_quota.cc index 828199bd31b2a..96322702230a4 100644 --- a/src/rgw/rgw_quota.cc +++ b/src/rgw/rgw_quota.cc @@ -122,103 +122,6 @@ bool RGWQuotaCache::can_use_cached_stats(RGWQuotaInfo& quota, RGWStorageStats return true; } -class BucketAsyncRefreshHandler : public RGWQuotaCache::AsyncRefreshHandler { -public: - BucketAsyncRefreshHandler(RGWRados *_store, RGWQuotaCache *_cache, - const string& _user, rgw_bucket& _bucket) : - RGWQuotaCache::AsyncRefreshHandler(_store, _cache, _user, _bucket) {} - - int init_fetch(); - void handle_response(int r); -}; - -class RGWBucketStatsCache : public RGWQuotaCache { -protected: - bool map_find(const string& user, rgw_bucket& bucket, RGWQuotaCacheStats& qs) { - return stats_map.find(bucket, qs); - } - - bool map_find_and_update(const string& user, rgw_bucket& bucket, lru_map::UpdateContext *ctx) { - return stats_map.find_and_update(bucket, NULL, ctx); - } - - void map_add(const string& user, rgw_bucket& bucket, RGWQuotaCacheStats& qs) { - stats_map.add(bucket, qs); - } - - int fetch_stats_from_storage(const string& user, rgw_bucket& bucket, RGWStorageStats& stats); - -public: - RGWBucketStatsCache(RGWRados *_store) : RGWQuotaCache(store, store->ctx()->_conf->rgw_bucket_quota_cache_size) { - } - - AsyncRefreshHandler *allocate_refresh_handler(const string& user, rgw_bucket& bucket) { - return new BucketAsyncRefreshHandler(store, this, user, bucket); - } -}; - -int RGWBucketStatsCache::fetch_stats_from_storage(const string& user, rgw_bucket& bucket, RGWStorageStats& stats) -{ - RGWBucketInfo bucket_info; - - uint64_t bucket_ver; - uint64_t master_ver; - - map bucket_stats; - int r = store->get_bucket_stats(bucket, &bucket_ver, &master_ver, bucket_stats, NULL); - if (r < 0) { - ldout(store->ctx(), 0) << "could not get bucket info for bucket=" << bucket.name << dendl; - return r; - } - - stats = RGWStorageStats(); - - map::iterator iter; - for (iter = bucket_stats.begin(); iter != bucket_stats.end(); ++iter) { - RGWStorageStats& s = iter->second; - stats.num_kb += s.num_kb; - stats.num_kb_rounded += s.num_kb_rounded; - stats.num_objects += s.num_objects; - } - - return 0; -} - -int BucketAsyncRefreshHandler::init_fetch() -{ - ldout(store->ctx(), 20) << "initiating async quota refresh for bucket=" << bucket << dendl; - map bucket_stats; - int r = store->get_bucket_stats_async(bucket, this); - if (r < 0) { - ldout(store->ctx(), 0) << "could not get bucket info for bucket=" << bucket.name << dendl; - - /* get_bucket_stats_async() dropped our reference already */ - return r; - } - - return 0; -} - -void BucketAsyncRefreshHandler::handle_response(int r) -{ - if (r < 0) { - ldout(store->ctx(), 20) << "AsyncRefreshHandler::handle_response() r=" << r << dendl; - return; /* nothing to do here */ - } - - RGWStorageStats bs; - - map::iterator iter; - for (iter = stats->begin(); iter != stats->end(); ++iter) { - RGWStorageStats& s = iter->second; - bs.num_kb += s.num_kb; - bs.num_kb_rounded += s.num_kb_rounded; - bs.num_objects += s.num_objects; - } - - cache->async_refresh_response(user, bucket, bs); -} - template int RGWQuotaCache::async_refresh(const string& user, rgw_bucket& bucket, RGWQuotaCacheStats& qs) { @@ -328,6 +231,103 @@ void RGWQuotaCache::adjust_stats(const string& user, rgw_bucket& bucket, int map_find_and_update(user, bucket, &update); } +class BucketAsyncRefreshHandler : public RGWQuotaCache::AsyncRefreshHandler { +public: + BucketAsyncRefreshHandler(RGWRados *_store, RGWQuotaCache *_cache, + const string& _user, rgw_bucket& _bucket) : + RGWQuotaCache::AsyncRefreshHandler(_store, _cache, _user, _bucket) {} + + int init_fetch(); + void handle_response(int r); +}; + +int BucketAsyncRefreshHandler::init_fetch() +{ + ldout(store->ctx(), 20) << "initiating async quota refresh for bucket=" << bucket << dendl; + map bucket_stats; + int r = store->get_bucket_stats_async(bucket, this); + if (r < 0) { + ldout(store->ctx(), 0) << "could not get bucket info for bucket=" << bucket.name << dendl; + + /* get_bucket_stats_async() dropped our reference already */ + return r; + } + + return 0; +} + +void BucketAsyncRefreshHandler::handle_response(int r) +{ + if (r < 0) { + ldout(store->ctx(), 20) << "AsyncRefreshHandler::handle_response() r=" << r << dendl; + return; /* nothing to do here */ + } + + RGWStorageStats bs; + + map::iterator iter; + for (iter = stats->begin(); iter != stats->end(); ++iter) { + RGWStorageStats& s = iter->second; + bs.num_kb += s.num_kb; + bs.num_kb_rounded += s.num_kb_rounded; + bs.num_objects += s.num_objects; + } + + cache->async_refresh_response(user, bucket, bs); +} + +class RGWBucketStatsCache : public RGWQuotaCache { +protected: + bool map_find(const string& user, rgw_bucket& bucket, RGWQuotaCacheStats& qs) { + return stats_map.find(bucket, qs); + } + + bool map_find_and_update(const string& user, rgw_bucket& bucket, lru_map::UpdateContext *ctx) { + return stats_map.find_and_update(bucket, NULL, ctx); + } + + void map_add(const string& user, rgw_bucket& bucket, RGWQuotaCacheStats& qs) { + stats_map.add(bucket, qs); + } + + int fetch_stats_from_storage(const string& user, rgw_bucket& bucket, RGWStorageStats& stats); + +public: + RGWBucketStatsCache(RGWRados *_store) : RGWQuotaCache(store, store->ctx()->_conf->rgw_bucket_quota_cache_size) { + } + + AsyncRefreshHandler *allocate_refresh_handler(const string& user, rgw_bucket& bucket) { + return new BucketAsyncRefreshHandler(store, this, user, bucket); + } +}; + +int RGWBucketStatsCache::fetch_stats_from_storage(const string& user, rgw_bucket& bucket, RGWStorageStats& stats) +{ + RGWBucketInfo bucket_info; + + uint64_t bucket_ver; + uint64_t master_ver; + + map bucket_stats; + int r = store->get_bucket_stats(bucket, &bucket_ver, &master_ver, bucket_stats, NULL); + if (r < 0) { + ldout(store->ctx(), 0) << "could not get bucket info for bucket=" << bucket.name << dendl; + return r; + } + + stats = RGWStorageStats(); + + map::iterator iter; + for (iter = bucket_stats.begin(); iter != bucket_stats.end(); ++iter) { + RGWStorageStats& s = iter->second; + stats.num_kb += s.num_kb; + stats.num_kb_rounded += s.num_kb_rounded; + stats.num_objects += s.num_objects; + } + + return 0; +} + class RGWQuotaHandlerImpl : public RGWQuotaHandler { RGWRados *store; -- 2.39.5