]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: dedup omap_head, reuse nid instead
authorxie xingguo <xie.xingguo@zte.com.cn>
Fri, 2 Dec 2016 06:24:24 +0000 (14:24 +0800)
committerxie xingguo <xie.xingguo@zte.com.cn>
Mon, 5 Dec 2016 04:49:39 +0000 (12:49 +0800)
This is faster and save us some memory as well as space.

Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
src/os/bluestore/BlueStore.cc
src/os/bluestore/bluestore_types.cc
src/os/bluestore/bluestore_types.h

index a4405fb2aa7ec6476864d362a0f47403cf3714e9..73026061705445b6fbe4329de830d9fc7c55899e 100644 (file)
@@ -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<string>::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<string>::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 <<dendl;
+  dout(10) << __func__ << " has_omap = " << (int)o->onode.has_omap() <<dendl;
   KeyValueDB::Iterator it = db->get_iterator(PREFIX_OMAP);
   return ObjectMap::ObjectMapIterator(new OmapIteratorImpl(c, o, it));
 }
@@ -8254,8 +8254,8 @@ int BlueStore::_do_remove(
   int r = _do_truncate(txc, c, o, 0);
   if (r < 0)
     return r;
-  if (o->onode.omap_head) {
-    _do_omap_clear(txc, o->onode.omap_head);
+  if (o->onode.has_omap()) {
+    _do_omap_clear(txc, o->onode.nid);
   }
   o->exists = false;
   o->onode = bluestore_onode_t();
@@ -8385,9 +8385,9 @@ int BlueStore::_omap_clear(TransContext *txc,
 {
   dout(15) << __func__ << " " << c->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();
index 028d7f603939255faef68b200e3b4316a40c9aa2..3e3f5feaa6f91a01af5f69633fe303bbb3542758 100644 (file)
@@ -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);
index 4fca244a0a3d74c3e6875adb6cae946cd0b5f7c2..559fe47a090d051cf36df7780ef16c25fbcc06ad 100644 (file)
@@ -667,7 +667,11 @@ struct bluestore_onode_t {
   uint64_t nid = 0;                    ///< numeric id (locally unique)
   uint64_t size = 0;                   ///< object size
   map<string, bufferptr> 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);