]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: new api to retrieve olh log
authorYehuda Sadeh <yehuda@redhat.com>
Tue, 9 Sep 2014 20:20:51 +0000 (13:20 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Fri, 16 Jan 2015 22:33:48 +0000 (14:33 -0800)
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/cls/rgw/cls_rgw.cc
src/cls/rgw/cls_rgw_client.cc
src/cls/rgw/cls_rgw_client.h
src/cls/rgw/cls_rgw_ops.h
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h

index 8882cfa5860a5ede6cd4c438c9d33cd8ad5096e0..3320b9926190615feceeca6be00bb78d008146e8 100644 (file)
@@ -29,6 +29,7 @@ cls_method_handle_t h_rgw_bucket_rebuild_index;
 cls_method_handle_t h_rgw_bucket_prepare_op;
 cls_method_handle_t h_rgw_bucket_complete_op;
 cls_method_handle_t h_rgw_bucket_link_olh;
+cls_method_handle_t h_rgw_bucket_read_olh_log;
 cls_method_handle_t h_rgw_bi_log_list_op;
 cls_method_handle_t h_rgw_dir_suggest_changes;
 cls_method_handle_t h_rgw_user_usage_log_add;
@@ -940,7 +941,7 @@ static int write_entry(cls_method_context_t hctx, T& entry, const string& key)
 static int rgw_bucket_link_olh(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
 {
   // decode request
-  cls_rgw_link_olh_op op;
+  rgw_cls_link_olh_op op;
   bufferlist::iterator iter = in->begin();
   try {
     ::decode(op, iter);
@@ -1054,6 +1055,54 @@ static int rgw_bucket_link_olh(cls_method_context_t hctx, bufferlist *in, buffer
   return 0;
 }
 
+static int rgw_bucket_read_olh_log(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
+{
+  // decode request
+  rgw_cls_read_olh_log_op op;
+  bufferlist::iterator iter = in->begin();
+  try {
+    ::decode(op, iter);
+  } catch (buffer::error& err) {
+    CLS_LOG(0, "ERROR: rgw_bucket_read_olh_log(): failed to decode request\n");
+    return -EINVAL;
+  }
+
+  if (!op.olh.instance.empty()) {
+    CLS_LOG(1, "bad key passed in (non empty instance)");
+    return -EINVAL;
+  }
+
+  struct rgw_bucket_olh_entry olh_data_entry;
+  string olh_data_key;
+  encode_olh_data_key(op.olh, &olh_data_key);
+  int ret = read_index_entry(hctx, olh_data_key, &olh_data_entry);
+  if (ret < 0 && ret != -ENOENT) {
+    CLS_LOG(0, "ERROR: read_index_entry() olh_key=%s ret=%d", olh_data_key.c_str(), ret);
+    return ret;
+  }
+
+  rgw_cls_read_olh_log_ret op_ret;
+
+#define MAX_OLH_LOG_ENTRIES 1000
+  map<uint64_t, rgw_bucket_olh_log_entry>& log = olh_data_entry.pending_log;
+
+  if (log.begin()->first > op.ver_marker && log.size() <= MAX_OLH_LOG_ENTRIES) {
+    op_ret.log = log;
+    op_ret.is_truncated = false;
+  } else {
+    map<uint64_t, rgw_bucket_olh_log_entry>::iterator iter = log.upper_bound(op.ver_marker);
+
+    for (int i = 0; i < MAX_OLH_LOG_ENTRIES && iter != log.end(); ++i, ++iter) {
+      op_ret.log[iter->first] = iter->second;
+    }
+    op_ret.is_truncated = (iter != log.end());
+  }
+
+  ::encode(op_ret, *out);
+
+  return 0;
+}
+
 int rgw_dir_suggest_changes(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
 {
   CLS_LOG(1, "rgw_dir_suggest_changes()");
@@ -1980,6 +2029,8 @@ void __cls_init()
   cls_register_cxx_method(h_class, "bucket_prepare_op", CLS_METHOD_RD | CLS_METHOD_WR, rgw_bucket_prepare_op, &h_rgw_bucket_prepare_op);
   cls_register_cxx_method(h_class, "bucket_complete_op", CLS_METHOD_RD | CLS_METHOD_WR, rgw_bucket_complete_op, &h_rgw_bucket_complete_op);
   cls_register_cxx_method(h_class, "bucket_link_olh", CLS_METHOD_RD | CLS_METHOD_WR, rgw_bucket_link_olh, &h_rgw_bucket_link_olh);
+  cls_register_cxx_method(h_class, "bucket_read_olh_log", CLS_METHOD_RD, rgw_bucket_read_olh_log, &h_rgw_bucket_read_olh_log);
+
   cls_register_cxx_method(h_class, "bi_log_list", CLS_METHOD_RD, rgw_bi_log_list, &h_rgw_bi_log_list_op);
   cls_register_cxx_method(h_class, "bi_log_trim", CLS_METHOD_RD | CLS_METHOD_WR, rgw_bi_log_trim, &h_rgw_bi_log_list_op);
   cls_register_cxx_method(h_class, "dir_suggest_changes", CLS_METHOD_RD | CLS_METHOD_WR, rgw_dir_suggest_changes, &h_rgw_dir_suggest_changes);
index 9c231f21149e662c4a60d7b9c9cfc1b904ecf587..e9c4b64a6cbf1333342dbc446c05e69b4d202326 100644 (file)
@@ -97,7 +97,7 @@ int cls_rgw_bucket_link_olh(librados::IoCtx& io_ctx, const string& oid, const cl
                             bool delete_marker, const string& op_tag)
 {
   bufferlist in, out;
-  struct cls_rgw_link_olh_op call;
+  struct rgw_cls_link_olh_op call;
   call.key = key;
   call.op_tag = op_tag;
   call.delete_marker = delete_marker;
@@ -109,6 +109,36 @@ int cls_rgw_bucket_link_olh(librados::IoCtx& io_ctx, const string& oid, const cl
   return 0;
 }
 
+int cls_rgw_get_olh_log(IoCtx& io_ctx, string& oid, const cls_rgw_obj_key& olh, uint64_t ver_marker,
+                        map<uint64_t, struct rgw_bucket_olh_log_entry> *log, bool *is_truncated)
+{
+  bufferlist in, out;
+  struct rgw_cls_read_olh_log_op call;
+  call.olh = olh;
+  call.ver_marker = ver_marker;
+  ::encode(call, in);
+  int r = io_ctx.exec(oid, "rgw", "bucket_read_olh_log", in, out);
+  if (r < 0)
+    return r;
+
+  struct rgw_cls_read_olh_log_ret ret;
+  try {
+    bufferlist::iterator iter = out.begin();
+    ::decode(ret, iter);
+  } catch (buffer::error& err) {
+    return -EIO;
+  }
+
+  if (log) {
+    *log = ret.log;
+  }
+  if (is_truncated) {
+    *is_truncated = ret.is_truncated;
+  }
+
+ return r;
+}
+
 int cls_rgw_bucket_check_index_op(IoCtx& io_ctx, string& oid,
                                  rgw_bucket_dir_header *existing_header,
                                  rgw_bucket_dir_header *calculated_header)
index 3953c26f9c249a2a0019d53c08ba151d2e3bc40d..2f67c4b862c0eb38cddfb7294c48d405bc936dd8 100644 (file)
@@ -33,6 +33,8 @@ int cls_rgw_list_op(librados::IoCtx& io_ctx, const string& oid,
 
 int cls_rgw_bucket_link_olh(librados::IoCtx& io_ctx, const string& oid, const cls_rgw_obj_key& key,
                             bool delete_marker, const string& op_tag);
+int cls_rgw_get_olh_log(librados::IoCtx& io_ctx, string& oid, const cls_rgw_obj_key& olh, uint64_t ver_marker,
+                        map<uint64_t, struct rgw_bucket_olh_log_entry> *log, bool *is_truncated);
 
 int cls_rgw_bucket_check_index_op(librados::IoCtx& io_ctx, string& oid,
                                  rgw_bucket_dir_header *existing_header,
index 94e283c7c300b6f6ed25d9bb7de39c80e2686aea..59476996f06f1689183472864fd84dcfa35aa922 100644 (file)
@@ -145,12 +145,12 @@ struct rgw_cls_obj_complete_op
 };
 WRITE_CLASS_ENCODER(rgw_cls_obj_complete_op)
 
-struct cls_rgw_link_olh_op {
+struct rgw_cls_link_olh_op {
   cls_rgw_obj_key key;
   bool delete_marker;
   string op_tag;
 
-  cls_rgw_link_olh_op() : delete_marker(false) {}
+  rgw_cls_link_olh_op() : delete_marker(false) {}
 
   void encode(bufferlist& bl) const {
     ENCODE_START(1, 1, bl);
@@ -169,8 +169,58 @@ struct cls_rgw_link_olh_op {
   }
 
   void dump(Formatter *f) const;
+#warning implement me
 };
-WRITE_CLASS_ENCODER(cls_rgw_link_olh_op)
+WRITE_CLASS_ENCODER(rgw_cls_link_olh_op)
+
+struct rgw_cls_read_olh_log_op
+{
+  cls_rgw_obj_key olh;
+  uint64_t ver_marker;
+
+  rgw_cls_read_olh_log_op() : ver_marker(0) {}
+
+  void encode(bufferlist &bl) const {
+    ENCODE_START(1, 1, bl);
+    ::encode(olh, bl);
+    ::encode(ver_marker, bl);
+    ENCODE_FINISH(bl);
+  }
+  void decode(bufferlist::iterator &bl) {
+    DECODE_START(1, bl);
+    ::decode(olh, bl);
+    ::decode(ver_marker, bl);
+    DECODE_FINISH(bl);
+  }
+  void dump(Formatter *f) const;
+#warning implement me
+};
+WRITE_CLASS_ENCODER(rgw_cls_read_olh_log_op)
+
+
+struct rgw_cls_read_olh_log_ret
+{
+  map<uint64_t, struct rgw_bucket_olh_log_entry> log;
+  bool is_truncated;
+
+  rgw_cls_read_olh_log_ret() : is_truncated(false) {}
+
+  void encode(bufferlist &bl) const {
+    ENCODE_START(2, 2, bl);
+    ::encode(log, bl);
+    ::encode(is_truncated, bl);
+    ENCODE_FINISH(bl);
+  }
+  void decode(bufferlist::iterator &bl) {
+    DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl);
+    ::decode(log, bl);
+    ::decode(is_truncated, bl);
+    DECODE_FINISH(bl);
+  }
+  void dump(Formatter *f) const;
+#warning implement me
+};
+WRITE_CLASS_ENCODER(rgw_cls_read_olh_log_ret)
 
 struct rgw_cls_list_op
 {
index 802b6b877d7f0d0be072a6d511497744de00a648..b4907cbc7ccfc0f33fef71457fcf63250a1a918e 100644 (file)
@@ -5285,6 +5285,34 @@ int RGWRados::bucket_index_link_olh(rgw_obj& obj_instance, bool delete_marker, c
   return 0;
 }
 
+int RGWRados::bucket_index_read_olh_log(rgw_obj& obj_instance, uint64_t ver_marker,
+                                        map<uint64_t, rgw_bucket_olh_log_entry> *log,
+                                        bool *is_truncated)
+{
+  rgw_rados_ref ref;
+  rgw_bucket bucket;
+  int r = get_obj_ref(obj_instance, &ref, &bucket);
+  if (r < 0) {
+    return r;
+  }
+
+  librados::IoCtx index_ctx;
+  string oid;
+
+  int ret = open_bucket_index(bucket, index_ctx, oid);
+  if (ret < 0) {
+    return ret;
+  }
+
+  cls_rgw_obj_key key(obj_instance.get_index_key_name(), obj_instance.get_instance());
+  ret = cls_rgw_get_olh_log(index_ctx, oid, key, ver_marker, log, is_truncated);
+  if (ret < 0) {
+    return ret;
+  }
+
+  return 0;
+}
+
 static void filter_attrset(map<string, bufferlist>& unfiltered_attrset, const string& check_prefix,
                            map<string, bufferlist> *attrset)
 {
index c60a9bed56727a4fa20768f288066f9859f274a9..210c9801c160a848eb57342b28fac2ac89b16828 100644 (file)
@@ -1751,6 +1751,8 @@ public:
 
   int olh_init_modification(rgw_obj& obj, string *tag);
   int bucket_index_link_olh(rgw_obj& obj_instance, bool delete_marker, const string& op_tag);
+  int bucket_index_read_olh_log(rgw_obj& obj_instance, uint64_t ver_marker,
+                                map<uint64_t, rgw_bucket_olh_log_entry> *log, bool *is_truncated);
 
   int follow_olh(map<string, bufferlist>& attrset, rgw_obj& target);
   int get_olh(rgw_obj& obj, RGWOLHInfo *olh);