From 90ba4ee6b475805ab438337c69cc8036a54d3c76 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 14 Dec 2016 15:09:36 -0500 Subject: [PATCH] os/bluestore: version shard and spanning blob buffers, not each blob Instead of versioning every blob encoding, and adding a full byte per blob, instead version the entire shard or spanning blob chunk, since they are always encoded together. We overload the 'features' argument here to pass through a struct_v. This is slightly abusing an argument that is normally used for feature bits, but only slightly. Signed-off-by: Sage Weil --- src/os/bluestore/BlueStore.cc | 26 ++++++++++++++++++++------ src/os/bluestore/BlueStore.h | 14 ++++++++------ src/os/bluestore/bluestore_types.h | 15 ++++++--------- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index c813859d6b8..2e8e66a1785 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -1790,8 +1790,11 @@ bool BlueStore::ExtentMap::encode_some(uint32_t offset, uint32_t length, auto start = extent_map.lower_bound(dummy); uint32_t end = offset + length; + __u8 struct_v = 1; + unsigned n = 0; size_t bound = 0; + denc(struct_v, bound); denc_varint(0, bound); for (auto p = start; p != extent_map.end() && p->logical_offset < end; @@ -1807,11 +1810,12 @@ bool BlueStore::ExtentMap::encode_some(uint32_t offset, uint32_t length, denc_varint(0, bound); // logical_offset denc_varint(0, bound); // len denc_varint(0, bound); // blob_offset - p->blob->bound_encode(bound, false); + p->blob->bound_encode(bound, struct_v, false); } { auto app = bl.get_contiguous_appender(bound); + denc(struct_v, app); denc_varint(n, app); if (pn) { *pn = n; @@ -1858,7 +1862,7 @@ bool BlueStore::ExtentMap::encode_some(uint32_t offset, uint32_t length, } pos = p->logical_end(); if (include_blob) { - p->blob->encode(app, false); + p->blob->encode(app, struct_v, false); } } } @@ -1880,6 +1884,9 @@ void BlueStore::ExtentMap::decode_some(bufferlist& bl) assert(bl.get_num_buffers() <= 1); auto p = bl.front().begin_deep(); + __u8 struct_v; + denc(struct_v, p); + assert(struct_v == 1); uint32_t num; denc_varint(num, p); vector blobs(num); @@ -1915,7 +1922,7 @@ void BlueStore::ExtentMap::decode_some(bufferlist& bl) assert(le->blob); } else { Blob *b = new Blob(); - b->decode(p, false); + b->decode(p, struct_v, false); blobs[n] = b; onode->c->open_shared_blob(b); le->assign_blob(b); @@ -1933,22 +1940,26 @@ void BlueStore::ExtentMap::decode_some(bufferlist& bl) void BlueStore::ExtentMap::bound_encode_spanning_blobs(size_t& p) { + __u8 struct_v = 1; + denc(struct_v, p); denc_varint((uint32_t)0, p); size_t key_size = 0; denc_varint((uint32_t)0, key_size); p += spanning_blob_map.size() * key_size; for (const auto& i : spanning_blob_map) { - i.second->bound_encode(p, true); + i.second->bound_encode(p, struct_v, true); } } void BlueStore::ExtentMap::encode_spanning_blobs( bufferlist::contiguous_appender& p) { + __u8 struct_v = 1; + denc(struct_v, p); denc_varint(spanning_blob_map.size(), p); for (auto& i : spanning_blob_map) { denc_varint(i.second->id, p); - i.second->encode(p, true); + i.second->encode(p, struct_v, true); } } @@ -1956,13 +1967,16 @@ void BlueStore::ExtentMap::decode_spanning_blobs( Collection *c, bufferptr::iterator& p) { + __u8 struct_v; + denc(struct_v, p); + assert(struct_v == 1); unsigned n; denc_varint(n, p); while (n--) { BlobRef b(new Blob()); denc_varint(b->id, p); spanning_blob_map[b->id] = b; - b->decode(p, true); + b->decode(p, struct_v, true); c->open_shared_blob(b); } } diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 07fe50bc0b8..0633bf7983d 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -534,20 +534,22 @@ public: } } #else - void bound_encode(size_t& p, bool include_ref_map) const { - denc(blob, p); + void bound_encode(size_t& p, uint64_t struct_v, bool include_ref_map) const { + denc(blob, p, struct_v); if (include_ref_map) { ref_map.bound_encode(p); } } - void encode(bufferlist::contiguous_appender& p, bool include_ref_map) const { - denc(blob, p); + void encode(bufferlist::contiguous_appender& p, uint64_t struct_v, + bool include_ref_map) const { + denc(blob, p, struct_v); if (include_ref_map) { ref_map.encode(p); } } - void decode(bufferptr::iterator& p, bool include_ref_map) { - denc(blob, p); + void decode(bufferptr::iterator& p, uint64_t struct_v, + bool include_ref_map) { + denc(blob, p, struct_v); if (include_ref_map) { ref_map.decode(p); } diff --git a/src/os/bluestore/bluestore_types.h b/src/os/bluestore/bluestore_types.h index 5f7fe18776a..571448da0eb 100644 --- a/src/os/bluestore/bluestore_types.h +++ b/src/os/bluestore/bluestore_types.h @@ -297,8 +297,8 @@ struct bluestore_blob_t { bluestore_blob_t(uint32_t f = 0) : flags(f) {} DENC_HELPERS; - void bound_encode(size_t& p) const { - p += 1; + void bound_encode(size_t& p, uint64_t struct_v) const { + assert(struct_v == 1); denc(extents, p); denc_varint(flags, p); denc_varint(sbid, p); @@ -310,9 +310,8 @@ struct bluestore_blob_t { p += sizeof(unsigned long long); } - void encode(bufferlist::contiguous_appender& p) const { - __u8 struct_v = 1; - denc(struct_v, p); + void encode(bufferlist::contiguous_appender& p, uint64_t struct_v) const { + assert(struct_v == 1); denc(extents, p); denc_varint(flags, p); if (is_shared()) { @@ -332,9 +331,7 @@ struct bluestore_blob_t { } } - void decode(bufferptr::iterator& p) { - __u8 struct_v; - denc(struct_v, p); + void decode(bufferptr::iterator& p, uint64_t struct_v) { assert(struct_v == 1); denc(extents, p); denc_varint(flags, p); @@ -639,7 +636,7 @@ struct bluestore_blob_t { } } }; -WRITE_CLASS_DENC(bluestore_blob_t) +WRITE_CLASS_DENC_FEATURED(bluestore_blob_t) ostream& operator<<(ostream& out, const bluestore_blob_t& o); -- 2.39.5