]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rgw: rename search variable to better indicate semantics
authorJ. Eric Ivancich <ivancich@redhat.com>
Tue, 3 Sep 2019 19:14:21 +0000 (15:14 -0400)
committerJ. Eric Ivancich <ivancich@redhat.com>
Fri, 24 Jan 2020 18:45:09 +0000 (13:45 -0500)
cls_cxx_map_get_vals takes a parameter of where in the sequence of
keys to start returning values. In code it's often referred to as the
"start_key", but in fact it only returns values who have keys *after*
it. To clarify the semantics, rename the variable to "start_after_key"
in the bucket listing functions in both rgw and cls.

Also, declare a type RGWRados::check_filter_t, so the type does not
have to be fully literalized multiple times.

Signed-off-by: J. Eric Ivancich <ivancich@redhat.com>
src/cls/rgw/cls_rgw.cc
src/rgw/rgw_admin.cc
src/rgw/rgw_bucket.cc
src/rgw/rgw_bucket.h
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h

index d52650ed9a431dd556b9caaabb493890627cfda0..30b408c84eb8b9af585b43a97c234517c8200f04 100644 (file)
@@ -448,14 +448,14 @@ int rgw_bucket_list(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
 
   map<string, bufferlist> keys;
   std::map<string, bufferlist>::iterator kiter;
-  string start_key;
+  string start_after_key;
   encode_list_index_key(hctx, op.start_obj, &start_key);
   bool done = false;
   uint32_t left_to_read = op.num_entries;
   bool more;
 
   do {
-    rc = get_obj_vals(hctx, start_key, op.filter_prefix, left_to_read, &keys, &more);
+    rc = get_obj_vals(hctx, start_after_key, op.filter_prefix, left_to_read, &keys, &more);
     if (rc < 0)
       return rc;
 
@@ -2323,18 +2323,23 @@ static int rgw_bi_put_op(cls_method_context_t hctx, bufferlist *in, bufferlist *
   return 0;
 }
 
-static int list_plain_entries(cls_method_context_t hctx, const string& name, const string& marker, uint32_t max,
-                              list<rgw_cls_bi_entry> *entries, bool *pmore)
+static int list_plain_entries(cls_method_context_t hctx,
+                             const string& name,
+                             const string& marker,
+                             uint32_t max,
+                              list<rgw_cls_bi_entry> *entries,
+                             bool *pmore)
 {
   string filter = name;
-  string start_key = marker;
+  string start_after_key = marker;
 
   string end_key; // stop listing at bi_log_prefix
   bi_log_prefix(end_key);
 
   int count = 0;
   map<string, bufferlist> keys;
-  int ret = cls_cxx_map_get_vals(hctx, start_key, filter, max, &keys, pmore);
+  int ret = cls_cxx_map_get_vals(hctx, start_after_key, filter, max,
+                                &keys, pmore);
   if (ret < 0) {
     return ret;
   }
@@ -2379,34 +2384,38 @@ static int list_plain_entries(cls_method_context_t hctx, const string& name, con
     if (count >= (int)max) {
       return count;
     }
-    start_key = entry.idx;
+    start_after_key = entry.idx;
   }
 
   return count;
 }
 
-static int list_instance_entries(cls_method_context_t hctx, const string& name, const string& marker, uint32_t max,
-                                 list<rgw_cls_bi_entry> *entries, bool *pmore)
+static int list_instance_entries(cls_method_context_t hctx,
+                                const string& name,
+                                const string& marker,
+                                uint32_t max,
+                                 list<rgw_cls_bi_entry> *entries,
+                                bool *pmore)
 {
   cls_rgw_obj_key key(name);
   string first_instance_idx;
   encode_obj_versioned_data_key(key, &first_instance_idx);
-  string start_key;
+  string start_after_key;
 
   if (!name.empty()) {
-    start_key = first_instance_idx;
+    start_after_key = first_instance_idx;
   } else {
-    start_key = BI_PREFIX_CHAR;
-    start_key.append(bucket_index_prefixes[BI_BUCKET_OBJ_INSTANCE_INDEX]);
+    start_after_key = BI_PREFIX_CHAR;
+    start_after_key.append(bucket_index_prefixes[BI_BUCKET_OBJ_INSTANCE_INDEX]);
   }
-  string filter = start_key;
-  if (bi_entry_gt(marker, start_key)) {
-    start_key = marker;
+  string filter = start_after_key;
+  if (bi_entry_gt(marker, start_after_key)) {
+    start_after_key = marker;
   }
   int count = 0;
   map<string, bufferlist> keys;
   bufferlist k;
-  int ret = cls_cxx_map_get_val(hctx, start_key, &k);
+  int ret = cls_cxx_map_get_val(hctx, start_after_key, &k);
   if (ret < 0 && ret != -ENOENT) {
     return ret;
   }
@@ -2415,14 +2424,17 @@ static int list_instance_entries(cls_method_context_t hctx, const string& name,
     --max;
   }
   if (max > 0) {
-    ret = cls_cxx_map_get_vals(hctx, start_key, string(), max, &keys, pmore);
-    CLS_LOG(20, "%s(): start_key=%s first_instance_idx=%s keys.size()=%d", __func__, escape_str(start_key).c_str(), escape_str(first_instance_idx).c_str(), (int)keys.size());
+    ret = cls_cxx_map_get_vals(hctx, start_after_key, string(), max,
+                              &keys, pmore);
+    CLS_LOG(20, "%s(): start_after_key=%s first_instance_idx=%s keys.size()=%d",
+           __func__, escape_str(start_after_key).c_str(),
+           escape_str(first_instance_idx).c_str(), (int)keys.size());
     if (ret < 0) {
       return ret;
     }
   }
   if (found_first) {
-    keys[start_key].claim(k);
+    keys[start_after_key].claim(k);
   }
 
   map<string, bufferlist>::iterator iter;
@@ -2462,35 +2474,39 @@ static int list_instance_entries(cls_method_context_t hctx, const string& name,
 
     entries->push_back(entry);
     count++;
-    start_key = entry.idx;
+    start_after_key = entry.idx;
   }
 
   return count;
 }
 
-static int list_olh_entries(cls_method_context_t hctx, const string& name, const string& marker, uint32_t max,
-                            list<rgw_cls_bi_entry> *entries, bool *pmore)
+static int list_olh_entries(cls_method_context_t hctx,
+                           const string& name,
+                           const string& marker,
+                           uint32_t max,
+                            list<rgw_cls_bi_entry> *entries,
+                           bool *pmore)
 {
   cls_rgw_obj_key key(name);
   string first_instance_idx;
   encode_olh_data_key(key, &first_instance_idx);
-  string start_key;
+  string start_after_key;
 
   if (!name.empty()) {
-    start_key = first_instance_idx;
+    start_after_key = first_instance_idx;
   } else {
-    start_key = BI_PREFIX_CHAR;
-    start_key.append(bucket_index_prefixes[BI_BUCKET_OLH_DATA_INDEX]);
+    start_after_key = BI_PREFIX_CHAR;
+    start_after_key.append(bucket_index_prefixes[BI_BUCKET_OLH_DATA_INDEX]);
   }
-  string filter = start_key;
-  if (bi_entry_gt(marker, start_key)) {
-    start_key = marker;
+  string filter = start_after_key;
+  if (bi_entry_gt(marker, start_after_key)) {
+    start_after_key = marker;
   }
   int count = 0;
   map<string, bufferlist> keys;
   int ret;
   bufferlist k;
-  ret = cls_cxx_map_get_val(hctx, start_key, &k);
+  ret = cls_cxx_map_get_val(hctx, start_after_key, &k);
   if (ret < 0 && ret != -ENOENT) {
     return ret;
   }
@@ -2499,15 +2515,18 @@ static int list_olh_entries(cls_method_context_t hctx, const string& name, const
     --max;
   }
   if (max > 0) {
-    ret = cls_cxx_map_get_vals(hctx, start_key, string(), max, &keys, pmore);
-    CLS_LOG(20, "%s(): start_key=%s first_instance_idx=%s keys.size()=%d", __func__, escape_str(start_key).c_str(), escape_str(first_instance_idx).c_str(), (int)keys.size());
+    ret = cls_cxx_map_get_vals(hctx, start_after_key, string(), max,
+                              &keys, pmore);
+    CLS_LOG(20, "%s(): start_after_key=%s first_instance_idx=%s keys.size()=%d",
+           __func__, escape_str(start_after_key).c_str(),
+           escape_str(first_instance_idx).c_str(), (int)keys.size());
     if (ret < 0) {
       return ret;
     }
   }
 
   if (found_first) {
-    keys[start_key].claim(k);
+    keys[start_after_key].claim(k);
   }
 
   map<string, bufferlist>::iterator iter;
@@ -2547,13 +2566,15 @@ static int list_olh_entries(cls_method_context_t hctx, const string& name, const
 
     entries->push_back(entry);
     count++;
-    start_key = entry.idx;
+    start_after_key = entry.idx;
   }
 
   return count;
 }
 
-static int rgw_bi_list_op(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
+static int rgw_bi_list_op(cls_method_context_t hctx,
+                         bufferlist *in,
+                         bufferlist *out)
 {
   // decode request
   rgw_cls_bi_list_op op;
@@ -2570,9 +2591,9 @@ static int rgw_bi_list_op(cls_method_context_t hctx, bufferlist *in, bufferlist
   string filter = op.name;
 #define MAX_BI_LIST_ENTRIES 1000
   int32_t max = (op.max < MAX_BI_LIST_ENTRIES ? op.max : MAX_BI_LIST_ENTRIES);
-  string start_key = op.marker;
   bool more;
-  int ret = list_plain_entries(hctx, op.name, op.marker, max, &op_ret.entries, &more);
+  int ret = list_plain_entries(hctx, op.name, op.marker, max,
+                              &op_ret.entries, &more);
   if (ret < 0) {
     CLS_LOG(0, "ERROR: %s(): list_plain_entries returned ret=%d", __func__, ret);
     return ret;
@@ -2624,10 +2645,14 @@ int bi_log_record_decode(bufferlist& bl, rgw_bi_log_entry& e)
   return 0;
 }
 
-static int bi_log_iterate_entries(cls_method_context_t hctx, const string& marker, const string& end_marker,
-                              string& key_iter, uint32_t max_entries, bool *truncated,
-                              int (*cb)(cls_method_context_t, const string&, rgw_bi_log_entry&, void *),
-                              void *param)
+static int bi_log_iterate_entries(cls_method_context_t hctx,
+                                 const string& marker,
+                                 const string& end_marker,
+                                 string& key_iter,
+                                 uint32_t max_entries,
+                                 bool *truncated,
+                                 int (*cb)(cls_method_context_t, const string&, rgw_bi_log_entry&, void *),
+                                 void *param)
 {
   CLS_LOG(10, "bi_log_iterate_range");
 
@@ -2639,15 +2664,15 @@ static int bi_log_iterate_entries(cls_method_context_t hctx, const string& marke
   if (truncated)
     *truncated = false;
 
-  string start_key;
+  string start_after_key;
   if (key_iter.empty()) {
     key = BI_PREFIX_CHAR;
     key.append(bucket_index_prefixes[BI_BUCKET_LOG_INDEX]);
     key.append(marker);
 
-    start_key = key;
+    start_after_key = key;
   } else {
-    start_key = key_iter;
+    start_after_key = key_iter;
   }
 
   if (end_marker.empty()) {
@@ -2659,11 +2684,13 @@ static int bi_log_iterate_entries(cls_method_context_t hctx, const string& marke
     end_key.append(end_marker);
   }
 
-  CLS_LOG(10, "bi_log_iterate_entries start_key=%s end_key=%s\n", start_key.c_str(), end_key.c_str());
+  CLS_LOG(10, "bi_log_iterate_entries start_after_key=%s end_key=%s\n",
+         start_after_key.c_str(), end_key.c_str());
 
   string filter;
 
-  int ret = cls_cxx_map_get_vals(hctx, start_key, filter, max_entries, &keys, truncated);
+  int ret = cls_cxx_map_get_vals(hctx, start_after_key, filter, max_entries,
+                                &keys, truncated);
   if (ret < 0)
     return ret;
 
index fa7559b11e8862df4399f6adc3e87e03922ec415..e59ca611ba96b37142e729604b548212ebbb96d5 100644 (file)
@@ -1451,13 +1451,6 @@ int set_user_quota(int opt_cmd, RGWUser& user, RGWUserAdminOpState& op_state, in
   return 0;
 }
 
-static bool bucket_object_check_filter(const string& name)
-{
-  rgw_obj_key k;
-  string ns; /* empty namespace */
-  return rgw_obj_key::oid_to_key_in_ns(name, &k, ns);
-}
-
 int check_min_obj_stripe_size(rgw::sal::RGWRadosStore *store, RGWBucketInfo& bucket_info, rgw_obj& obj, uint64_t min_stripe_size, bool *need_rewrite)
 {
   map<string, bufferlist> attrs;
@@ -6266,8 +6259,7 @@ next:
                                       prefix, 1000, true,
                                       result, &is_truncated, &marker,
                                        null_yield,
-                                      bucket_object_check_filter);
-
+                                      rgw_bucket_object_check_filter);
       if (r < 0 && r != -ENOENT) {
         cerr << "ERROR: failed operation r=" << r << std::endl;
       }
index b8a48c788f8780a1685c0b16789b3cd729457724..6d228bd3e64e75af5b832fac8ff8dfc3c5f5473f 100644 (file)
@@ -303,7 +303,8 @@ void check_bad_user_bucket_mapping(rgw::sal::RGWRadosStore *store, const rgw_use
   } while (user_buckets.is_truncated());
 }
 
-static bool bucket_object_check_filter(const string& oid)
+// note: function type conforms to RGWRados::check_filter_t
+bool rgw_bucket_object_check_filter(const string& oid)
 {
   rgw_obj_key key;
   string ns;
index 410cc7cd49e2a4813721d92be5b4f44730b0580c..1c6bd7cc49e4abffc3c2f39bb29ba92328f013f6 100644 (file)
@@ -49,6 +49,10 @@ extern void rgw_parse_url_bucket(const string& bucket,
                                  const string& auth_tenant,
                                  string &tenant_name, string &bucket_name);
 
+// this is used as a filter to RGWRados::cls_bucket_list_ordered; it
+// conforms to the type declaration of RGWRados::check_filter_t.
+extern bool rgw_bucket_object_check_filter(const string& oid);
+
 struct RGWBucketCompleteInfo {
   RGWBucketInfo info;
   map<string, bufferlist> attrs;
index 235bde47f889ef1356b6e7c99db6e1dc43a8047c..3c1b18119bae8943dbf25860d4d07e996a83d7e2 100644 (file)
@@ -8016,7 +8016,7 @@ uint32_t RGWRados::calc_ordered_bucket_list_per_shard(uint32_t num_entries,
 
 int RGWRados::cls_bucket_list_ordered(RGWBucketInfo& bucket_info,
                                      int shard_id,
-                                     const rgw_obj_index_key& start,
+                                     const rgw_obj_index_key& start_after,
                                      const string& prefix,
                                      uint32_t num_entries,
                                      bool list_versions,
@@ -8024,11 +8024,11 @@ int RGWRados::cls_bucket_list_ordered(RGWBucketInfo& bucket_info,
                                      bool *is_truncated,
                                      rgw_obj_index_key *last_entry,
                                       optional_yield y,
-                                     bool (*force_check_filter)(const string& name))
+                                     check_filter_t force_check_filter)
 {
   ldout(cct, 10) << "cls_bucket_list_ordered " << bucket_info.bucket <<
-    " start " << start.name << "[" << start.instance << "] num_entries " <<
-    num_entries << dendl;
+    " start_after " << start_after.name << "[" << start_after.instance <<
+    "] num_entries " << num_entries << dendl;
 
   RGWSI_RADOS::Pool index_pool;
   // key   - oid (for different shards if there is any)
@@ -8051,8 +8051,8 @@ int RGWRados::cls_bucket_list_ordered(RGWBucketInfo& bucket_info,
 
   auto& ioctx = index_pool.ioctx();
   map<int, struct rgw_cls_list_ret> list_results;
-  cls_rgw_obj_key start_key(start.name, start.instance);
-  r = CLSRGWIssueBucketList(ioctx, start_key, prefix, num_entries_per_shard,
+  cls_rgw_obj_key start_after_key(start_after.name, start_after.instance);
+  r = CLSRGWIssueBucketList(ioctx, start_key_after, prefix, num_entries_per_shard,
                            list_versions, oids, list_results,
                            cct->_conf->rgw_bucket_index_max_aio)();
   if (r < 0) {
@@ -8167,7 +8167,7 @@ int RGWRados::cls_bucket_list_ordered(RGWBucketInfo& bucket_info,
 
 int RGWRados::cls_bucket_list_unordered(RGWBucketInfo& bucket_info,
                                        int shard_id,
-                                       const rgw_obj_index_key& start,
+                                       const rgw_obj_index_key& start_after,
                                        const string& prefix,
                                        uint32_t num_entries,
                                        bool list_versions,
@@ -8175,9 +8175,9 @@ int RGWRados::cls_bucket_list_unordered(RGWBucketInfo& bucket_info,
                                        bool *is_truncated,
                                        rgw_obj_index_key *last_entry,
                                         optional_yield y,
-                                       bool (*force_check_filter)(const string& name)) {
+                                       check_filter_t force_check_filter) {
   ldout(cct, 10) << "cls_bucket_list_unordered " << bucket_info.bucket <<
-    " start " << start.name << "[" << start.instance <<
+    " start_after " << start_after.name << "[" << start_after.instance <<
     "] num_entries " << num_entries << dendl;
 
   static MultipartMetaFilter multipart_meta_filter;
@@ -8194,23 +8194,23 @@ int RGWRados::cls_bucket_list_unordered(RGWBucketInfo& bucket_info,
 
   const uint32_t num_shards = oids.size();
 
-  rgw_obj_index_key marker = start;
+  rgw_obj_index_key marker = start_after;
   uint32_t current_shard;
   if (shard_id >= 0) {
     current_shard = shard_id;
-  } else if (start.empty()) {
+  } else if (start_after.empty()) {
     current_shard = 0u;
   } else {
-    // at this point we have a marker (start) that has something in
-    // it, so we need to get to the bucket shard index, so we can
+    // at this point we have a marker (start_after) that has something
+    // in it, so we need to get to the bucket shard index, so we can
     // start reading from there
 
     std::string key;
     // test whether object name is a multipart meta name
-    if(! multipart_meta_filter.filter(start.name, key)) {
+    if(! multipart_meta_filter.filter(start_after.name, key)) {
       // if multipart_meta_filter fails, must be "regular" (i.e.,
       // unadorned) and the name is the key
-      key = start.name;
+      key = start_after.name;
     }
 
     // now convert the key (oid) to an rgw_obj_key since that will
@@ -8220,7 +8220,7 @@ int RGWRados::cls_bucket_list_unordered(RGWBucketInfo& bucket_info,
     if (!parsed) {
       ldout(cct, 0) <<
        "ERROR: RGWRados::cls_bucket_list_unordered received an invalid "
-       "start marker: '" << start << "'" << dendl;
+       "start marker: '" << start_after << "'" << dendl;
       return -EINVAL;
     } else if (obj_key.name.empty()) {
       // if the name is empty that means the object name came in with
index 1bdaa5c9af350a9f5ba3d6f1f9d8f0dc2ce3141c..855597705cfd530aad0ae13f4a38a97200d3d78b 100644 (file)
@@ -1346,23 +1346,28 @@ public:
   using ent_map_t =
     boost::container::flat_map<std::string, rgw_bucket_dir_entry>;
 
+  using check_filter_t = bool (*)(const std::string&);
+
   int cls_bucket_list_ordered(RGWBucketInfo& bucket_info, int shard_id,
-                             const rgw_obj_index_key& start,
+                             const rgw_obj_index_key& start_after,
                              const string& prefix,
                              uint32_t num_entries, bool list_versions,
                              ent_map_t& m,
                              bool *is_truncated,
                              rgw_obj_index_key *last_entry,
                               optional_yield y,
-                             bool (*force_check_filter)(const string& name) = nullptr);
-  int cls_bucket_list_unordered(RGWBucketInfo& bucket_info, int shard_id,
-                               const rgw_obj_index_key& start,
+                             check_filter_t force_check_filter = nullptr);
+  int cls_bucket_list_unordered(RGWBucketInfo& bucket_info,
+                               int shard_id,
+                               const rgw_obj_index_key& start_after,
                                const string& prefix,
-                               uint32_t num_entries, bool list_versions,
+                               uint32_t num_entries,
+                               bool list_versions,
                                vector<rgw_bucket_dir_entry>& ent_list,
-                               bool *is_truncated, rgw_obj_index_key *last_entry,
+                               bool *is_truncated,
+                               rgw_obj_index_key *last_entry,
                                 optional_yield y,
-                               bool (*force_check_filter)(const string& name) = nullptr);
+                               check_filter_t = nullptr);
   int cls_bucket_head(const RGWBucketInfo& bucket_info, int shard_id, vector<rgw_bucket_dir_header>& headers, map<int, string> *bucket_instance_ids = NULL);
   int cls_bucket_head_async(const RGWBucketInfo& bucket_info, int shard_id, RGWGetDirHeader_CB *ctx, int *num_aio);