From: Haomai Wang Date: Tue, 16 Sep 2014 04:58:50 +0000 (+0800) Subject: KeyValueStore: Reduce redundancy set_header call X-Git-Tag: v0.88~139^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=bb49547d0fa3f65aabb3b20a96fb8dabd8dc81c0;p=ceph.git KeyValueStore: Reduce redundancy set_header call Signed-off-by: Haomai Wang --- diff --git a/src/os/KeyValueStore.cc b/src/os/KeyValueStore.cc index 34c56f54295b..af282d3fd1ec 100644 --- a/src/os/KeyValueStore.cc +++ b/src/os/KeyValueStore.cc @@ -93,10 +93,12 @@ static CompatSet get_kv_supported_compat_set() { int StripObjectMap::save_strip_header(StripObjectHeaderRef strip_header, KeyValueDB::Transaction t) { - strip_header->header->data.clear(); - ::encode(*strip_header, strip_header->header->data); + if (strip_header->updated) { + strip_header->header->data.clear(); + ::encode(*strip_header, strip_header->header->data); - set_header(strip_header->cid, strip_header->oid, *(strip_header->header), t); + set_header(strip_header->cid, strip_header->oid, *(strip_header->header), t); + } return 0; } @@ -113,6 +115,7 @@ int StripObjectMap::create_strip_header(const coll_t &cid, tmp->oid = oid; tmp->cid = cid; tmp->header = header; + tmp->updated = true; if (strip_header) *strip_header = tmp; @@ -123,7 +126,7 @@ int StripObjectMap::lookup_strip_header(const coll_t &cid, const ghobject_t &oid, StripObjectHeaderRef *strip_header) { - if (cid != coll_t()) { + { Mutex::Locker l(lock); pair p; if (caches.lookup(oid, &p)) { @@ -148,8 +151,10 @@ int StripObjectMap::lookup_strip_header(const coll_t &cid, ::decode(*tmp, bliter); } - if (tmp->strip_size == 0) + if (tmp->strip_size == 0) { tmp->strip_size = default_strip_size; + tmp->updated = true; + } tmp->oid = oid; tmp->cid = cid; @@ -219,7 +224,9 @@ void StripObjectMap::clone_wrap(StripObjectHeaderRef old_header, tmp->strip_size = old_header->strip_size; tmp->max_size = old_header->max_size; tmp->bits = old_header->bits; + tmp->updated = true; old_header->header = new_origin_header; + old_header->updated = true; if (target_header) *target_header = tmp; @@ -238,6 +245,7 @@ void StripObjectMap::rename_wrap(StripObjectHeaderRef old_header, const coll_t & tmp->header = old_header->header; tmp->oid = oid; tmp->cid = cid; + tmp->updated = true; if (new_header) *new_header = tmp; @@ -1731,6 +1739,7 @@ int KeyValueStore::_remove(coll_t cid, const ghobject_t& oid, header->max_size = 0; header->bits.clear(); + header->updated = true; r = t.clear_buffer(header); dout(10) << __func__ << " " << cid << "/" << oid << " = " << r << dendl; @@ -1809,6 +1818,7 @@ int KeyValueStore::_truncate(coll_t cid, const ghobject_t& oid, uint64_t size, header->bits.resize(size/header->strip_size+1); header->max_size = size; + header->updated = true; dout(10) << __func__ << " " << cid << "/" << oid << " size " << size << " = " << r << dendl; @@ -1912,6 +1922,7 @@ int KeyValueStore::_generic_write(StripObjectMap::StripObjectHeaderRef header, } assert(bl_offset == len); + header->updated = true; t.set_buffer_keys(header, OBJECT_STRIP_PREFIX, values); dout(10) << __func__ << " " << header->cid << "/" << header->oid << " " << offset << "~" << len << " = " << r << dendl; diff --git a/src/os/KeyValueStore.h b/src/os/KeyValueStore.h index da3aadf92f20..9ed47c70f41c 100644 --- a/src/os/KeyValueStore.h +++ b/src/os/KeyValueStore.h @@ -66,10 +66,11 @@ class StripObjectMap: public GenericObjectMap { // also block read operation which not should be permitted. coll_t cid; ghobject_t oid; + bool updated; bool deleted; map, bufferlist> buffers; // pair(prefix, key) - StripObjectHeader(): strip_size(default_strip_size), max_size(0), deleted(false) {} + StripObjectHeader(): strip_size(default_strip_size), max_size(0), updated(false), deleted(false) {} void encode(bufferlist &bl) const { ENCODE_START(1, 1, bl);