From: Piotr Dałek Date: Wed, 24 Feb 2016 12:18:39 +0000 (+0100) Subject: test/objectstore: add test for GetNumBytes X-Git-Tag: v10.1.0~213^2~5^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2104df820d12ed68a1efefddd3cbda7fa573c30c;p=ceph.git test/objectstore: add test for GetNumBytes 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 --- diff --git a/src/os/ObjectStore.h b/src/os/ObjectStore.h index f20280a8fafc..0ecf00641383 100644 --- a/src/os/ObjectStore.h +++ b/src/os/ObjectStore.h @@ -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(); } diff --git a/src/test/objectstore/test_transaction.cc b/src/test/objectstore/test_transaction.cc index 6e12b5da299f..ebaccaaa36df 100644 --- a/src/test/objectstore/test_transaction.cc +++ b/src/test/objectstore/test_transaction.cc @@ -14,6 +14,8 @@ #include "os/ObjectStore.h" #include +#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 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 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); +}