]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
KeyValueStore: Add KEY_ENDING sign to the end of key
authorHaomai Wang <haomaiwang@gmail.com>
Wed, 19 Nov 2014 06:34:52 +0000 (14:34 +0800)
committerHaomai Wang <haomaiwang@gmail.com>
Wed, 19 Nov 2014 07:07:16 +0000 (15:07 +0800)
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 <haomaiwang@gmail.com>
src/os/GenericObjectMap.cc
src/os/GenericObjectMap.h

index 9b1b28d9a28b3868db84ae9bd0e0bc833748e371..0255df76089b1a0ea6525de0875570cda43a41af 100644 (file)
@@ -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;
 }
 
index b254795207398aa2155d0dc85376293369b9fcce..864a06b78230194e885f012517dd7dd63f61aa69 100644 (file)
@@ -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