diff options
author | Yehuda Sadeh <yehuda@inktank.com> | 2013-06-03 19:22:38 -0700 |
---|---|---|
committer | Yehuda Sadeh <yehuda@inktank.com> | 2013-06-10 14:28:03 -0700 |
commit | 31676c59e4cdcb3a5b293499e26c7697c2ef9a63 (patch) | |
tree | 3720ee9dd929bdde9b5853f86636b0381c72a2da | |
parent | f6c7c0cbc786c4ca96fb1e5b61506bf8f050af7f (diff) | |
download | ceph-31676c59e4cdcb3a5b293499e26c7697c2ef9a63.tar.gz |
rgw: skeleton for obj copy across regions
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
-rw-r--r-- | src/rgw/rgw_op.cc | 19 | ||||
-rw-r--r-- | src/rgw/rgw_op.h | 3 | ||||
-rw-r--r-- | src/rgw/rgw_rados.cc | 14 | ||||
-rw-r--r-- | src/rgw/rgw_rados.h | 5 | ||||
-rw-r--r-- | src/rgw/rgw_rest_client.cc | 23 | ||||
-rw-r--r-- | src/rgw/rgw_rest_client.h | 2 | ||||
-rw-r--r-- | src/rgw/rgw_rest_conn.cc | 14 | ||||
-rw-r--r-- | src/rgw/rgw_rest_conn.h | 1 |
8 files changed, 78 insertions, 3 deletions
diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 5b737fec653..f2e97d19810 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -1742,8 +1742,6 @@ int RGWCopyObj::verify_permission() if (ret < 0) return ret; - RGWBucketInfo src_bucket_info, dest_bucket_info; - /* get buckets info (source and dest) */ ret = store->get_bucket_info(s->obj_ctx, src_bucket_name, src_bucket_info, NULL); @@ -1838,11 +1836,28 @@ void RGWCopyObj::execute() src_obj.init(src_bucket, src_object); dst_obj.init(dest_bucket, dest_object); store->set_atomic(s->obj_ctx, src_obj); +#if 0 + + if ((dest_bucket_info.region.empty() && !store->region.is_master) || + (dest_bucket_info.region != store->region.name)) { + + map<string, bufferlist> src_attrs; + + int ret = get_obj_attrs(store, s, src_obj, src_attrs + uint64_t *obj_size, RGWObjVersionTracker *objv_tracker) + + int ret = store->rest_conn->put_obj(s->user.user_id, dst_obj, + if (ret < 0) + return ret; + } +#endif store->set_atomic(s->obj_ctx, dst_obj); ret = store->copy_obj(s->obj_ctx, + s->user.user_id, dst_obj, src_obj, + dest_bucket_info, &mtime, mod_ptr, unmod_ptr, diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index aed43671c75..55011b4102f 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -441,6 +441,9 @@ protected: string dest_object; time_t mtime; bool replace_attrs; + RGWBucketInfo src_bucket_info; + RGWBucketInfo dest_bucket_info; + int init_common(); diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index e634b617d80..4ae126e8348 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -1871,8 +1871,10 @@ bool RGWRados::aio_completed(void *handle) * Returns: 0 on success, -ERR# otherwise. */ int RGWRados::copy_obj(void *ctx, + const string& user_id, rgw_obj& dest_obj, rgw_obj& src_obj, + RGWBucketInfo& dest_bucket_info, time_t *mtime, const time_t *mod_ptr, const time_t *unmod_ptr, @@ -1942,6 +1944,18 @@ int RGWRados::copy_obj(void *ctx, } } + + if ((dest_bucket_info.region.empty() && !region.is_master) || + (dest_bucket_info.region != region.name)) { + /* dest is in a different region, copy it there */ + + map<string, bufferlist> src_attrs; + + int ret = rest_conn->put_obj(user_id, dest_obj, astate->size, NULL); + if (ret < 0) + return ret; + } + if (copy_data) { /* refcounting tail wouldn't work here, just copy the data */ return copy_obj_data(ctx, handle, end, dest_obj, src_obj, mtime, attrset, category, ptag, err); } diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 9417c24d5fd..d6897823794 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -759,8 +759,11 @@ public: * err: stores any errors resulting from the get of the original object * Returns: 0 on success, -ERR# otherwise. */ - virtual int copy_obj(void *ctx, rgw_obj& dest_obj, + virtual int copy_obj(void *ctx, + const string& user_id, + rgw_obj& dest_obj, rgw_obj& src_obj, + RGWBucketInfo& dest_bucket_info, time_t *mtime, const time_t *mod_ptr, const time_t *unmod_ptr, diff --git a/src/rgw/rgw_rest_client.cc b/src/rgw/rgw_rest_client.cc index 4c4c43d3415..d7c0a9596a9 100644 --- a/src/rgw/rgw_rest_client.cc +++ b/src/rgw/rgw_rest_client.cc @@ -233,3 +233,26 @@ int RGWRESTClient::forward_request(RGWAccessKey& key, req_info& info, size_t max return rgw_http_error_to_errno(status); } + +int RGWRESTClient::put_obj(RGWAccessKey& key, rgw_obj& obj, uint64_t obj_size, void (*get_data)(uint64_t ofs, uint64_t len, bufferlist& bl, void *)) +{ + string resource = obj.bucket.name + "/" + obj.object; + string new_url = url + "/" + resource; + string date_str; + get_new_date_str(cct, date_str); + + RGWEnv new_env; + req_info new_info(cct, &new_env); + + new_env.set("HTTP_DATE", date_str.c_str()); + + new_info.script_uri = resource; + new_info.request_uri = resource; + + int r = process("PUT", new_url.c_str()); + if (r < 0) + return r; + + return 0; +} + diff --git a/src/rgw/rgw_rest_client.h b/src/rgw/rgw_rest_client.h index 5e871bbdd96..1b3b46bcf3d 100644 --- a/src/rgw/rgw_rest_client.h +++ b/src/rgw/rgw_rest_client.h @@ -42,6 +42,8 @@ public: int execute(RGWAccessKey& key, const char *method, const char *resource); int forward_request(RGWAccessKey& key, req_info& info, size_t max_response, bufferlist *inbl, bufferlist *outbl); + + int put_obj(RGWAccessKey& key, rgw_obj& obj, uint64_t obj_size, void (*get_data)(uint64_t ofs, uint64_t len, bufferlist& bl, void *)); }; diff --git a/src/rgw/rgw_rest_conn.cc b/src/rgw/rgw_rest_conn.cc index 66d5d9bf484..ddcad57f4e8 100644 --- a/src/rgw/rgw_rest_conn.cc +++ b/src/rgw/rgw_rest_conn.cc @@ -40,3 +40,17 @@ int RGWRegionConnection::forward(const string& uid, req_info& info, size_t max_r return client.forward_request(key, info, max_response, inbl, outbl); } +int RGWRegionConnection::put_obj(const string& uid, rgw_obj& obj, uint64_t obj_size, void (*get_data)(uint64_t ofs, uint64_t len, bufferlist& bl, void *)) +{ + string url; + int ret = get_url(url); + if (ret < 0) + return ret; + + list<pair<string, string> > params; + params.push_back(make_pair<string, string>(RGW_SYS_PARAM_PREFIX "uid", uid)); + params.push_back(make_pair<string, string>(RGW_SYS_PARAM_PREFIX "region", region)); + RGWRESTClient client(cct, url, NULL, ¶ms); + return client.put_obj(key, obj, obj_size, get_data); +} + diff --git a/src/rgw/rgw_rest_conn.h b/src/rgw/rgw_rest_conn.h index 6b296342d93..00bb286b130 100644 --- a/src/rgw/rgw_rest_conn.h +++ b/src/rgw/rgw_rest_conn.h @@ -20,6 +20,7 @@ public: int get_url(string& endpoint); int forward(const string& uid, req_info& info, size_t max_response, bufferlist *inbl, bufferlist *outbl); + int put_obj(const string& uid, rgw_obj& obj, uint64_t obj_size, void (*get_data)(uint64_t ofs, uint64_t len, bufferlist& bl, void *)); }; #endif |