osd_types: add manifest type (chunked)

Signed-off-by: Myoungwon Oh <omwmw@sk.com>
This commit is contained in:
myoungwon oh 2017-06-02 13:14:20 +09:00
parent 3455a38f73
commit e968c64795
2 changed files with 106 additions and 6 deletions

View File

@ -4834,6 +4834,44 @@ void watch_info_t::generate_test_instances(list<watch_info_t*>& o)
o.back()->addr = ea;
}
// -- chunk_info_t --
void chunk_info_t::encode(bufferlist& bl) const
{
ENCODE_START(1, 1, bl);
::encode(offset, bl);
::encode(length, bl);
::encode(oid, bl);
::encode(flags, bl);
ENCODE_FINISH(bl);
}
void chunk_info_t::decode(bufferlist::iterator& bl)
{
DECODE_START(1, bl);
::decode(offset, bl);
::decode(length, bl);
::decode(oid, bl);
::decode(flags, bl);
DECODE_FINISH(bl);
}
void chunk_info_t::dump(Formatter *f) const
{
f->dump_unsigned("length", length);
f->open_object_section("oid");
oid.dump(f);
f->close_section();
f->dump_unsigned("flags", flags);
}
ostream& operator<<(ostream& out, const chunk_info_t& ci)
{
return out << "(len: " << ci.length << " oid: " << ci.oid
<< " offset: " << ci.offset
<< " flags: " << ci.get_flag_string(ci.flags) << ")";
}
// -- object_manifest_t --
void object_manifest_t::encode(bufferlist& bl) const
@ -4845,6 +4883,9 @@ void object_manifest_t::encode(bufferlist& bl) const
case TYPE_REDIRECT:
::encode(redirect_target, bl);
break;
case TYPE_CHUNKED:
::encode(chunk_map, bl);
break;
default:
ceph_abort();
}
@ -4860,6 +4901,9 @@ void object_manifest_t::decode(bufferlist::iterator& bl)
case TYPE_REDIRECT:
::decode(redirect_target, bl);
break;
case TYPE_CHUNKED:
::decode(chunk_map, bl);
break;
default:
ceph_abort();
}
@ -4869,9 +4913,20 @@ void object_manifest_t::decode(bufferlist::iterator& bl)
void object_manifest_t::dump(Formatter *f) const
{
f->dump_unsigned("type", type);
f->open_object_section("redirect_target");
redirect_target.dump(f);
f->close_section();
if (type == TYPE_REDIRECT) {
f->open_object_section("redirect_target");
redirect_target.dump(f);
f->close_section();
} else if (type == TYPE_CHUNKED) {
f->open_array_section("chunk_map");
for (auto& p : chunk_map) {
f->open_object_section("chunk");
f->dump_unsigned("offset", p.first);
p.second.dump(f);
f->close_section();
}
f->close_section();
}
}
void object_manifest_t::generate_test_instances(list<object_manifest_t*>& o)
@ -4882,7 +4937,14 @@ void object_manifest_t::generate_test_instances(list<object_manifest_t*>& o)
ostream& operator<<(ostream& out, const object_manifest_t& om)
{
return out << "type:" << om.type << " redirect_target:" << om.redirect_target;
out << "manifest(" << om.get_type_name();
if (om.is_redirect()) {
out << " " << om.redirect_target;
} else if (om.is_chunked()) {
out << " " << om.chunk_map;
}
out << ")";
return out;
}
// -- object_info_t --

View File

@ -4538,15 +4538,48 @@ static inline ostream& operator<<(ostream& out, const notify_info_t& n) {
<< " " << n.timeout << "s)";
}
struct chunk_info_t {
enum {
FLAG_DIRTY = 1,
FLAG_MISSING = 2,
};
uint32_t offset;
uint32_t length;
hobject_t oid;
uint32_t flags; // FLAG_*
chunk_info_t() : length(0), flags(0) { }
static string get_flag_string(uint64_t flags) {
string r;
if (flags & FLAG_DIRTY) {
r += "|dirty";
}
if (flags & FLAG_MISSING) {
r += "|missing";
}
if (r.length())
return r.substr(1);
return r;
}
void encode(bufferlist &bl) const;
void decode(bufferlist::iterator &bl);
void dump(Formatter *f) const;
friend ostream& operator<<(ostream& out, const chunk_info_t& ci);
};
WRITE_CLASS_ENCODER(chunk_info_t)
ostream& operator<<(ostream& out, const chunk_info_t& ci);
struct object_info_t;
struct object_manifest_t {
enum {
TYPE_NONE = 0,
TYPE_REDIRECT = 1, // start with this
TYPE_CHUNKED = 2, // do this later
TYPE_REDIRECT = 1,
TYPE_CHUNKED = 2,
};
uint8_t type; // redirect, chunked, ...
hobject_t redirect_target;
map <uint64_t, chunk_info_t> chunk_map;
object_manifest_t() : type(0) { }
object_manifest_t(uint8_t type, const hobject_t& redirect_target)
@ -4572,6 +4605,11 @@ struct object_manifest_t {
const char *get_type_name() const {
return get_type_name(type);
}
void clear() {
type = 0;
redirect_target = hobject_t();
chunk_map.clear();
}
static void generate_test_instances(list<object_manifest_t*>& o);
void encode(bufferlist &bl) const;
void decode(bufferlist::iterator &bl);