From 89f9d0a935bbd040303e853f59d2c17939697e9b Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Tue, 18 Aug 2015 17:14:05 -0700 Subject: [PATCH] rgw: read remote meta coroutine Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_rest_client.h | 1 + src/rgw/rgw_rest_conn.h | 14 ++++++++- src/rgw/rgw_sync.cc | 62 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 75 insertions(+), 2 deletions(-) diff --git a/src/rgw/rgw_rest_client.h b/src/rgw/rgw_rest_client.h index 5a6c4198fddd1..e607dbacde0a5 100644 --- a/src/rgw/rgw_rest_client.h +++ b/src/rgw/rgw_rest_client.h @@ -61,6 +61,7 @@ public: map& get_out_headers() { return out_headers; } int get_http_status() { return http_status; } + int get_status() { return status; } }; diff --git a/src/rgw/rgw_rest_conn.h b/src/rgw/rgw_rest_conn.h index c8b88b9667f67..0d7735a4041b5 100644 --- a/src/rgw/rgw_rest_conn.h +++ b/src/rgw/rgw_rest_conn.h @@ -166,6 +166,14 @@ public: return req.get_http_status(); } + int wait_bl(bufferlist *pbl) { + if (req.get_status() < 0) { + return req.get_status(); + } + *pbl = bl; + return 0; + } + template int wait(T *dest); @@ -177,7 +185,11 @@ public: template int RGWRESTReadResource::decode_resource(T *dest) { - int ret = parse_decode_json(cct, *dest, bl); + int ret = req.get_status(); + if (ret < 0) { + return ret; + } + ret = parse_decode_json(cct, *dest, bl); if (ret < 0) { return ret; } diff --git a/src/rgw/rgw_sync.cc b/src/rgw/rgw_sync.cc index 6be3865924f37..bf4587a7ef859 100644 --- a/src/rgw/rgw_sync.cc +++ b/src/rgw/rgw_sync.cc @@ -1059,6 +1059,66 @@ static string full_sync_index_shard_oid(int shard_id) return string(buf); } +template +class RGWReadRemoteMetadataCR : public RGWCoroutine { + RGWRados *store; + RGWHTTPManager *http_manager; + RGWAsyncRadosProcessor *async_rados; + + RGWRESTReadResource *http_op; + + string section; + string key; + + bufferlist *pbl; + +public: + RGWReadRemoteMetadataCR(RGWRados *_store, RGWHTTPManager *_mgr, RGWAsyncRadosProcessor *_async_rados, + const string& _section, const string& _key, bufferlist *_pbl) : RGWCoroutine(_store->ctx()), store(_store), + http_manager(_mgr), + async_rados(_async_rados), + http_op(NULL), + section(_section), + key(_key), + pbl(_pbl) { + } + + int operate() { + RGWRESTConn *conn = store->rest_master_conn; + reenter(this) { + yield { + rgw_http_param_pair pairs[] = { { NULL, NULL } }; + + string p = string("/metadata") + section + "/" + key; + + http_op = new RGWRESTReadResource(conn, p, pairs, NULL, http_manager); + + http_op->set_user_info((void *)stack); + + int ret = http_op->aio_read(); + if (ret < 0) { + ldout(store->ctx(), 0) << "ERROR: failed to fetch mdlog data" << dendl; + log_error() << "failed to send http operation: " << http_op->to_str() << " ret=" << ret << std::endl; + http_op->put(); + return set_state(RGWCoroutine_Error, ret); + } + + return io_block(0); + } + yield { + int ret = http_op->wait_bl(pbl); + if (ret < 0) { + return set_state(RGWCoroutine_Error, ret); + } + return set_state(RGWCoroutine_Done, 0); + } + } + return 0; + } +}; + + + class RGWMetaSyncShardCR : public RGWCoroutine { RGWRados *store; RGWHTTPManager *http_manager; @@ -1108,7 +1168,7 @@ public: // update shard marker } } - } while (entries.size() == max_entries); + } while ((int)entries.size() == max_entries); // update shard state return set_state(RGWCoroutine_Done, 0); } else if (sync_marker.state == rgw_meta_sync_marker::IncrementalSync) { -- 2.39.5