]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: speed up get_key_name 17071/head
authorJ. Eric Ivancich <ivancich@redhat.com>
Thu, 17 Aug 2017 18:33:51 +0000 (14:33 -0400)
committerJ. Eric Ivancich <ivancich@redhat.com>
Tue, 29 Aug 2017 16:46:09 +0000 (12:46 -0400)
Reduce string manipulation and creation of an extra string by
streamlining code for get_key_name in both eversion_t and
pg_log_dup_t.

Signed-off-by: J. Eric Ivancich <ivancich@redhat.com>
src/osd/osd_types.cc
src/osd/osd_types.h
src/test/osd/TestPGLog.cc

index 393cd7097d23fdb9483949fd2571e506fc31f629..0fa3919441b321d6e636082369d0377f4853310e 100644 (file)
@@ -917,16 +917,12 @@ int pg_string_state(const std::string& state)
 // -- eversion_t --
 string eversion_t::get_key_name() const
 {
-  char key[32];
-  // Below is equivalent of sprintf("%010u.%020llu");
-  key[31] = 0;
-  ritoa<uint64_t, 10, 20>(version, key + 31);
-  key[10] = '.';
-  ritoa<uint32_t, 10, 10>(epoch, key + 10);
-  return string(key);
+  std::string key(32, ' ');
+  get_key_name(&key[0]);
+  key.resize(31); // remove the null terminator
+  return key;
 }
 
-
 // -- pool_snap_info_t --
 void pool_snap_info_t::dump(Formatter *f) const
 {
@@ -4125,9 +4121,14 @@ ostream& operator<<(ostream& out, const pg_log_entry_t& e)
 
 // -- pg_log_dup_t --
 
-string pg_log_dup_t::get_key_name() const
+std::string pg_log_dup_t::get_key_name() const
 {
-  return "dup_" + version.get_key_name();
+  static const char prefix[] = "dup_";
+  std::string key(36, ' ');
+  memcpy(&key[0], prefix, 4);
+  version.get_key_name(&key[4]);
+  key.resize(35); // remove the null terminator
+  return key;
 }
 
 void pg_log_dup_t::encode(bufferlist &bl) const
index 43d9a98e73753ea8bb14c45ba32f01ea19a24d0b..5c66e478b7da64dd97981931122db0a5e56eb09d 100644 (file)
@@ -811,6 +811,15 @@ public:
 
   string get_key_name() const;
 
+  // key must point to the beginning of a block of 32 chars
+  inline void get_key_name(char* key) const {
+    // Below is equivalent of sprintf("%010u.%020llu");
+    key[31] = 0;
+    ritoa<uint64_t, 10, 20>(version, key + 31);
+    key[10] = '.';
+    ritoa<uint32_t, 10, 10>(epoch, key + 10);
+  }
+
   void encode(bufferlist &bl) const {
 #if defined(CEPH_LITTLE_ENDIAN)
     bl.append((char *)this, sizeof(version_t) + sizeof(epoch_t));
index 4a87d535aebc18d2fa91b48c4628fe413ce54ad0..48c6d8d5473dcec6704e8ea14f0fb89351d8ac5f 100644 (file)
@@ -2990,6 +2990,20 @@ TEST_F(PGLogTest, _merge_object_divergent_entries) {
   }
 }
 
+TEST(eversion_t, get_key_name) {
+  eversion_t a(1234, 5678);
+  std::string a_key_name = a.get_key_name();
+  EXPECT_EQ("0000001234.00000000000000005678", a_key_name);
+}
+
+TEST(pg_log_dup_t, get_key_name) {
+  pg_log_dup_t a(eversion_t(1234, 5678),
+                13,
+                osd_reqid_t(entity_name_t::CLIENT(777), 8, 999),
+                15);
+  std::string a_key_name = a.get_key_name();
+  EXPECT_EQ("dup_0000001234.00000000000000005678", a_key_name);
+}
 
 // Local Variables:
 // compile-command: "cd ../.. ; make unittest_pglog ; ./unittest_pglog --log-to-stderr=true  --debug-osd=20 # --gtest_filter=*.* "