From 3903e213c7ac7624e3452f5f3b1ca1c339bf2ca2 Mon Sep 17 00:00:00 2001 From: Pavan Rallabhandi Date: Tue, 18 Jul 2017 14:40:04 +0530 Subject: [PATCH] rgw: Do not decrement stats cache when the cache values are zero With RGWs configured in a load balancer, there is a possibility of having the cached values going unbound, when PUT/DELETE operations do not land up on the same RGW. To avoid such cases, make sure the decrement of stats happen only when the cached values are sane. Fixes: http://tracker.ceph.com/issues/20661 Signed-off-by: Pavan Rallabhandi --- src/rgw/rgw_quota.cc | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/rgw/rgw_quota.cc b/src/rgw/rgw_quota.cc index 370cf3f1a606..bf74e7fdc324 100644 --- a/src/rgw/rgw_quota.cc +++ b/src/rgw/rgw_quota.cc @@ -232,9 +232,23 @@ public: const uint64_t rounded_added = rgw_rounded_objsize(added_bytes); const uint64_t rounded_removed = rgw_rounded_objsize(removed_bytes); - entry->stats.size += added_bytes - removed_bytes; - entry->stats.size_rounded += rounded_added - rounded_removed; - entry->stats.num_objects += objs_delta; + if ((entry->stats.size + added_bytes - removed_bytes) >= 0) { + entry->stats.size += added_bytes - removed_bytes; + } else { + entry->stats.size = 0; + } + + if ((entry->stats.size_rounded + rounded_added - rounded_removed) >= 0) { + entry->stats.size_rounded += rounded_added - rounded_removed; + } else { + entry->stats.size_rounded = 0; + } + + if ((entry->stats.num_objects + objs_delta) >= 0) { + entry->stats.num_objects += objs_delta; + } else { + entry->stats.num_objects = 0; + } return true; } -- 2.47.3