]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: rgw_rados related fixes for usage logging
authorYehuda Sadeh <yehuda@inktank.com>
Mon, 11 Jun 2012 21:25:01 +0000 (14:25 -0700)
committerYehuda Sadeh <yehuda@inktank.com>
Mon, 11 Jun 2012 21:25:01 +0000 (14:25 -0700)
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/rgw/rgw_log.cc
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h

index 77a7befcf0dd9b4679a9705b063f0b7fccf86bd2..b83ea889237842253a5f45b4ac3cb0c7edda1520 100644 (file)
@@ -79,7 +79,7 @@ string render_log_object_name(const string& format,
 /* usage logger */
 class UsageLogger {
   CephContext *cct;
-  map<rgw_user_bucket, RGWUsageInfo> usage_map;
+  map<rgw_user_bucket, RGWUsageBatch> usage_map;
   Mutex lock;
   int32_t num_entries;
   Mutex timer_lock;
@@ -146,7 +146,7 @@ public:
   }
 
   void flush() {
-    map<rgw_user_bucket, RGWUsageInfo> old_map;
+    map<rgw_user_bucket, RGWUsageBatch> old_map;
     lock.Lock();
     old_map.swap(usage_map);
     num_entries = 0;
index 92420e35c56605fbd86eaf91de8b85d320e5fd45..05bfd39d22b1d34a1611a98fef485f5c3c27ae53 100644 (file)
@@ -335,20 +335,37 @@ int RGWRados::log_show_next(RGWAccessHandle handle, rgw_log_entry *entry)
   return 1;
 }
 
+/**
+ * usage_log_hash: get usage log key hash, based on name and index
+ *
+ * Get the usage object name. Since a user may have more than 1
+ * object holding that info (multiple shards), we use index to
+ * specify that shard number. Once index exceeds max shards it
+ * wraps.
+ * If name is not being set, results for all users will be returned
+ * and index will wrap only after total shards number.
+ *
+ * @param cct [in] ceph context
+ * @param name [in] user name
+ * @param hash [out] hash value
+ * @param index [in] shard index number 
+ */
 static void usage_log_hash(CephContext *cct, const string& name, string& hash, uint32_t index)
 {
   uint32_t val = index;
 
   if (!name.empty()) {
-    val %= cct->_conf->rgw_usage_max_user_shards;
+    int max_user_shards = max(cct->_conf->rgw_usage_max_user_shards, 1);
+    val %= max_user_shards;
     val += ceph_str_hash_linux(name.c_str(), name.size());
   }
   char buf[16];
-  snprintf(buf, sizeof(buf), RGW_USAGE_OBJ_PREFIX "%u", (unsigned)(val % cct->_conf->rgw_usage_max_shards));
+  int max_shards = max(cct->_conf->rgw_usage_max_shards, 1);
+  snprintf(buf, sizeof(buf), RGW_USAGE_OBJ_PREFIX "%u", (unsigned)(val % max_shards));
   hash = buf;
 }
 
-int RGWRados::log_usage(map<rgw_user_bucket, RGWUsageInfo>& usage_info)
+int RGWRados::log_usage(map<rgw_user_bucket, RGWUsageBatch>& usage_info)
 {
   uint32_t index = 0;
 
@@ -358,10 +375,10 @@ int RGWRados::log_usage(map<rgw_user_bucket, RGWUsageInfo>& usage_info)
   string last_user;
 
   /* restructure usage map, cluster by object hash */
-  map<rgw_user_bucket, RGWUsageInfo>::iterator iter;
+  map<rgw_user_bucket, RGWUsageBatch>::iterator iter;
   for (iter = usage_info.begin(); iter != usage_info.end(); ++iter) {
     const rgw_user_bucket& ub = iter->first;
-    RGWUsageInfo& info = iter->second;
+    RGWUsageBatch& info = iter->second;
 
     if (ub.user.empty()) {
       ldout(cct, 0) << "WARNING: RGWRados::log_usage(): user name empty (bucket=" << ub.bucket << "), skipping" << dendl;
@@ -437,7 +454,7 @@ int RGWRados::trim_usage(string& user, uint64_t start_epoch, uint64_t end_epoch)
 {
   uint32_t index = 0;
   string hash, first_hash;
-  usage_log_hash(cct, user, first_hash, 0);
+  usage_log_hash(cct, user, first_hash, index);
 
   hash = first_hash;
 
index 9f835a8499b73b399654b3b7f6e8675b845c61cc..a475b99954070f01eeea853ab8b17b8b455afc7a 100644 (file)
@@ -29,7 +29,7 @@ static inline void get_obj_bucket_and_oid_key(rgw_obj& obj, rgw_bucket& bucket,
   prepend_bucket_marker(bucket, obj.key, key);
 }
 
-struct RGWUsageInfo {
+struct RGWUsageBatch {
   map<utime_t, rgw_usage_log_entry> m;
 
   void insert(utime_t& t, rgw_usage_log_entry& entry, bool *account) {
@@ -320,7 +320,7 @@ public:
   int log_show_next(RGWAccessHandle handle, rgw_log_entry *entry);
 
   // log bandwidth info
-  int log_usage(map<rgw_user_bucket, RGWUsageInfo>& usage_info);
+  int log_usage(map<rgw_user_bucket, RGWUsageBatch>& usage_info);
   int read_usage(string& user, uint64_t start_epoch, uint64_t end_epoch, uint32_t max_entries,
                  bool *is_truncated, RGWUsageIter& read_iter, map<rgw_user_bucket, rgw_usage_log_entry>& usage);
   int trim_usage(string& user, uint64_t start_epoch, uint64_t end_epoch);