]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw, cls_rgw: log versioned operations in bucket index log
authorYehuda Sadeh <yehuda@redhat.com>
Tue, 6 Jan 2015 22:12:06 +0000 (14:12 -0800)
committerYehuda Sadeh <yehuda@redhat.com>
Mon, 19 Jan 2015 23:58:01 +0000 (15:58 -0800)
Add the following log ops:
 - link_olh
 - link_olh_del
 - unlink_instance

Log operations if needed. Use current version field in the log entries
to specify versioned epoch.

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.cc
src/cls/rgw/cls_rgw_ops.h
src/cls/rgw/cls_rgw_types.cc
src/cls/rgw/cls_rgw_types.h
src/rgw/rgw_rados.cc

index 807ce9751c8f52acec7a735ddf30c92a1772c59f..58d8c1101b65ff20d7af9a1236e60e602a5f4c13 100644 (file)
@@ -1036,6 +1036,10 @@ public:
     return 0;
   }
 
+  rgw_bucket_dir_entry& get_dir_entry() {
+    return instance_entry;
+  }
+
   void init_as_delete_marker(rgw_bucket_dir_entry_meta& meta) {
     /* a deletion marker, need to initialize it, there's no instance entry for it yet */
     instance_entry.key = key;
@@ -1467,7 +1471,28 @@ static int rgw_bucket_link_olh(cls_method_context_t hctx, bufferlist *in, buffer
     return ret;
   }
 
-  return 0;
+  struct rgw_bucket_dir_header header;
+  ret = read_bucket_header(hctx, &header);
+  if (ret < 0) {
+    CLS_LOG(1, "ERROR: rgw_bucket_unlink_instance(): failed to read header\n");
+    return ret;
+  }
+
+  if (op.log_op) {
+    rgw_bucket_dir_entry& entry = obj.get_dir_entry();
+
+    rgw_bucket_entry_ver ver;
+    ver.epoch = (op.olh_epoch ? op.olh_epoch : olh.get_epoch());
+
+    RGWModifyOp operation = (op.delete_marker ? CLS_RGW_OP_LINK_OLH_DM : CLS_RGW_OP_LINK_OLH);
+    ret = log_index_operation(hctx, op.key, operation, op.op_tag,
+                              entry.meta.mtime, ver,
+                              CLS_RGW_STATE_COMPLETE, header.ver, header.max_marker);
+    if (ret < 0)
+      return ret;
+  }
+
+  return write_bucket_header(hctx, &header); /* updates header version */
 }
 
 static int rgw_bucket_unlink_instance(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
@@ -1578,7 +1603,26 @@ static int rgw_bucket_unlink_instance(cls_method_context_t hctx, bufferlist *in,
     return ret;
   }
 
-  return 0;
+  struct rgw_bucket_dir_header header;
+  ret = read_bucket_header(hctx, &header);
+  if (ret < 0) {
+    CLS_LOG(1, "ERROR: rgw_bucket_unlink_instance(): failed to read header\n");
+    return ret;
+  }
+
+  if (op.log_op) {
+    rgw_bucket_entry_ver ver;
+    ver.epoch = (op.olh_epoch ? op.olh_epoch : olh.get_epoch());
+
+    utime_t mtime = ceph_clock_now(g_ceph_context); /* mtime has no real meaning in instance removal context */
+    ret = log_index_operation(hctx, op.key, CLS_RGW_OP_UNLINK_INSTANCE, op.op_tag,
+                              mtime, ver,
+                              CLS_RGW_STATE_COMPLETE, header.ver, header.max_marker);
+    if (ret < 0)
+      return ret;
+  }
+
+  return write_bucket_header(hctx, &header); /* updates header version */
 }
 
 static int rgw_bucket_read_olh_log(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
index be447172c2dcd3e465a53864c5671e0d1a735f47..5d8e6102be623421c4ceb5fecc93aaace5634848 100644 (file)
@@ -182,7 +182,7 @@ int cls_rgw_bi_list(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, bufferlist& olh_tag,
                             bool delete_marker, const string& op_tag, struct rgw_bucket_dir_entry_meta *meta,
-                            uint64_t olh_epoch)
+                            uint64_t olh_epoch, bool log_op)
 {
   bufferlist in, out;
   struct rgw_cls_link_olh_op call;
@@ -194,6 +194,7 @@ int cls_rgw_bucket_link_olh(librados::IoCtx& io_ctx, const string& oid, const cl
     call.meta = *meta;
   }
   call.olh_epoch = olh_epoch;
+  call.log_op = log_op;
   ::encode(call, in);
   int r = io_ctx.exec(oid, "rgw", "bucket_link_olh", in, out);
   if (r < 0)
@@ -204,13 +205,14 @@ int cls_rgw_bucket_link_olh(librados::IoCtx& io_ctx, const string& oid, const cl
 
 int cls_rgw_bucket_unlink_instance(librados::IoCtx& io_ctx, const string& oid,
                                    const cls_rgw_obj_key& key, const string& op_tag,
-                                   uint64_t olh_epoch)
+                                   uint64_t olh_epoch, bool log_op)
 {
   bufferlist in, out;
   struct rgw_cls_unlink_instance_op call;
   call.key = key;
   call.op_tag = op_tag;
   call.olh_epoch = olh_epoch;
+  call.log_op = log_op;
   ::encode(call, in);
   int r = io_ctx.exec(oid, "rgw", "bucket_unlink_instance", in, out);
   if (r < 0)
index 5af68855c0f287d4dd21ba4cf8642fe6d4a8fddd..d7568949e0d08e816b10b8e7ba3c305206c85295 100644 (file)
@@ -45,9 +45,9 @@ int cls_rgw_bi_list(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, bufferlist& olh_tag,
                             bool delete_marker, const string& op_tag, struct rgw_bucket_dir_entry_meta *meta,
-                            uint64_t olh_epoch);
+                            uint64_t olh_epoch, bool log_op);
 int cls_rgw_bucket_unlink_instance(librados::IoCtx& io_ctx, const string& oid, const cls_rgw_obj_key& key, const string& op_tag,
-                                   uint64_t olh_epoch);
+                                   uint64_t olh_epoch, bool log_op);
 int cls_rgw_get_olh_log(librados::IoCtx& io_ctx, string& oid, librados::ObjectReadOperation& op, const cls_rgw_obj_key& olh, uint64_t ver_marker,
                         const string& olh_tag,
                         map<uint64_t, vector<struct rgw_bucket_olh_log_entry> > *log, bool *is_truncated);
