Skip to content

Commit baa6b7b

Browse files
authored
Merge pull request ceph#60151 from shreyanshjain7174/wip-skoduri-cloud-restore
rgw/restore: Fixed status codes and response headers Reviewed-by: Soumya Koduri <[email protected]>
2 parents b3d0757 + b027d43 commit baa6b7b

File tree

5 files changed

+89
-70
lines changed

5 files changed

+89
-70
lines changed

src/rgw/driver/rados/rgw_rados.cc

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5252,13 +5252,7 @@ int RGWRados::restore_obj_from_cloud(RGWLCCloudTierCtx& tier_ctx,
52525252

52535253
ceph::real_time restore_time = real_clock::now();
52545254
{
5255-
char buf[32];
5256-
utime_t ut(restore_time);
5257-
snprintf(buf, sizeof(buf), "%lld.%09lld",
5258-
(long long)ut.sec(),
5259-
(long long)ut.nsec());
52605255
bufferlist bl;
5261-
bl.append(buf, 32);
52625256
encode(restore_time, bl);
52635257
attrs[RGW_ATTR_RESTORE_TIME] = std::move(bl);
52645258
}
@@ -5278,13 +5272,7 @@ int RGWRados::restore_obj_from_cloud(RGWLCCloudTierCtx& tier_ctx,
52785272
delete_at = expiration_date;
52795273

52805274
{
5281-
char buf[32];
5282-
utime_t ut(expiration_date);
5283-
snprintf(buf, sizeof(buf), "%lld.%09lld",
5284-
(long long)ut.sec(),
5285-
(long long)ut.nsec());
52865275
bufferlist bl;
5287-
bl.append(buf, 32);
52885276
encode(expiration_date, bl);
52895277
attrs[RGW_ATTR_RESTORE_EXPIRY_DATE] = std::move(bl);
52905278
}

src/rgw/rgw_admin.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8623,6 +8623,10 @@ int main(int argc, const char **argv)
86238623
handled = decode_dump<uint64_t>("pg_ver", bl, formatter.get());
86248624
} else if (iter->first == RGW_ATTR_SOURCE_ZONE) {
86258625
handled = decode_dump<uint32_t>("source_zone", bl, formatter.get());
8626+
} else if (iter->first == RGW_ATTR_RESTORE_EXPIRY_DATE) {
8627+
handled = decode_dump<utime_t>("restore_expiry_date", bl, formatter.get());
8628+
} else if (iter->first == RGW_ATTR_RESTORE_TIME) {
8629+
handled = decode_dump<utime_t>("restore_time", bl, formatter.get());
86268630
}
86278631

86288632
if (!handled)

src/rgw/rgw_op.cc

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,17 @@ void handle_replication_status_header(
943943
/*
944944
* GET on CloudTiered objects either it will synced to other zones.
945945
* In all other cases, it will try to fetch the object from remote cloud endpoint.
946+
*
947+
* @return:
948+
* Note - return status may differ based on whether it is RESTORE op or
949+
* READTHROUGH/GET op.
950+
* for e.g, ERR_INVALID_OBJECT_STATE is sent for non cloud-transitioned
951+
* incase of restore op and ERR_REQUEST_TIMEOUT is applicable only for
952+
* read-through etc.
953+
* `<0` : failed to process; s->err.message & op_ret set accrodingly
954+
* `0` : restore request initiated
955+
* `1` : restore is already in progress
956+
* `2` : already restored
946957
*/
947958
int handle_cloudtier_obj(req_state* s, const DoutPrefixProvider *dpp, rgw::sal::Driver* driver,
948959
rgw::sal::Attrs& attrs, bool sync_cloudtiered, std::optional<uint64_t> days,
@@ -1051,12 +1062,17 @@ int handle_cloudtier_obj(req_state* s, const DoutPrefixProvider *dpp, rgw::sal::
10511062
s->err.message = "restore is still in progress";
10521063
}
10531064
return op_ret;
1054-
} else if ((!restore_op) && (restore_status == rgw::sal::RGWRestoreStatus::RestoreAlreadyInProgress)) {
1055-
op_ret = -ERR_REQUEST_TIMEOUT;
1056-
ldpp_dout(dpp, 5) << "restore is still in progress, please check restore status and retry" << dendl;
1057-
s->err.message = "restore is still in progress";
1058-
} else { // CloudRestored..return success
1059-
return 0;
1065+
} else if (restore_status == rgw::sal::RGWRestoreStatus::RestoreAlreadyInProgress) {
1066+
if (!restore_op) {
1067+
op_ret = -ERR_REQUEST_TIMEOUT;
1068+
ldpp_dout(dpp, 5) << "restore is still in progress, please check restore status and retry" << dendl;
1069+
s->err.message = "restore is still in progress";
1070+
return op_ret;
1071+
} else {
1072+
return 1; // for restore-op, corresponds to RESTORE_ALREADY_IN_PROGRESS
1073+
}
1074+
} else {
1075+
return 2; // corresponds to CLOUD_RESTORED
10601076
}
10611077
} catch (const buffer::end_of_buffer&) {
10621078
//empty manifest; it's not cloud-tiered
@@ -5282,33 +5298,14 @@ void RGWRestoreObj::execute(optional_yield y)
52825298
int op_ret = s->object->get_obj_attrs(y, this);
52835299
if (op_ret < 0) {
52845300
ldpp_dout(this, 1) << "failed to fetch get_obj_attrs op ret = " << op_ret << dendl;
5301+
restore_ret = op_ret;
52855302
return;
52865303
}
5287-
rgw::sal::Attrs attrs = s->object->get_attrs();
5288-
auto attr_iter = attrs.find(RGW_ATTR_MANIFEST);
5289-
if (attr_iter != attrs.end()) {
5290-
RGWObjManifest m;
5291-
decode(m, attr_iter->second);
5292-
RGWObjTier tier_config;
5293-
m.get_tier_config(&tier_config);
5294-
if (m.get_tier_type() == "cloud-s3") {
5295-
ldpp_dout(this, 20) << "execute: expiry days" << expiry_days <<dendl;
5296-
op_ret = handle_cloudtier_obj(s, this, driver, attrs, false, expiry_days, true, y);
5297-
if (op_ret < 0) {
5298-
ldpp_dout(this, 4) << "Cannot get cloud tiered object: " << *s->object
5299-
<<". Failing with " << op_ret << dendl;
5300-
if (op_ret == -ERR_INVALID_OBJECT_STATE) {
5301-
s->err.message = "This object was transitioned to cloud-s3";
5302-
}
5303-
}
5304-
} else {
5305-
ldpp_dout(this, 20) << "not cloud tier object erroring" << dendl;
5306-
op_ret = -ERR_INVALID_OBJECT_STATE;
5307-
}
5308-
} else {
5309-
ldpp_dout(this, 20) << " manifest not found" << dendl;
5310-
}
5311-
ldpp_dout(this, 20) << "completed restore" << dendl;
5304+
rgw::sal::Attrs attrs;
5305+
attrs = s->object->get_attrs();
5306+
op_ret = handle_cloudtier_obj(s, this, driver, attrs, false, expiry_days, true, y);
5307+
restore_ret = op_ret;
5308+
ldpp_dout(this, 20) << "Restore completed of object: " << *s->object << "with op ret: " << restore_ret <<dendl;
53125309

53135310
return;
53145311
}

src/rgw/rgw_op.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,7 @@ class RGWPutMetadataObject : public RGWOp {
14641464
class RGWRestoreObj : public RGWOp {
14651465
protected:
14661466
std::optional<uint64_t> expiry_days;
1467+
int restore_ret;
14671468
public:
14681469
RGWRestoreObj() {}
14691470

src/rgw/rgw_rest_s3.cc

Lines changed: 56 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,7 @@ int RGWGetObj_ObjStore_S3::send_response_data(bufferlist& bl, off_t bl_ofs,
449449
dump_content_length(s, total_len);
450450
dump_last_modified(s, lastmod);
451451
dump_header_if_nonempty(s, "x-amz-version-id", version_id);
452-
dump_header_if_nonempty(s, "x-amz-expiration", expires);
453-
452+
dump_header_if_nonempty(s, "x-amz-expiration", expires);
454453
if (attrs.find(RGW_ATTR_APPEND_PART_NUM) != attrs.end()) {
455454
dump_header(s, "x-rgw-object-type", "Appendable");
456455
dump_header(s, "x-rgw-next-append-position", s->obj_size);
@@ -526,7 +525,29 @@ int RGWGetObj_ObjStore_S3::send_response_data(bufferlist& bl, off_t bl_ofs,
526525
auto iter = bl.cbegin();
527526
decode(rt, iter);
528527

528+
rgw::sal::RGWRestoreStatus restore_status;
529+
attr_iter = attrs.find(RGW_ATTR_RESTORE_STATUS);
530+
if (attr_iter != attrs.end()) {
531+
bufferlist bl = attr_iter->second;
532+
auto iter = bl.cbegin();
533+
decode(restore_status, iter);
534+
}
535+
536+
//restore status
537+
if (restore_status == rgw::sal::RGWRestoreStatus::RestoreAlreadyInProgress) {
538+
dump_header(s, "x-amz-restore", "ongoing-request=\"true\"");
539+
}
529540
if (rt == rgw::sal::RGWRestoreType::Temporary) {
541+
auto expire_iter = attrs.find(RGW_ATTR_RESTORE_EXPIRY_DATE);
542+
ceph::real_time expiration_date;
543+
544+
if (expire_iter != attrs.end()) {
545+
bufferlist bl = expire_iter->second;
546+
auto iter = bl.cbegin();
547+
decode(expiration_date, iter);
548+
}
549+
//restore status
550+
dump_header_if_nonempty(s, "x-amz-restore", "ongoing-request=\"false\", expiry-date=\""+ dump_time_to_str(expiration_date) +"\"");
530551
// temporary restore; set storage-class to cloudtier storage class
531552
auto c_iter = attrs.find(RGW_ATTR_CLOUDTIER_STORAGE_CLASS);
532553

@@ -3519,38 +3540,46 @@ int RGWRestoreObj_ObjStore_S3::get_params(optional_yield y)
35193540

35203541
void RGWRestoreObj_ObjStore_S3::send_response()
35213542
{
3522-
if (op_ret < 0)
3523-
{
3524-
set_req_state_err(s, op_ret);
3543+
if (restore_ret < 0) {
3544+
set_req_state_err(s, restore_ret);
35253545
dump_errno(s);
35263546
end_header(s, this);
35273547
dump_start(s);
35283548
return;
35293549
}
35303550

3531-
rgw::sal::Attrs attrs = s->object->get_attrs();
3532-
auto attr_iter = attrs.find(RGW_ATTR_RESTORE_STATUS);
3533-
rgw::sal::RGWRestoreStatus restore_status;
3534-
if (attr_iter != attrs.end()) {
3535-
bufferlist bl = attr_iter->second;
3536-
auto iter = bl.cbegin();
3537-
decode(restore_status, iter);
3538-
}
3539-
ldpp_dout(this, 10) << "restore_status=" << restore_status << dendl;
3540-
3541-
if (attr_iter == attrs.end() || restore_status != rgw::sal::RGWRestoreStatus::None) {
3542-
s->err.http_ret = 202; //Accepted
3543-
dump_header(s, "x-amz-restore", rgw_bl_str(restore_status));
3544-
} else if (restore_status != rgw::sal::RGWRestoreStatus::RestoreAlreadyInProgress) {
3551+
if (restore_ret == 0) {
3552+
s->err.http_ret = 202; // OK
3553+
} else if (restore_ret == 1) {
35453554
s->err.http_ret = 409; // Conflict
3546-
dump_header_if_nonempty(s, "x-amz-restore", rgw_bl_str(restore_status));
3547-
} else if (restore_status != rgw::sal::RGWRestoreStatus::CloudRestored) {
3548-
s->err.http_ret = 200; // OK
3549-
dump_header_if_nonempty(s, "x-amz-restore", rgw_bl_str(restore_status));
3550-
} else {
3551-
s->err.http_ret = 202; // Accepted
3552-
dump_header_if_nonempty(s, "x-amz-restore", rgw_bl_str(restore_status));
3553-
}
3555+
dump_header(s, "x-amz-restore", "on-going-request=\"true\"");
3556+
} else if (restore_ret == 2) {
3557+
rgw::sal::Attrs attrs;
3558+
ceph::real_time expiration_date;
3559+
rgw::sal::RGWRestoreType rt;
3560+
attrs = s->object->get_attrs();
3561+
auto expire_iter = attrs.find(RGW_ATTR_RESTORE_EXPIRY_DATE);
3562+
auto type_iter = attrs.find(RGW_ATTR_RESTORE_TYPE);
3563+
3564+
if (expire_iter != attrs.end()) {
3565+
bufferlist bl = expire_iter->second;
3566+
auto iter = bl.cbegin();
3567+
decode(expiration_date, iter);
3568+
}
3569+
3570+
if (type_iter != attrs.end()) {
3571+
bufferlist bl = type_iter->second;
3572+
auto iter = bl.cbegin();
3573+
decode(rt, iter);
3574+
}
3575+
if (rt == rgw::sal::RGWRestoreType::Temporary) {
3576+
s->err.http_ret = 200; // OK
3577+
dump_header(s, "x-amz-restore", "ongoing-request=\"false\", expiry-date=\""+ dump_time_to_str(expiration_date) +"\"");
3578+
} else {
3579+
s->err.http_ret = 200;
3580+
dump_header(s, "x-amz-restore", "ongoing-request=\"false\"");
3581+
}
3582+
}
35543583

35553584
dump_errno(s);
35563585
end_header(s, this);

0 commit comments

Comments
 (0)