]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw:send x-amz-version-id header when upload files 18935/head
authorXinying Song <songxinying@cloudin.cn>
Wed, 15 Nov 2017 06:10:58 +0000 (14:10 +0800)
committerXinying Song <songxinying@cloudin.cn>
Fri, 17 Nov 2017 05:08:34 +0000 (13:08 +0800)
To be compatible with aws s3, an x-amz-version-id header should be returned.

For atomic upload, RGWPutObj::version_id will stores the version-id either
generated by rgw randomly or read from user. For multipart upload,
RGWCompleteMultipart::version_id will stores the version-id either
generated by rgw randomly or read from user.

Function send_respones() will send 'x-amz-version-id' header when version_id is not empty.

Signed-off-by: Xinying Song <songxinying@cloudin.cn>
src/rgw/rgw_common.h
src/rgw/rgw_op.cc
src/rgw/rgw_op.h
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h
src/rgw/rgw_rest_s3.cc

index 37db621b0923314d627cc4f563cee9313e1cbbd8..508e566e70b235406aa75d3e9a86487b50363a6d 100644 (file)
@@ -1537,6 +1537,10 @@ struct rgw_obj_key {
     instance = i;
   }
 
+  const string& get_instance() const {
+    return instance;
+  }
+
   string get_index_key_name() const {
     if (ns.empty()) {
       if (name.size() < 1 || name[0] != '_') {
index 73aa0ed543716abb80530aa9b728f68431b8423f..4003bea61ff9b5bda9f812221233757b17b108c3 100644 (file)
@@ -3577,6 +3577,10 @@ void RGWPutObj::execute()
                                (delete_at ? *delete_at : real_time()), if_match, if_nomatch,
                                (user_data.empty() ? nullptr : &user_data));
 
+  // only atomic upload will upate version_id here
+  if (!multipart) 
+    version_id = (static_cast<RGWPutObjProcessor_Atomic *>(processor))->get_version_id();
+
   /* produce torrent */
   if (s->cct->_conf->rgw_torrent_flag && (ofs == torrent.get_data_len()))
   {
@@ -5282,7 +5286,6 @@ void RGWCompleteMultipart::execute()
   RGWMPObj mp;
   RGWObjManifest manifest;
   uint64_t olh_epoch = 0;
-  string version_id;
 
   op_ret = get_params();
   if (op_ret < 0)
@@ -5489,7 +5492,12 @@ void RGWCompleteMultipart::execute()
 
   target_obj.init(s->bucket, s->object.name);
   if (versioned_object) {
-    store->gen_rand_obj_instance_name(&target_obj);
+    if (!version_id.empty()) {
+      target_obj.key.set_instance(version_id);
+    } else {
+      store->gen_rand_obj_instance_name(&target_obj);
+      version_id = target_obj.key.get_instance();
+    }
   }
 
   RGWObjectCtx& obj_ctx = *static_cast<RGWObjectCtx *>(s->obj_ctx);
index 3d644f4f0c1ce131a81c59ad941716c235480bd4..1cb44d2c48e0c7b5c06fcb0ea737a45763bd8c83 100644 (file)
@@ -1602,6 +1602,7 @@ class RGWCompleteMultipart : public RGWOp {
 protected:
   string upload_id;
   string etag;
+  string version_id;
   char *data;
   int len;
 
index 161608a89d987fc0ff1ce3215b03eb5b08588344..608d6e4b5e87e524673263a8d46a35ade650220a 100644 (file)
@@ -2656,10 +2656,13 @@ int RGWPutObjProcessor_Atomic::prepare(RGWRados *store, string *oid_rand)
     return r;
   }
 
-  if (!version_id.empty()) {
-    head_obj.key.set_instance(version_id);
-  } else if (versioned_object) {
-    store->gen_rand_obj_instance_name(&head_obj);
+  if (versioned_object) {
+    if (!version_id.empty()) {
+      head_obj.key.set_instance(version_id);
+    } else {
+      store->gen_rand_obj_instance_name(&head_obj);
+      version_id = head_obj.key.get_instance();
+    }
   }
 
   manifest.set_trivial_rule(max_chunk_size, store->ctx()->_conf->rgw_obj_stripe_size);
index d18398eba4d0bf5f184ef4ee1b62c90e3a92b4e0..4fd3fdf838e185da02aaf3e8276d732de9301cf6 100644 (file)
@@ -3934,6 +3934,10 @@ public:
   void set_version_id(const string& vid) {
     version_id = vid;
   }
+
+  const string& get_version_id() const {
+    return version_id;
+  }
 }; /* RGWPutObjProcessor_Atomic */
 
 #define MP_META_SUFFIX ".meta"
index bdd8ea4ee8593fee5ffc65c034496e86dc6c5ce1..3614dc47eab0e39785b337adf9c11cf78d9be6c4 100644 (file)
@@ -1384,10 +1384,12 @@ void RGWPutObj_ObjStore_S3::send_response()
       dump_errno(s);
       dump_etag(s, etag);
       dump_content_length(s, 0);
+      dump_header_if_nonempty(s, "x-amz-version-id", version_id);
       for (auto &it : crypt_http_responses)
         dump_header(s, it.first, it.second);
     } else {
       dump_errno(s);
+      dump_header_if_nonempty(s, "x-amz-version-id", version_id);
       end_header(s, this, "application/xml");
       dump_start(s);
       struct tm tmp;
@@ -2539,6 +2541,7 @@ void RGWCompleteMultipart_ObjStore_S3::send_response()
   if (op_ret)
     set_req_state_err(s, op_ret);
   dump_errno(s);
+  dump_header_if_nonempty(s, "x-amz-version-id", version_id);
   end_header(s, this, "application/xml");
   if (op_ret == 0) { 
     dump_start(s);