]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: add location when data in another region. 2801/head
authorVRan Liu <gliuwr@gmail.com>
Fri, 14 Nov 2014 08:27:17 +0000 (16:27 +0800)
committerVRan Liu <gliuwr@gmail.com>
Fri, 14 Nov 2014 09:11:21 +0000 (17:11 +0800)
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 <gliuwr@gmail.com>
src/rgw/rgw_common.h
src/rgw/rgw_op.cc
src/rgw/rgw_rest.cc

index 1170650b56aaef476decca088980b6b7c4bbfed2..19980031aeb0fa4bc4509e3278371eb7b4c29fb4 100644 (file)
@@ -885,6 +885,7 @@ struct req_state {
    ACLOwner bucket_owner;
    ACLOwner owner;
 
+   string region_endpoint;
    string bucket_instance_id;
 
    RGWBucketInfo bucket_info;
index 7522fc52a5324790ba190ac739c6ff21183af359..aea24e95df5e30749c8c9200888abb6d458918b2 100644 (file)
@@ -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<string, RGWRegion>::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
index 153628d5722c9faca19ea1f7fbc5356ef9da3057..751b2054b4a711fa1c36f49d2b6bbceee4a7048b 100644 (file)
@@ -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);