From: VRan Liu Date: Fri, 14 Nov 2014 08:27:17 +0000 (+0800) Subject: rgw: add location when data in another region. X-Git-Tag: v0.90~87^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F2801%2Fhead;p=ceph.git rgw: add location when data in another region. When the bucket of requested is in another region, Add location header in response, so client can follow that to get data. Signed-off-by: VRan Liu --- diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index 1170650b56aae..19980031aeb0f 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -885,6 +885,7 @@ struct req_state { ACLOwner bucket_owner; ACLOwner owner; + string region_endpoint; string bucket_instance_id; RGWBucketInfo bucket_info; diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 7522fc52a5324..aea24e95df5e3 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -372,6 +372,10 @@ static int rgw_build_policies(RGWRados *store, struct req_state *s, bool only_bu s->bucket_owner = s->bucket_acl->get_owner(); string& region = s->bucket_info.region; + map::iterator dest_region = store->region_map.regions.find(region); + if (dest_region != store->region_map.regions.end()) { + s->region_endpoint = dest_region->second.endpoints.front(); + } if (s->bucket_exists && !store->region.equals(region)) { ldout(s->cct, 0) << "NOTICE: request for data in a different region (" << region << " != " << store->region.name << ")" << dendl; /* we now need to make sure that the operation actually requires copy source, that is diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index 153628d5722c9..751b2054b4a71 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -470,6 +470,21 @@ void abort_early(struct req_state *s, RGWOp *op, int err_no) set_req_state_err(s, err_no); dump_errno(s); dump_bucket_from_state(s); + if (err_no == -ERR_PERMANENT_REDIRECT && !s->region_endpoint.empty()) { + string dest_uri = s->region_endpoint; + /* + * reqest_uri is always start with slash, so we need to remove + * the unnecessary slash at the end of dest_uri. + */ + if (dest_uri[dest_uri.size() - 1] == '/') { + dest_uri = dest_uri.substr(0, dest_uri.size() - 1); + } + dest_uri += s->info.request_uri; + dest_uri += "?"; + dest_uri += s->info.request_params; + + dump_redirect(s, dest_uri); + } end_header(s, op); rgw_flush_formatter_and_reset(s, s->formatter); perfcounter->inc(l_rgw_failed_req);