From: Haomai Wang Date: Wed, 19 Nov 2014 06:34:52 +0000 (+0800) Subject: KeyValueStore: Add KEY_ENDING sign to the end of key X-Git-Tag: v0.90~54^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b4fa384fc023558b0c4af781cbe34a35315f4967;p=ceph.git KeyValueStore: Add KEY_ENDING sign to the end of key Keys stored in alphabetical order and need to follow ghobject_t comparison rule. "generation" and "shard_id" are optional fields for object key, but a default ghobject with UINT64_MAX generation(by default) will larger than the same ghobject with other generation. GenericObjectMap rejects to store generation if generation is UINT64_MAX in order to reduce too much words in key. So we need to add a MAX sign to the end of key to make ordering is same with ghobject's comparison rule. For example: _GHOBJTOSEQ_:1%e1ds0_head!D168A7E8!!1!!benchmark_last_metadata!head _GHOBJTOSEQ_:1%e1ds0_head!D168A7E8!!1!!benchmark_last_metadata!head!78!0 The first key should larger than the second in ghobject_t ordering because of generation. But the first key less than the second in GenericObjectMap. _GHOBJTOSEQ_:1%e1ds0_head!D168A7E8!!1!!benchmark_last_metadata!head _GHOBJTOSEQ_:1%e1ds0_head!D168A7E8!!1!!benchmark_last_metadata!head!78!0 After we add KEY_ENDING, '!' is (21) in hexadecimal: _GHOBJTOSEQ_:1%e1ds0_head!D168A7E8!!1!!benchmark_last_metadata!head(21)78!0(FF) _GHOBJTOSEQ_:1%e1ds0_head!D168A7E8!!1!!benchmark_last_metadata!head(FF) Fix bug #10119 Signed-off-by: Haomai Wang --- diff --git a/src/os/GenericObjectMap.cc b/src/os/GenericObjectMap.cc index 9b1b28d9a28b..0255df76089b 100644 --- a/src/os/GenericObjectMap.cc +++ b/src/os/GenericObjectMap.cc @@ -31,6 +31,7 @@ #include "include/assert.h" #define dout_subsys ceph_subsys_keyvaluestore + const string GenericObjectMap::GLOBAL_STATE_KEY = "HEADER"; const string GenericObjectMap::USER_PREFIX = "_SEQ_"; @@ -43,6 +44,7 @@ const string GenericObjectMap::PARENT_KEY = "_PARENT_HEADER_"; // so use "!" to separated const string GenericObjectMap::GHOBJECT_KEY_SEP_S = "!"; const char GenericObjectMap::GHOBJECT_KEY_SEP_C = '!'; +const char GenericObjectMap::GHOBJECT_KEY_ENDING = 0xFF; // ============== GenericObjectMap Key Function ================= @@ -147,7 +149,7 @@ string GenericObjectMap::header_key(const coll_t &cid, const ghobject_t &oid) t = buf; end = t + sizeof(buf); - t += snprintf(t, end - t, "%llx", (long long unsigned)oid.generation); + t += snprintf(t, end - t, "%016llx", (long long unsigned)oid.generation); full_name += string(buf); full_name.append(GHOBJECT_KEY_SEP_S); @@ -158,6 +160,8 @@ string GenericObjectMap::header_key(const coll_t &cid, const ghobject_t &oid) full_name += string(buf); } + full_name.append(1, GHOBJECT_KEY_ENDING); + return full_name; } diff --git a/src/os/GenericObjectMap.h b/src/os/GenericObjectMap.h index b25479520739..864a06b78230 100644 --- a/src/os/GenericObjectMap.h +++ b/src/os/GenericObjectMap.h @@ -274,6 +274,7 @@ class GenericObjectMap { static const string GHOBJECT_KEY_SEP_S; static const char GHOBJECT_KEY_SEP_C; + static const char GHOBJECT_KEY_ENDING; private: /// Implicit lock on Header->seq