rgw: add locators to the directory objects, and functions handling them

Signed-off-by: Greg Farnum <gregory.farnum@dreamhost.com>
This commit is contained in:
Greg Farnum 2011-10-20 17:00:12 -07:00
parent 0da45ca643
commit 927c357725
4 changed files with 50 additions and 12 deletions

View File

@ -162,6 +162,7 @@ int rgw_bucket_prepare_op(cls_method_context_t hctx, bufferlist *in, bufferlist
entry.name = op.name;
entry.epoch = 0;
entry.exists = false;
entry.locator = op.locator;
}
// fill in proper state
@ -209,6 +210,7 @@ int rgw_bucket_complete_op(cls_method_context_t hctx, bufferlist *in, bufferlist
entry.name = op.name;
entry.epoch = op.epoch;
entry.meta = op.meta;
entry.locator = op.locator;
ondisk = false;
}
} else {

View File

@ -84,6 +84,7 @@ WRITE_CLASS_ENCODER(rgw_bucket_dir_entry_meta)
struct rgw_bucket_dir_entry {
std::string name;
uint64_t epoch;
std::string locator;
bool exists;
struct rgw_bucket_dir_entry_meta meta;
map<string, struct rgw_bucket_pending_info> pending_map;
@ -92,13 +93,19 @@ struct rgw_bucket_dir_entry {
epoch(0), exists(false) {}
void encode(bufferlist &bl) const {
__u8 struct_v = 1;
__u8 struct_v = 2;
if (!locator.size()) {
struct_v = 1; // don't waste space encoding it
}
::encode(struct_v, bl);
::encode(name, bl);
::encode(epoch, bl);
::encode(exists, bl);
::encode(meta, bl);
::encode(pending_map, bl);
if (locator.size()) {
::encode(locator, bl);
}
}
void decode(bufferlist::iterator &bl) {
__u8 struct_v;
@ -108,6 +115,9 @@ struct rgw_bucket_dir_entry {
::decode(exists, bl);
::decode(meta, bl);
::decode(pending_map, bl);
if (struct_v >= 2) {
::decode(locator, bl);
}
}
};
WRITE_CLASS_ENCODER(rgw_bucket_dir_entry)
@ -174,13 +184,20 @@ struct rgw_cls_obj_prepare_op
uint8_t op;
string name;
string tag;
string locator;
void encode(bufferlist &bl) const {
__u8 struct_v = 1;
__u8 struct_v = 2;
if (!locator.size()) {
struct_v = 1; // don't waste the encoding space
}
::encode(struct_v, bl);
::encode(op, bl);
::encode(name, bl);
::encode(tag, bl);
if (locator.size()) {
::encode(locator, bl);
}
}
void decode(bufferlist::iterator &bl) {
__u8 struct_v;
@ -188,6 +205,9 @@ struct rgw_cls_obj_prepare_op
::decode(op, bl);
::decode(name, bl);
::decode(tag, bl);
if (struct_v >= 2) {
::decode(locator, bl);
}
}
};
WRITE_CLASS_ENCODER(rgw_cls_obj_prepare_op)
@ -196,19 +216,26 @@ struct rgw_cls_obj_complete_op
{
uint8_t op;
string name;
string locator;
uint64_t epoch;
struct rgw_bucket_dir_entry_meta meta;
string tag;
void encode(bufferlist &bl) const {
__u8 struct_v = 1;
__u8 struct_v = 2;
if (!locator.size()) {
struct_v = 1; // don't waste the encoding space
}
::encode(struct_v, bl);
::encode(op, bl);
::encode(name, bl);
::encode(epoch, bl);
::encode(meta, bl);
::encode(tag, bl);
}
if (locator.size()) {
::encode(locator, bl);
}
}
void decode(bufferlist::iterator &bl) {
__u8 struct_v;
::decode(struct_v, bl);
@ -217,6 +244,9 @@ struct rgw_cls_obj_complete_op
::decode(epoch, bl);
::decode(meta, bl);
::decode(tag, bl);
if (struct_v >= 2) {
::decode(locator, bl);
}
}
};
WRITE_CLASS_ENCODER(rgw_cls_obj_complete_op)

View File

@ -646,7 +646,7 @@ int RGWRados::put_obj_meta(void *ctx, std::string& id, rgw_obj& obj, uint64_t s
return 0;
string tag;
r = prepare_update_index(NULL, bucket, obj.object, tag);
r = prepare_update_index(NULL, bucket, obj, tag);
if (r < 0)
return r;
@ -1011,7 +1011,7 @@ int RGWRados::delete_obj_impl(void *ctx, std::string& id, rgw_obj& obj, bool syn
string tag;
op.remove();
if (sync) {
r = prepare_update_index(state, bucket, obj.object, tag);
r = prepare_update_index(state, bucket, obj, tag);
if (r < 0)
return r;
r = io_ctx.operate(oid, &op);
@ -1474,7 +1474,8 @@ done_err:
return r;
}
int RGWRados::prepare_update_index(RGWObjState *state, rgw_bucket& bucket, string& oid, string& tag)
int RGWRados::prepare_update_index(RGWObjState *state, rgw_bucket& bucket,
rgw_obj& obj, string& tag)
{
if (state && state->obj_tag.length()) {
int len = state->obj_tag.length();
@ -1485,7 +1486,8 @@ int RGWRados::prepare_update_index(RGWObjState *state, rgw_bucket& bucket, strin
} else {
append_rand_alpha(tag, tag, 32);
}
int ret = cls_obj_prepare_op(bucket, CLS_RGW_OP_ADD, tag, oid);
int ret = cls_obj_prepare_op(bucket, CLS_RGW_OP_ADD, tag,
obj.object, obj.key);
return ret;
}
@ -1607,7 +1609,7 @@ int RGWRados::clone_objs_impl(void *ctx, rgw_obj& dst_obj,
string tag;
uint64_t epoch = 0;
int ret = prepare_update_index(state, bucket, dst_obj.object, tag);
int ret = prepare_update_index(state, bucket, dst_obj, tag);
if (ret < 0)
goto done;
@ -2027,7 +2029,8 @@ int RGWRados::cls_rgw_init_index(rgw_bucket& bucket, string& oid)
return r;
}
int RGWRados::cls_obj_prepare_op(rgw_bucket& bucket, uint8_t op, string& tag, string& name)
int RGWRados::cls_obj_prepare_op(rgw_bucket& bucket, uint8_t op, string& tag,
string& name, string& locator)
{
if (bucket.marker.empty()) {
if (bucket.name[0] == '.')
@ -2050,6 +2053,7 @@ int RGWRados::cls_obj_prepare_op(rgw_bucket& bucket, uint8_t op, string& tag, st
call.op = op;
call.tag = tag;
call.name = name;
call.locator = locator;
::encode(call, in);
r = io_ctx.exec(oid, "rgw", "bucket_prepare_op", in, out);
return r;

View File

@ -300,7 +300,8 @@ public:
virtual int get_bucket_info(string& bucket_name, RGWBucketInfo& info);
int cls_rgw_init_index(rgw_bucket& bucket, string& oid);
int cls_obj_prepare_op(rgw_bucket& bucket, uint8_t op, string& tag, string& name);
int cls_obj_prepare_op(rgw_bucket& bucket, uint8_t op, string& tag,
string& name, string& locator);
int cls_obj_complete_op(rgw_bucket& bucket, uint8_t op, string& tag, uint64_t epoch,
RGWObjEnt& ent, RGWObjCategory category);
int cls_obj_complete_add(rgw_bucket& bucket, string& tag, uint64_t epoch, RGWObjEnt& ent, RGWObjCategory category);
@ -309,7 +310,8 @@ public:
map<string, RGWObjEnt>& m, bool *is_truncated,
string *last_entry = NULL);
int cls_bucket_head(rgw_bucket& bucket, struct rgw_bucket_dir_header& header);
int prepare_update_index(RGWObjState *state, rgw_bucket& bucket, string& oid, string& tag);
int prepare_update_index(RGWObjState *state, rgw_bucket& bucket,
rgw_obj& oid, string& tag);
int complete_update_index(rgw_bucket& bucket, string& oid, string& tag, uint64_t epoch, uint64_t size,
utime_t& ut, string& etag, bufferlist *acl_bl, RGWObjCategory category);
int complete_update_index_del(rgw_bucket& bucket, string& oid, string& tag, uint64_t epoch) {