Skip to content

Commit

Permalink
rgw: handle the situation that get a 409 response from S3 correctly
Browse files Browse the repository at this point in the history
pass the http body and use it when creating a bucket

Signed-off-by: lvshanchun <lvshanchun@gmail.com>
  • Loading branch information
Leeshine committed Dec 14, 2017
1 parent aba9f4e commit 1bb6669
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/rgw/rgw_rest_conn.h
Expand Up @@ -411,14 +411,14 @@ class RGWRESTSendResource : public RefCountedObject, public RGWIOProvider {

int wait(bufferlist *pbl) {
int ret = req.wait();
*pbl = bl;
if (ret < 0) {
return ret;
}

if (req.get_status() < 0) {
return req.get_status();
}
*pbl = bl;
return 0;
}

Expand Down
40 changes: 36 additions & 4 deletions src/rgw/rgw_sync_module_aws.cc
Expand Up @@ -767,6 +767,16 @@ class RGWAWSHandleRemoteObjCBCR: public RGWStatRemoteObjCBCR {
uint32_t src_zone_short_id{0};
uint64_t src_pg_ver{0};

bufferlist out_bl;

struct CreateBucketResult {
string code;

void decode_xml(XMLObj *obj) {
RGWXMLDecoder::decode_xml("Code", code, obj);
}
} result;

public:
RGWAWSHandleRemoteObjCBCR(RGWDataSyncEnv *_sync_env,
RGWBucketInfo& _bucket_info,
Expand Down Expand Up @@ -808,12 +818,34 @@ class RGWAWSHandleRemoteObjCBCR: public RGWStatRemoteObjCBCR {
yield {
ldout(sync_env->cct,0) << "AWS: creating bucket" << target_bucket_name << dendl;
bufferlist bl;
call(new RGWPutRawRESTResourceCR <int> (sync_env->cct, instance.conn.get(),
call(new RGWPutRawRESTResourceCR <bufferlist> (sync_env->cct, instance.conn.get(),
sync_env->http_manager,
target_bucket_name, nullptr, bl, nullptr));
target_bucket_name, nullptr, bl, &out_bl));
}
if (retcode < 0) {
return set_cr_error(retcode);
if (retcode < 0 ) {
RGWXMLDecoder::XMLParser parser;
if (!parser.init()) {
ldout(sync_env->cct, 0) << "ERROR: failed to initialize xml parser for parsing multipart init response from server" << dendl;
return set_cr_error(retcode);
}

if (!parser.parse(out_bl.c_str(), out_bl.length(), 1)) {
string str(out_bl.c_str(), out_bl.length());
ldout(sync_env->cct, 5) << "ERROR: failed to parse xml: " << str << dendl;
return set_cr_error(retcode);
}

try {
RGWXMLDecoder::decode_xml("Error", result, &parser, true);
} catch (RGWXMLDecoder::err& err) {
string str(out_bl.c_str(), out_bl.length());
ldout(sync_env->cct, 5) << "ERROR: unexpected xml: " << str << dendl;
return set_cr_error(retcode);
}

if (result.code != "BucketAlreadyOwnedByYou") {
return set_cr_error(retcode);
}
}

bucket_created[target_bucket_name] = true;
Expand Down

0 comments on commit 1bb6669

Please sign in to comment.