]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cls/user: some fixes + handle old buckets case
authorYehuda Sadeh <yehuda@inktank.com>
Wed, 8 Jan 2014 22:13:27 +0000 (14:13 -0800)
committerYehuda Sadeh <yehuda@inktank.com>
Fri, 24 Jan 2014 18:28:48 +0000 (10:28 -0800)
If a bucket was created prior to the new accounting, we can't substract
the old values, as the header stats didn't account for them.

Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/cls/user/cls_user.cc
src/cls/user/cls_user_types.h

index b460d6283eafad0d467760803ce871c3bc8f0adb..ba172898bc296171a41a2e0005170dc7d2ce137a 100644 (file)
@@ -149,11 +149,14 @@ static int cls_user_set_buckets_info(cls_method_context_t hctx, bufferlist *in,
     if (ret < 0) {
       CLS_LOG(0, "ERROR: get_existing_bucket_entry() key=%s returned %d", key.c_str(), ret);
       return ret;
-    } else if (ret >= 0) {
+    } else if (ret >= 0 && old_entry.user_stats_sync) {
       dec_header_stats(&header, old_entry);
     }
 
-    CLS_LOG(20, "storing entry by client/op at %s", key.c_str());
+    CLS_LOG(20, "storing entry for key=%s size=%lld count=%lld",
+            key.c_str(), (long long)entry.size, (long long)entry.count);
+
+    entry.user_stats_sync = true;
 
     ret = write_entry(hctx, key, entry);
     if (ret < 0)
@@ -161,7 +164,17 @@ static int cls_user_set_buckets_info(cls_method_context_t hctx, bufferlist *in,
 
     add_header_stats(&header, entry);
   }
+
+  bufferlist bl;
+
+  CLS_LOG(20, "header: total bytes=%lld entries=%lld", (long long)header.total_bytes, (long long)header.total_entries);
+
+  ::encode(header, bl);
   
+  ret = cls_cxx_map_write_header(hctx, &bl);
+  if (ret < 0)
+    return ret;
+
   return 0;
 }
 
@@ -198,7 +211,9 @@ static int cls_user_remove_bucket(cls_method_context_t hctx, bufferlist *in, buf
     return ret;
   }
 
-  dec_header_stats(&header, entry);
+  if (entry.user_stats_sync) {
+    dec_header_stats(&header, entry);
+  }
 
   CLS_LOG(20, "removing entry at %s", key.c_str());
 
index dde508b0ab7a7b5d117679b9e085caa2b42f1792..d38bf9d1b39d82a66572bde55d4c33e269618b24 100644 (file)
@@ -66,11 +66,12 @@ struct cls_user_bucket_entry {
   size_t size_rounded;
   time_t creation_time;
   uint64_t count;
+  bool user_stats_sync;
 
-  cls_user_bucket_entry() : size(0), size_rounded(0), creation_time(0), count(0) {}
+  cls_user_bucket_entry() : size(0), size_rounded(0), creation_time(0), count(0), user_stats_sync(false) {}
 
   void encode(bufferlist& bl) const {
-    ENCODE_START(5, 5, bl);
+    ENCODE_START(6, 5, bl);
     uint64_t s = size;
     __u32 mt = creation_time;
     string empty_str;  // originally had the bucket name here, but we encode bucket later
@@ -81,10 +82,11 @@ struct cls_user_bucket_entry {
     ::encode(bucket, bl);
     s = size_rounded;
     ::encode(s, bl);
+    ::encode(user_stats_sync, bl);
     ENCODE_FINISH(bl);
   }
   void decode(bufferlist::iterator& bl) {
-    DECODE_START_LEGACY_COMPAT_LEN(5, 5, 5, bl);
+    DECODE_START_LEGACY_COMPAT_LEN(6, 5, 5, bl);
     __u32 mt;
     uint64_t s;
     string empty_str;  // backward compatibility
@@ -100,6 +102,8 @@ struct cls_user_bucket_entry {
     if (struct_v >= 4)
       ::decode(s, bl);
     size_rounded = s;
+    if (struct_v >= 6)
+      ::decode(user_stats_sync, bl);
     DECODE_FINISH(bl);
   }
 };