index 69ffef68ff6a425902a13bbbb7659752dab4a6df..b70df791ff7bb368bd7c8f23201ad3f13f04438e 100644 (file)
@@ -154,6 +154,7 @@ void rgw_cls_link_olh_op::generate_test_instances(list<rgw_cls_link_olh_op*>& o)
   rgw_bucket_dir_entry_meta::generate_test_instances(l);
   list<rgw_bucket_dir_entry_meta *>::iterator iter = l.begin();
   op->meta = *(*iter);
+  op->log_op = true;
 
   o.push_back(op);
 
@@ -168,6 +169,7 @@ void rgw_cls_link_olh_op::dump(Formatter *f) const
   ::encode_json("op_tag", op_tag, f);
   ::encode_json("meta", meta, f);
   ::encode_json("olh_epoch", olh_epoch, f);
+  ::encode_json("log_op", log_op, f);
 }
 
 void rgw_cls_unlink_instance_op::generate_test_instances(list<rgw_cls_unlink_instance_op*>& o)
@@ -176,6 +178,7 @@ void rgw_cls_unlink_instance_op::generate_test_instances(list<rgw_cls_unlink_ins
   op->key.name = "name";
   op->op_tag = "op_tag";
   op->olh_epoch = 124;
+  op->log_op = true;
 
   o.push_back(op);
 
@@ -187,6 +190,7 @@ void rgw_cls_unlink_instance_op::dump(Formatter *f) const
   ::encode_json("key", key, f);
   ::encode_json("op_tag", op_tag, f);
   ::encode_json("olh_epoch", olh_epoch, f);
+  ::encode_json("log_op", log_op, f);
 }
 
 void rgw_cls_read_olh_log_op::generate_test_instances(list<rgw_cls_read_olh_log_op*>& o)
