]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: cancel bucket update if operation failed
authorYehuda Sadeh <yehuda@hq.newdream.net>
Tue, 6 Mar 2012 01:28:16 +0000 (17:28 -0800)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Tue, 6 Mar 2012 01:28:16 +0000 (17:28 -0800)
Beforehand the operation was leaking.

Signed-off-by: Yehuda Sadeh <yehuda@hq.newdream.net>
src/rgw/rgw_cls_api.h
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h

index f19fd9634866f558f9b49933a9ffdd5130ec5896..b3209baaa3039e5e938e495aa38937f65415c11f 100644 (file)
@@ -17,8 +17,9 @@ enum RGWPendingState {
 };
 
 enum RGWModifyOp {
-  CLS_RGW_OP_ADD = 0,
-  CLS_RGW_OP_DEL = 1,
+  CLS_RGW_OP_ADD    = 0,
+  CLS_RGW_OP_DEL    = 1,
+  CLS_RGW_OP_CANCEL = 2,
 };
 
 struct rgw_bucket_pending_info {
index ecc0ecb094160677fd584ea3e5c7de38b75d83e9..e0bcec84185b70956f34035f9c516a851af15f0f 100644 (file)
@@ -722,26 +722,28 @@ int RGWRados::put_obj_meta(void *ctx, rgw_obj& obj,  uint64_t size,
     return 0;
 
   string tag;
+  uint64_t epoch;
+  utime_t ut;
   r = prepare_update_index(NULL, bucket, obj, tag);
   if (r < 0)
     return r;
 
   r = io_ctx.operate(oid, &op);
   if (r < 0)
-    return r;
+    goto done_cancel;
 
-  uint64_t epoch = io_ctx.get_last_version();
+  epoch = io_ctx.get_last_version();
 
   r = complete_atomic_overwrite(rctx, state, obj);
   if (r < 0) {
     dout(0) << "ERROR: complete_atomic_overwrite returned r=" << r << dendl;
   }
 
-  utime_t ut = ceph_clock_now(g_ceph_context);
+  ut = ceph_clock_now(g_ceph_context);
   r = complete_update_index(bucket, obj.object, tag, epoch, size,
                             ut, etag, content_type, &acl_bl, category);
   if (r < 0)
-    return r;
+    goto done_cancel;
 
 
   if (mtime) {
@@ -751,6 +753,13 @@ int RGWRados::put_obj_meta(void *ctx, rgw_obj& obj,  uint64_t size,
   }
 
   return 0;
+
+done_cancel:
+  int ret = complete_update_index_cancel(bucket, obj.object, tag);
+  if (ret < 0) {
+    dout(0) << "ERROR: complete_update_index_cancel() returned ret=" << ret << dendl;
+  }
+  return r;
 }
 
 /**
@@ -1094,6 +1103,11 @@ int RGWRados::delete_obj_impl(void *ctx, rgw_obj& obj, bool sync)
     if ((r >= 0 || r == -ENOENT) && bucket.marker.size()) {
       uint64_t epoch = io_ctx.get_last_version();
       r = complete_update_index_del(bucket, obj.object, tag, epoch);
+    } else {
+      int ret = complete_update_index_cancel(bucket, obj.object, tag);
+      if (ret < 0) {
+        dout(0) << "ERROR: complete_update_index_cancel returned ret=" << ret << dendl;
+      }
     }
     if (removed) {
       int ret = complete_atomic_overwrite(rctx, state, obj);
@@ -1812,9 +1826,16 @@ int RGWRados::clone_objs_impl(void *ctx, rgw_obj& dst_obj,
 done:
   atomic_write_finish(state, ret);
 
-  if (update_index && ret >= 0) {
-    ret = complete_update_index(bucket, dst_obj.object, tag, epoch, size,
-                                ut, etag, content_type, &acl_bl, category);
+  if (update_index) {
+    if (ret >= 0) {
+      ret = complete_update_index(bucket, dst_obj.object, tag, epoch, size,
+                                  ut, etag, content_type, &acl_bl, category);
+    } else {
+      int r = complete_update_index_cancel(bucket, dst_obj.object, tag);
+      if (r < 0) {
+        dout(0) << "ERROR: comlete_update_index_cancel() returned r=" << r << dendl;
+      }
+    }
   }
 
   return ret;
@@ -2393,6 +2414,13 @@ int RGWRados::cls_obj_complete_del(rgw_bucket& bucket, string& tag, uint64_t epo
   return cls_obj_complete_op(bucket, CLS_RGW_OP_DEL, tag, epoch, ent, RGW_OBJ_CATEGORY_NONE);
 }
 
+int RGWRados::cls_obj_complete_cancel(rgw_bucket& bucket, string& tag, string& name)
+{
+  RGWObjEnt ent;
+  ent.name = name;
+  return cls_obj_complete_op(bucket, CLS_RGW_OP_ADD, tag, 0, ent, RGW_OBJ_CATEGORY_NONE);
+}
+
 int RGWRados::cls_bucket_list(rgw_bucket& bucket, string start, uint32_t num, map<string, RGWObjEnt>& m,
                              bool *is_truncated, string *last_entry)
 {
index eb20c7e6cbe5f1b4709a60ba2610fd63a3953d41..18ad2aee40477ed77b2f6a11de3f46d3401cc8b6 100644 (file)
@@ -343,6 +343,7 @@ public:
                           RGWObjEnt& ent, RGWObjCategory category);
   int cls_obj_complete_add(rgw_bucket& bucket, string& tag, uint64_t epoch, RGWObjEnt& ent, RGWObjCategory category);
   int cls_obj_complete_del(rgw_bucket& bucket, string& tag, uint64_t epoch, string& name);
+  int cls_obj_complete_cancel(rgw_bucket& bucket, string& tag, string& name);
   int cls_bucket_list(rgw_bucket& bucket, string start, uint32_t num,
                       map<string, RGWObjEnt>& m, bool *is_truncated,
                       string *last_entry = NULL);
@@ -354,6 +355,9 @@ public:
   int complete_update_index_del(rgw_bucket& bucket, string& oid, string& tag, uint64_t epoch) {
     return cls_obj_complete_del(bucket, tag, epoch, oid);
   }
+  int complete_update_index_cancel(rgw_bucket& bucket, string& oid, string& tag) {
+    return cls_obj_complete_cancel(bucket, tag, oid);
+  }
 
   /// clean up/process any temporary objects older than given date[/time]
   int remove_temp_objects(string date, string time);