]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test/objectstore: add test for GetNumBytes 7775/head
authorPiotr Dałek <piotr.dalek@ts.fujitsu.com>
Wed, 24 Feb 2016 12:18:39 +0000 (13:18 +0100)
committerPiotr Dałek <piotr.dalek@ts.fujitsu.com>
Wed, 24 Feb 2016 15:30:08 +0000 (16:30 +0100)
Since new, fast implementation relies on results of encoded_size()
methods which may be invalidated once someone modifies the coll_t
and/or hobject_t classes, this test should be convincing enough for
anyone trying to modify them to update also relevant encoded_size
methods.

Signed-off-by: Piotr Dałek <piotr.dalek@ts.fujitsu.com>
src/os/ObjectStore.h
src/test/objectstore/test_transaction.cc

index f20280a8fafc4184e8ff8efb641ad262352e8263..0ecf00641383dcaaf8c906d7008d5f0fcddf5301 100644 (file)
@@ -832,6 +832,24 @@ public:
       }
     }
 
+    /// Retain old version for regression testing purposes
+    uint64_t get_encoded_bytes_test() {
+      if (use_tbl)
+        return 1 + 8 + 8 + 4 + 4 + 4 + 4 + 4 + tbl.length();
+      else {
+        //layout: data_bl + op_bl + coll_index + object_index + data
+
+        bufferlist bl;
+        ::encode(coll_index, bl);
+        ::encode(object_index, bl);
+
+        return data_bl.length() +
+          op_bl.length() +
+          bl.length() +
+          sizeof(data);
+      }
+    }
+
     uint64_t get_num_bytes() {
       return get_encoded_bytes();
     }
index 6e12b5da299f15f470f45e81aecd032b69162ff9..ebaccaaa36df9cf54932f27016bf737d0485e5c4 100644 (file)
@@ -14,6 +14,8 @@
 
 #include "os/ObjectStore.h"
 #include <gtest/gtest.h>
+#include "common/Clock.h"
+#include "include/utime.h"
 
 TEST(Transaction, MoveConstruct)
 {
@@ -73,3 +75,115 @@ TEST(Transaction, Swap)
   ASSERT_TRUE(a.empty());
   ASSERT_FALSE(b.empty());
 }
+
+ObjectStore::Transaction generate_transaction()
+{
+  auto a = ObjectStore::Transaction{};
+  a.set_use_tbl(false);
+  a.nop();
+
+  coll_t cid;
+  object_t obj("test_name");
+  snapid_t snap(0);
+  hobject_t hoid(obj, "key", snap, 0, 0, "nspace");
+  ghobject_t oid(hoid);
+
+  coll_t acid;
+  object_t aobj("another_test_name");
+  snapid_t asnap(0);
+  hobject_t ahoid(obj, "another_key", snap, 0, 0, "another_nspace");
+  ghobject_t aoid(hoid);
+  std::set<string> keys;
+  keys.insert("any_1");
+  keys.insert("any_2");
+  keys.insert("any_3");
+
+  bufferlist bl;
+  bl.append_zero(4096);
+
+  a.write(cid, oid, 1, 4096, bl, 0);
+
+  a.omap_setkeys(acid, aoid, bl);
+
+  a.omap_rmkeys(cid, aoid, keys);
+
+  a.touch(acid, oid);
+
+  return a;
+}
+
+TEST(Transaction, GetNumBytes)
+{
+  auto a = ObjectStore::Transaction{};
+  a.set_use_tbl(false);
+  a.nop();
+  ASSERT_TRUE(a.get_encoded_bytes() == a.get_encoded_bytes_test());
+
+  coll_t cid;
+  object_t obj("test_name");
+  snapid_t snap(0);
+  hobject_t hoid(obj, "key", snap, 0, 0, "nspace");
+  ghobject_t oid(hoid);
+
+  coll_t acid;
+  object_t aobj("another_test_name");
+  snapid_t asnap(0);
+  hobject_t ahoid(obj, "another_key", snap, 0, 0, "another_nspace");
+  ghobject_t aoid(hoid);
+  std::set<string> keys;
+  keys.insert("any_1");
+  keys.insert("any_2");
+  keys.insert("any_3");
+
+  bufferlist bl;
+  bl.append_zero(4096);
+
+  a.write(cid, oid, 1, 4096, bl, 0);
+  ASSERT_TRUE(a.get_encoded_bytes() == a.get_encoded_bytes_test());
+
+  a.omap_setkeys(acid, aoid, bl);
+  ASSERT_TRUE(a.get_encoded_bytes() == a.get_encoded_bytes_test());
+
+  a.omap_rmkeys(cid, aoid, keys);
+  ASSERT_TRUE(a.get_encoded_bytes() == a.get_encoded_bytes_test());
+
+  a.touch(acid, oid);
+  ASSERT_TRUE(a.get_encoded_bytes() == a.get_encoded_bytes_test());
+}
+
+void bench_num_bytes(bool legacy)
+{
+  const int max = 2500000;
+  auto a = generate_transaction();
+
+  if (legacy) {
+    cout << "get_encoded_bytes_test: ";
+  } else {
+    cout << "get_encoded_bytes: ";
+  }
+
+  utime_t start = ceph_clock_now(NULL);
+  if (legacy) {
+    for (int i = 0; i < max; ++i) {
+      a.get_encoded_bytes_test();
+    }
+  } else {
+    for (int i = 0; i < max; ++i) {
+      a.get_encoded_bytes();
+    }
+  }
+
+  utime_t end = ceph_clock_now(NULL);
+  cout << max << " encodes in " << (end - start) << std::endl;
+
+}
+
+TEST(Transaction, GetNumBytesBenchLegacy)
+{
+   bench_num_bytes(true);
+}
+
+TEST(Transaction, GetNumBytesBenchCurrent)
+{
+   bench_num_bytes(false);
+}