]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: initial work on mdlog sync
authorYehuda Sadeh <yehuda@redhat.com>
Wed, 1 Jul 2015 23:25:00 +0000 (16:25 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Tue, 9 Feb 2016 20:45:02 +0000 (12:45 -0800)
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/Makefile.am
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h
src/rgw/rgw_rest_client.cc
src/rgw/rgw_rest_client.h
src/rgw/rgw_rest_conn.cc
src/rgw/rgw_rest_conn.h
src/rgw/rgw_sync.cc [new file with mode: 0644]

index 0fcc93df2b6f946a9d73d74211cf0b758367eded..a848d2b2865402cdbbe31e506c030153979b4c0c 100644 (file)
@@ -48,6 +48,7 @@ librgw_la_SOURCES =  \
        rgw/rgw_replica_log.cc \
        rgw/rgw_keystone.cc \
        rgw/rgw_quota.cc \
+       rgw/rgw_sync.cc \
        rgw/rgw_dencoder.cc \
        rgw/rgw_object_expirer_core.cc \
        rgw/rgw_website.cc
index 7153cee44cac32805790747febad6903314e9cf7..120c04cf68b76748829588ac8471044e360e5877 100644 (file)
@@ -4517,6 +4517,15 @@ int RGWRados::copy_obj_data(RGWObjectCtx& obj_ctx,
   return ret;
 }
 
+bool RGWRados::is_meta_master()
+{
+  if (!region.is_master) {
+    return false;
+  }
+
+  return (region.master_zone == zone_public_config.name);
+}
+
 /**
   * Check to see if the bucket metadata could be synced
   * bucket: the bucket to check
index 30a7772a7abf334df2cb3e246968db54935e47b0..fa4047774b92309a93cd7ecf546e62522fefa371 100644 (file)
@@ -1938,6 +1938,8 @@ public:
    */
   virtual int delete_bucket(rgw_bucket& bucket, RGWObjVersionTracker& objv_tracker);
 
+  bool is_meta_master();
+
   /**
    * Check to see if the bucket metadata is synced
    */
index 4ca88abbc8b818872bc49bbb3f7a8f9f2679f472..5996a4c12ff7e90cd2687c85aa34c18a71e98619 100644 (file)
@@ -546,6 +546,12 @@ int RGWRESTStreamReadRequest::get_obj(RGWAccessKey& key, map<string, string>& ex
   url_encode(obj.bucket.name, urlsafe_bucket);
   url_encode(obj.get_object(), urlsafe_object);
   string resource = urlsafe_bucket + "/" + urlsafe_object;
+
+  return get_resource(key, extra_headers, resource);
+}
+
+int RGWRESTStreamReadRequest::get_resource(RGWAccessKey& key, map<string, string>& extra_headers, const string& resource)
+{
   string new_url = url;
   if (new_url[new_url.size() - 1] != '/')
     new_url.append("/");
@@ -560,7 +566,14 @@ int RGWRESTStreamReadRequest::get_obj(RGWAccessKey& key, map<string, string>& ex
   map<string, string>& args = new_info.args.get_params();
   get_params_str(args, params_str);
 
-  new_url.append(resource + params_str);
+  string new_resource;
+  if (resource[0] == '/') {
+    new_resource = resource.substr(1);
+  } else {
+    new_resource = resource;
+  }
+
+  new_url.append(new_resource + params_str);
 
   new_env.set("HTTP_DATE", date_str.c_str());
 
@@ -572,7 +585,7 @@ int RGWRESTStreamReadRequest::get_obj(RGWAccessKey& key, map<string, string>& ex
   new_info.method = "GET";
 
   new_info.script_uri = "/";
-  new_info.script_uri.append(resource);
+  new_info.script_uri.append(new_resource);
   new_info.request_uri = new_info.script_uri;
 
   new_info.init_meta_info(NULL);
index ccbb01c7257466857d1fb384733ce06419dc6c71..694984a29e277ebc6dcedd6e185e76e61812c9e3 100644 (file)
@@ -92,6 +92,7 @@ public:
                 chunk_ofs(0), ofs(0) {}
   ~RGWRESTStreamReadRequest() {}
   int get_obj(RGWAccessKey& key, map<string, string>& extra_headers, rgw_obj& obj);
+  int get_resource(RGWAccessKey& key, map<string, string>& extra_headers, const string& resource);
   int complete(string& etag, time_t *mtime, map<string, string>& attrs);
 
   void set_in_cb(RGWGetDataCB *_cb) { cb = _cb; }
index e278ad2d3cf7a2367bb29c7419ead12e4317c7a3..283882209680d2653ca3f4fad765d2b9b3e7e925 100644 (file)
@@ -122,4 +122,58 @@ int RGWRESTConn::complete_request(RGWRESTStreamReadRequest *req, string& etag, t
   return ret;
 }
 
+class StreamIntoBufferlist : public RGWGetDataCB {
+  bufferlist& bl;
+public:
+  StreamIntoBufferlist(bufferlist& _bl) : bl(_bl) {}
+  int handle_data(bufferlist& inbl, off_t bl_ofs, off_t bl_len) {
+    bl.claim_append(inbl);
+    return bl_len;
+  }
+};
+
+int RGWRESTConn::get_resource(const string& resource,
+                    list<pair<string, string> > *extra_params,
+                    map<string, string> *extra_headers,
+                    bufferlist& bl)
+{
+  string url;
+  int ret = get_url(url);
+  if (ret < 0)
+    return ret;
+
+  list<pair<string, string> > params;
+
+  if (extra_params) {
+    list<pair<string, string> >::iterator iter = extra_params->begin();
+    for (; iter != extra_params->end(); ++iter) {
+      params.push_back(*iter);
+    }
+  }
+
+  params.push_back(pair<string, string>(RGW_SYS_PARAM_PREFIX "region", region));
+
+  StreamIntoBufferlist cb(bl);
+
+  RGWRESTStreamReadRequest req(cct, url, &cb, NULL, &params);
+
+  map<string, string> headers;
+  if (extra_headers) {
+    for (map<string, string>::iterator iter = extra_headers->begin();
+        iter != extra_headers->end(); ++iter) {
+      headers[iter->first] = iter->second;
+    }
+  }
+
+  ret = req.get_resource(key, headers, resource);
+  if (ret < 0) {
+    ldout(cct, 0) << __func__ << ": get_resource() resource=" << resource << " returned ret=" << ret << dendl;
+    return ret;
+  }
+
+  string etag;
+  map<string, string> attrs;
+  return req.complete(etag, NULL, attrs);
+}
+
 
index d7620da39b32a9edf7f075c6206f139c47f2ce15..b5097f9d3a6ca5e626babc3bdf5dc7803f3146ee 100644 (file)
@@ -32,6 +32,11 @@ public:
 
   int get_obj(const rgw_user& uid, req_info *info /* optional */, rgw_obj& obj, bool prepend_metadata, RGWGetDataCB *cb, RGWRESTStreamReadRequest **req);
   int complete_request(RGWRESTStreamReadRequest *req, string& etag, time_t *mtime, map<string, string>& attrs);
+
+  int get_resource(const string& resource,
+                   list<pair<string, string> > *extra_params,
+                   map<string, string>* extra_headers,
+                   bufferlist& bl);
 };
 
 #endif
diff --git a/src/rgw/rgw_sync.cc b/src/rgw/rgw_sync.cc
new file mode 100644 (file)
index 0000000..482f5e8
--- /dev/null
@@ -0,0 +1,70 @@
+#include "rgw_common.h"
+#include "rgw_rados.h"
+
+
+#define dout_subsys ceph_subsys_rgw
+
+
+class RGWRemoteMetaLog {
+
+  RGWRados *store;
+
+  int num_shards;
+
+  vector<string> markers;
+
+public:
+  RGWRemoteMetaLog(RGWRados *_store) : store(_store), num_shards(0) {}
+  int init();
+};
+
+int RGWRemoteMetaLog::init()
+{
+  list<pair<string, string> > params;
+  params.push_back(make_pair("type", "metadata"));
+
+  bufferlist bl;
+  int ret = store->rest_master_conn->get_resource("/admin/log", &params, NULL, bl);
+  if (ret < 0) {
+    lderr(store->ctx()) << "ERROR: failed to fetch log info from master, ret=" << ret << dendl;
+    return ret;
+  }
+
+  return 0;
+}
+
+
+
+class RGWMetadataSync {
+  RGWRados *store;
+
+  RGWRemoteMetaLog master_log;
+public:
+  RGWMetadataSync(RGWRados *_store) : store(_store), master_log(_store) {}
+
+  int init();
+
+};
+
+
+int RGWMetadataSync::init()
+{
+  if (store->is_meta_master()) {
+    return 0;
+  }
+
+  if (!store->rest_master_conn) {
+    lderr(store->ctx()) << "no REST connection to master zone" << dendl;
+    return -EIO;
+  }
+
+  int ret = master_log.init();
+  if (ret < 0) {
+    return ret;
+  }
+
+  return 0;
+}
+
+
+