From: xie xingguo Date: Fri, 23 Dec 2016 09:09:05 +0000 (+0800) Subject: os/bluestore: preallocate object[extent_shard] key to avoid reallocate X-Git-Tag: v12.0.0~383^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F12644%2Fhead;p=ceph.git os/bluestore: preallocate object[extent_shard] key to avoid reallocate which is less efficient. Signed-off-by: xie xingguo --- diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index a4acb10b0f82..cdd3362a1eeb 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -281,6 +281,14 @@ static void get_object_key(const ghobject_t& oid, string *key) { key->clear(); + size_t max_len = 1 + 8 + 4 + + (oid.hobj.nspace.length() * 3 + 1) + + (oid.hobj.get_key().length() * 3 + 1) + + 1 + // for '<', '=', or '>' + (oid.hobj.oid.name.length() * 3 + 1) + + 8 + 8 + 1; + key->reserve(max_len); + _key_encode_shard(oid.shard_id, key); _key_encode_u64(oid.hobj.pool + 0x8000000000000000ull, key); _key_encode_u32(oid.hobj.get_bitwise_key_u32(), key); @@ -392,6 +400,7 @@ static void get_extent_shard_key(const string& onode_key, uint32_t offset, string *key) { key->clear(); + key->reserve(onode_key.length() + 4 + 1); key->append(onode_key); _key_encode_u32(offset, key); key->push_back(EXTENT_SHARD_KEY_SUFFIX);