From d5484ff2395da5cfb954cea7699db2a4394d4c9f Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Wed, 1 Jul 2015 16:25:00 -0700 Subject: [PATCH] rgw: initial work on mdlog sync Signed-off-by: Yehuda Sadeh --- src/rgw/Makefile.am | 1 + src/rgw/rgw_rados.cc | 9 +++++ src/rgw/rgw_rados.h | 2 ++ src/rgw/rgw_rest_client.cc | 17 +++++++-- src/rgw/rgw_rest_client.h | 1 + src/rgw/rgw_rest_conn.cc | 54 +++++++++++++++++++++++++++++ src/rgw/rgw_rest_conn.h | 5 +++ src/rgw/rgw_sync.cc | 70 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 src/rgw/rgw_sync.cc diff --git a/src/rgw/Makefile.am b/src/rgw/Makefile.am index 0fcc93df2b6f9..a848d2b286540 100644 --- a/src/rgw/Makefile.am +++ b/src/rgw/Makefile.am @@ -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 diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 7153cee44cac3..120c04cf68b76 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -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 diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 30a7772a7abf3..fa4047774b923 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -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 */ diff --git a/src/rgw/rgw_rest_client.cc b/src/rgw/rgw_rest_client.cc index 4ca88abbc8b81..5996a4c12ff7e 100644 --- a/src/rgw/rgw_rest_client.cc +++ b/src/rgw/rgw_rest_client.cc @@ -546,6 +546,12 @@ int RGWRESTStreamReadRequest::get_obj(RGWAccessKey& key, map& 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& 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& ex map& 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& 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); diff --git a/src/rgw/rgw_rest_client.h b/src/rgw/rgw_rest_client.h index ccbb01c725746..694984a29e277 100644 --- a/src/rgw/rgw_rest_client.h +++ b/src/rgw/rgw_rest_client.h @@ -92,6 +92,7 @@ public: chunk_ofs(0), ofs(0) {} ~RGWRESTStreamReadRequest() {} int get_obj(RGWAccessKey& key, map& extra_headers, rgw_obj& obj); + int get_resource(RGWAccessKey& key, map& extra_headers, const string& resource); int complete(string& etag, time_t *mtime, map& attrs); void set_in_cb(RGWGetDataCB *_cb) { cb = _cb; } diff --git a/src/rgw/rgw_rest_conn.cc b/src/rgw/rgw_rest_conn.cc index e278ad2d3cf7a..283882209680d 100644 --- a/src/rgw/rgw_rest_conn.cc +++ b/src/rgw/rgw_rest_conn.cc @@ -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 > *extra_params, + map *extra_headers, + bufferlist& bl) +{ + string url; + int ret = get_url(url); + if (ret < 0) + return ret; + + list > params; + + if (extra_params) { + list >::iterator iter = extra_params->begin(); + for (; iter != extra_params->end(); ++iter) { + params.push_back(*iter); + } + } + + params.push_back(pair(RGW_SYS_PARAM_PREFIX "region", region)); + + StreamIntoBufferlist cb(bl); + + RGWRESTStreamReadRequest req(cct, url, &cb, NULL, ¶ms); + + map headers; + if (extra_headers) { + for (map::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 attrs; + return req.complete(etag, NULL, attrs); +} + diff --git a/src/rgw/rgw_rest_conn.h b/src/rgw/rgw_rest_conn.h index d7620da39b32a..b5097f9d3a6ca 100644 --- a/src/rgw/rgw_rest_conn.h +++ b/src/rgw/rgw_rest_conn.h @@ -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& attrs); + + int get_resource(const string& resource, + list > *extra_params, + map* extra_headers, + bufferlist& bl); }; #endif diff --git a/src/rgw/rgw_sync.cc b/src/rgw/rgw_sync.cc new file mode 100644 index 0000000000000..482f5e82c165a --- /dev/null +++ b/src/rgw/rgw_sync.cc @@ -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 markers; + +public: + RGWRemoteMetaLog(RGWRados *_store) : store(_store), num_shards(0) {} + int init(); +}; + +int RGWRemoteMetaLog::init() +{ + list > params; + params.push_back(make_pair("type", "metadata")); + + bufferlist bl; + int ret = store->rest_master_conn->get_resource("/admin/log", ¶ms, 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; +} + + + -- 2.39.5