index cd2467a07163d3d27337622816413baeac1b08a0..7891828fc0241d01be9ede71f23bd5f4c0454516 100644 (file)
@@ -152,8 +152,9 @@ struct rgw_cls_link_olh_op {
   string op_tag;
   struct rgw_bucket_dir_entry_meta meta;
   uint64_t olh_epoch;
+  bool log_op;
 
-  rgw_cls_link_olh_op() : delete_marker(false), olh_epoch(0) {}
+  rgw_cls_link_olh_op() : delete_marker(false), olh_epoch(0), log_op(false) {}
 
   void encode(bufferlist& bl) const {
     ENCODE_START(1, 1, bl);
@@ -163,6 +164,7 @@ struct rgw_cls_link_olh_op {
     ::encode(op_tag, bl);
     ::encode(meta, bl);
     ::encode(olh_epoch, bl);
+    ::encode(log_op, bl);
     ENCODE_FINISH(bl);
   }
 
@@ -174,6 +176,7 @@ struct rgw_cls_link_olh_op {
     ::decode(op_tag, bl);
     ::decode(meta, bl);
     ::decode(olh_epoch, bl);
+    ::decode(log_op, bl);
     DECODE_FINISH(bl);
   }
 
@@ -186,14 +189,16 @@ struct rgw_cls_unlink_instance_op {
   cls_rgw_obj_key key;
   string op_tag;
   uint64_t olh_epoch;
+  bool log_op;
 
-  rgw_cls_unlink_instance_op() : olh_epoch(0) {}
+  rgw_cls_unlink_instance_op() : olh_epoch(0), log_op(false) {}
 
   void encode(bufferlist& bl) const {
     ENCODE_START(1, 1, bl);
     ::encode(key, bl);
     ::encode(op_tag, bl);
     ::encode(olh_epoch, bl);
+    ::encode(log_op, bl);
     ENCODE_FINISH(bl);
   }
 
@@ -202,6 +207,7 @@ struct rgw_cls_unlink_instance_op {
     ::decode(key, bl);
     ::decode(op_tag, bl);
     ::decode(olh_epoch, bl);
+    ::decode(log_op, bl);
     DECODE_FINISH(bl);
   }
 
index fcc92a7d2f20f0319b3b39ef2ac14ecb749b7bdc..a2daa153a4d85231c0ad2f0ad66f5f75ea69849a 100644 (file)
@@ -287,6 +287,15 @@ void rgw_bi_log_entry::dump(Formatter *f) const
     case CLS_RGW_OP_UNKNOWN:
       f->dump_string("op", "unknown");
       break;
+    case CLS_RGW_OP_LINK_OLH:
+      f->dump_string("op", "link_olh");
+      break;
+    case CLS_RGW_OP_LINK_OLH_DM:
+      f->dump_string("op", "link_olh_del");
+      break;
+    case CLS_RGW_OP_UNLINK_INSTANCE:
+      f->dump_string("op", "unlink_instance");
+      break;
     default:
       f->dump_string("op", "invalid");
       break;
index a36298cc1cf8f8179f9e6b8b74b0c9b24ed37d3e..5221520cbc53cce929cdebf74a54334487595a6d 100644 (file)
@@ -27,6 +27,9 @@ enum RGWModifyOp {
   CLS_RGW_OP_DEL     = 1,
   CLS_RGW_OP_CANCEL  = 2,
   CLS_RGW_OP_UNKNOWN = 3,
+  CLS_RGW_OP_LINK_OLH        = 4,
+  CLS_RGW_OP_LINK_OLH_DM     = 5, /* creation of delete marker */
+  CLS_RGW_OP_UNLINK_INSTANCE = 6,
 };
 
 struct rgw_bucket_pending_info {
index 61227128fee38f2dd2e5add6ca5a0cbbfeda398e..138f84d5835afac0c34b0e8a184ee2169656e351 100644 (file)
@@ -5653,7 +5653,8 @@ int RGWRados::bucket_index_link_olh(RGWObjState& olh_state, rgw_obj& obj_instanc
   }
 
   cls_rgw_obj_key key(obj_instance.get_index_key_name(), obj_instance.get_instance());
-  ret = cls_rgw_bucket_link_olh(index_ctx, oid, key, olh_state.olh_tag, delete_marker, op_tag, meta, olh_epoch);
+  ret = cls_rgw_bucket_link_olh(index_ctx, oid, key, olh_state.olh_tag, delete_marker, op_tag, meta, olh_epoch,
+                                zone_public_config.log_data);
   if (ret < 0) {
     return ret;
   }
@@ -5685,7 +5686,7 @@ int RGWRados::bucket_index_unlink_instance(rgw_obj& obj_instance, const string&
   }
 
   cls_rgw_obj_key key(obj_instance.get_index_key_name(), obj_instance.get_instance());
-  ret = cls_rgw_bucket_unlink_instance(index_ctx, oid, key, op_tag, olh_epoch);
+  ret = cls_rgw_bucket_unlink_instance(index_ctx, oid, key, op_tag, olh_epoch, zone_public_config.log_data);
   if (ret < 0) {
     return ret;
   }