From d68ee83018d73c47861514eaef1e463c90227d13 Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Fri, 2 Dec 2016 14:24:24 +0800 Subject: [PATCH] os/bluestore: dedup omap_head, reuse nid instead This is faster and save us some memory as well as space. Signed-off-by: xie xingguo --- src/os/bluestore/BlueStore.cc | 102 ++++++++++++++-------------- src/os/bluestore/bluestore_types.cc | 2 +- src/os/bluestore/bluestore_types.h | 40 ++++++++++- 3 files changed, 90 insertions(+), 54 deletions(-) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index a4405fb2aa7..73026061705 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -4475,13 +4475,13 @@ int BlueStore::fsck(bool deep) } } // omap - if (o->onode.omap_head) { - if (used_omap_head.count(o->onode.omap_head)) { - derr << __func__ << " " << oid << " omap_head " << o->onode.omap_head + if (o->onode.has_omap()) { + if (used_omap_head.count(o->onode.nid)) { + derr << __func__ << " " << oid << " omap_head " << o->onode.nid << " already in use" << dendl; ++errors; } else { - used_omap_head.insert(o->onode.omap_head); + used_omap_head.insert(o->onode.nid); } } } @@ -5640,9 +5640,9 @@ BlueStore::OmapIteratorImpl::OmapIteratorImpl( : c(c), o(o), it(it) { RWLock::RLocker l(c->lock); - if (o->onode.omap_head) { - get_omap_key(o->onode.omap_head, string(), &head); - get_omap_tail(o->onode.omap_head, &tail); + if (o->onode.has_omap()) { + get_omap_key(o->onode.nid, string(), &head); + get_omap_tail(o->onode.nid, &tail); it->lower_bound(head); } } @@ -5650,7 +5650,7 @@ BlueStore::OmapIteratorImpl::OmapIteratorImpl( int BlueStore::OmapIteratorImpl::seek_to_first() { RWLock::RLocker l(c->lock); - if (o->onode.omap_head) { + if (o->onode.has_omap()) { it->lower_bound(head); } else { it = KeyValueDB::Iterator(); @@ -5661,9 +5661,9 @@ int BlueStore::OmapIteratorImpl::seek_to_first() int BlueStore::OmapIteratorImpl::upper_bound(const string& after) { RWLock::RLocker l(c->lock); - if (o->onode.omap_head) { + if (o->onode.has_omap()) { string key; - get_omap_key(o->onode.omap_head, after, &key); + get_omap_key(o->onode.nid, after, &key); it->upper_bound(key); } else { it = KeyValueDB::Iterator(); @@ -5674,9 +5674,9 @@ int BlueStore::OmapIteratorImpl::upper_bound(const string& after) int BlueStore::OmapIteratorImpl::lower_bound(const string& to) { RWLock::RLocker l(c->lock); - if (o->onode.omap_head) { + if (o->onode.has_omap()) { string key; - get_omap_key(o->onode.omap_head, to, &key); + get_omap_key(o->onode.nid, to, &key); it->lower_bound(key); } else { it = KeyValueDB::Iterator(); @@ -5687,13 +5687,13 @@ int BlueStore::OmapIteratorImpl::lower_bound(const string& to) bool BlueStore::OmapIteratorImpl::valid() { RWLock::RLocker l(c->lock); - return o->onode.omap_head && it->valid() && it->raw_key().second <= tail; + return o->onode.has_omap() && it->valid() && it->raw_key().second <= tail; } int BlueStore::OmapIteratorImpl::next(bool validate) { RWLock::RLocker l(c->lock); - if (o->onode.omap_head) { + if (o->onode.has_omap()) { it->next(); return 0; } else { @@ -5749,14 +5749,14 @@ int BlueStore::omap_get( r = -ENOENT; goto out; } - if (!o->onode.omap_head) + if (!o->onode.has_omap()) goto out; o->flush(); { KeyValueDB::Iterator it = db->get_iterator(PREFIX_OMAP); string head, tail; - get_omap_header(o->onode.omap_head, &head); - get_omap_tail(o->onode.omap_head, &tail); + get_omap_header(o->onode.nid, &head); + get_omap_tail(o->onode.nid, &tail); it->lower_bound(head); while (it->valid()) { if (it->key() == head) { @@ -5812,12 +5812,12 @@ int BlueStore::omap_get_header( r = -ENOENT; goto out; } - if (!o->onode.omap_head) + if (!o->onode.has_omap()) goto out; o->flush(); { string head; - get_omap_header(o->onode.omap_head, &head); + get_omap_header(o->onode.nid, &head); if (db->get(PREFIX_OMAP, head, header) >= 0) { dout(30) << __func__ << " got header" << dendl; } else { @@ -5859,14 +5859,14 @@ int BlueStore::omap_get_keys( r = -ENOENT; goto out; } - if (!o->onode.omap_head) + if (!o->onode.has_omap()) goto out; o->flush(); { KeyValueDB::Iterator it = db->get_iterator(PREFIX_OMAP); string head, tail; - get_omap_key(o->onode.omap_head, string(), &head); - get_omap_tail(o->onode.omap_head, &tail); + get_omap_key(o->onode.nid, string(), &head); + get_omap_tail(o->onode.nid, &tail); it->lower_bound(head); while (it->valid()) { if (it->key() >= tail) { @@ -5919,10 +5919,10 @@ int BlueStore::omap_get_values( r = -ENOENT; goto out; } - if (!o->onode.omap_head) + if (!o->onode.has_omap()) goto out; o->flush(); - _key_encode_u64(o->onode.omap_head, &final_key); + _key_encode_u64(o->onode.nid, &final_key); final_key.push_back('.'); for (set::const_iterator p = keys.begin(); p != keys.end(); ++p) { final_key.resize(9); // keep prefix @@ -5972,10 +5972,10 @@ int BlueStore::omap_check_keys( r = -ENOENT; goto out; } - if (!o->onode.omap_head) + if (!o->onode.has_omap()) goto out; o->flush(); - _key_encode_u64(o->onode.omap_head, &final_key); + _key_encode_u64(o->onode.nid, &final_key); final_key.push_back('.'); for (set::const_iterator p = keys.begin(); p != keys.end(); ++p) { final_key.resize(9); // keep prefix @@ -6026,7 +6026,7 @@ ObjectMap::ObjectMapIterator BlueStore::get_omap_iterator( return ObjectMap::ObjectMapIterator(); } o->flush(); - dout(10) << __func__ << " header = " << o->onode.omap_head <cid << " " << o->oid << dendl; int r = 0; - if (o->onode.omap_head != 0) { - _do_omap_clear(txc, o->onode.omap_head); - o->onode.omap_head = 0; + if (o->onode.has_omap()) { + _do_omap_clear(txc, o->onode.nid); + o->onode.clear_omap_flag(); txc->write_onode(o); } dout(10) << __func__ << " " << c->cid << " " << o->oid << " = " << r << dendl; @@ -8403,12 +8403,12 @@ int BlueStore::_omap_setkeys(TransContext *txc, int r; bufferlist::iterator p = bl.begin(); __u32 num; - if (!o->onode.omap_head) { - o->onode.omap_head = o->onode.nid; + if (!o->onode.has_omap()) { + o->onode.set_omap_flag(); txc->write_onode(o); } string final_key; - _key_encode_u64(o->onode.omap_head, &final_key); + _key_encode_u64(o->onode.nid, &final_key); final_key.push_back('.'); ::decode(num, p); while (num--) { @@ -8435,11 +8435,11 @@ int BlueStore::_omap_setheader(TransContext *txc, dout(15) << __func__ << " " << c->cid << " " << o->oid << dendl; int r; string key; - if (!o->onode.omap_head) { - o->onode.omap_head = o->onode.nid; + if (!o->onode.has_omap()) { + o->onode.set_omap_flag(); txc->write_onode(o); } - get_omap_header(o->onode.omap_head, &key); + get_omap_header(o->onode.nid, &key); txc->t->set(PREFIX_OMAP, key, bl); r = 0; dout(10) << __func__ << " " << c->cid << " " << o->oid << " = " << r << dendl; @@ -8457,10 +8457,10 @@ int BlueStore::_omap_rmkeys(TransContext *txc, __u32 num; string final_key; - if (!o->onode.omap_head) { + if (!o->onode.has_omap()) { goto out; } - _key_encode_u64(o->onode.omap_head, &final_key); + _key_encode_u64(o->onode.nid, &final_key); final_key.push_back('.'); ::decode(num, p); while (num--) { @@ -8487,12 +8487,12 @@ int BlueStore::_omap_rmkey_range(TransContext *txc, KeyValueDB::Iterator it; string key_first, key_last; int r = 0; - if (!o->onode.omap_head) { + if (!o->onode.has_omap()) { goto out; } it = db->get_iterator(PREFIX_OMAP); - get_omap_key(o->onode.omap_head, first, &key_first); - get_omap_key(o->onode.omap_head, last, &key_last); + get_omap_key(o->onode.nid, first, &key_first); + get_omap_key(o->onode.nid, last, &key_last); it->lower_bound(key_first); while (it->valid()) { if (it->key() >= key_last) { @@ -8574,19 +8574,19 @@ int BlueStore::_clone(TransContext *txc, newo->onode.attrs = oldo->onode.attrs; // clone omap - if (newo->onode.omap_head) { + if (newo->onode.has_omap()) { dout(20) << __func__ << " clearing old omap data" << dendl; - _do_omap_clear(txc, newo->onode.omap_head); + _do_omap_clear(txc, newo->onode.nid); } - if (oldo->onode.omap_head) { + if (oldo->onode.has_omap()) { dout(20) << __func__ << " copying omap data" << dendl; - if (!newo->onode.omap_head) { - newo->onode.omap_head = newo->onode.nid; + if (!newo->onode.has_omap()) { + newo->onode.set_omap_flag(); } KeyValueDB::Iterator it = db->get_iterator(PREFIX_OMAP); string head, tail; - get_omap_header(oldo->onode.omap_head, &head); - get_omap_tail(oldo->onode.omap_head, &tail); + get_omap_header(oldo->onode.nid, &head); + get_omap_tail(oldo->onode.nid, &tail); it->lower_bound(head); while (it->valid()) { if (it->key() >= tail) { @@ -8596,7 +8596,7 @@ int BlueStore::_clone(TransContext *txc, dout(30) << __func__ << " got header/data " << pretty_binary_string(it->key()) << dendl; string key; - rewrite_omap_key(newo->onode.omap_head, it->key(), &key); + rewrite_omap_key(newo->onode.nid, it->key(), &key); txc->t->set(PREFIX_OMAP, key, it->value()); } it->next(); diff --git a/src/os/bluestore/bluestore_types.cc b/src/os/bluestore/bluestore_types.cc index 028d7f60393..3e3f5feaa6f 100644 --- a/src/os/bluestore/bluestore_types.cc +++ b/src/os/bluestore/bluestore_types.cc @@ -572,7 +572,7 @@ void bluestore_onode_t::dump(Formatter *f) const f->close_section(); } f->close_section(); - f->dump_unsigned("omap_head", omap_head); + f->dump_string("flags", get_flags_string()); f->open_array_section("extent_map_shards"); for (auto si : extent_map_shards) { f->dump_object("shard", si); diff --git a/src/os/bluestore/bluestore_types.h b/src/os/bluestore/bluestore_types.h index 4fca244a0a3..559fe47a090 100644 --- a/src/os/bluestore/bluestore_types.h +++ b/src/os/bluestore/bluestore_types.h @@ -667,7 +667,11 @@ struct bluestore_onode_t { uint64_t nid = 0; ///< numeric id (locally unique) uint64_t size = 0; ///< object size map attrs; ///< attrs - uint64_t omap_head = 0; ///< id for omap root node + uint8_t flags = 0; + + enum { + FLAG_OMAP = 1, + }; struct shard_info { uint32_t offset = 0; ///< logical offset for start of shard @@ -686,6 +690,38 @@ struct bluestore_onode_t { uint32_t expected_write_size = 0; uint32_t alloc_hint_flags = 0; + string get_flags_string() const { + string s; + if (flags & FLAG_OMAP) { + s = "omap"; + } + return s; + } + + bool has_flag(unsigned f) const { + return flags & f; + } + + void set_flag(unsigned f) { + flags |= f; + } + + void clear_flag(unsigned f) { + flags &= ~f; + } + + bool has_omap() const { + return has_flag(FLAG_OMAP); + } + + void set_omap_flag() { + set_flag(FLAG_OMAP); + } + + void clear_omap_flag() { + clear_flag(FLAG_OMAP); + } + /// get preferred csum chunk size size_t get_preferred_csum_order() const; @@ -694,7 +730,7 @@ struct bluestore_onode_t { denc(v.nid, p); denc(v.size, p); denc(v.attrs, p); - denc(v.omap_head, p); + denc(v.flags, p); denc(v.extent_map_shards, p); denc(v.expected_object_size, p); denc(v.expected_write_size, p); -- 2.39.5