From: Sage Weil Date: Thu, 15 Jun 2017 21:23:49 +0000 (-0400) Subject: unittest_ec_transaction: test nearby writes touching the same stripe X-Git-Tag: v12.1.0~69^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=110c4e82c367707a66ad0776d51fcf8b737da7af;p=ceph.git unittest_ec_transaction: test nearby writes touching the same stripe Reproduces http://tracker.ceph.com/issues/19882 Signed-off-by: Sage Weil --- diff --git a/src/test/osd/CMakeLists.txt b/src/test/osd/CMakeLists.txt index f291026ad1b..10b59cb513a 100644 --- a/src/test/osd/CMakeLists.txt +++ b/src/test/osd/CMakeLists.txt @@ -99,3 +99,10 @@ add_executable(unittest_pg_transaction ) add_ceph_unittest(unittest_pg_transaction ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest_pg_transaction) target_link_libraries(unittest_pg_transaction osd global ${BLKID_LIBRARIES}) + +# unittest ECTransaction +add_executable(unittest_ec_transaction + test_ec_transaction.cc +) +add_ceph_unittest(unittest_ec_transaction ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest_ec_transaction) +target_link_libraries(unittest_ec_transaction osd global ${BLKID_LIBRARIES}) diff --git a/src/test/osd/test_ec_transaction.cc b/src/test/osd/test_ec_transaction.cc new file mode 100644 index 00000000000..0818cf36b94 --- /dev/null +++ b/src/test/osd/test_ec_transaction.cc @@ -0,0 +1,83 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2016 Red Hat + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#include +#include "osd/PGTransaction.h" +#include "osd/ECTransaction.h" + +#include "test/unit.cc" + +struct mydpp : public DoutPrefixProvider { + string gen_prefix() const override { return "foo"; } + CephContext *get_cct() const override { return g_ceph_context; } + unsigned get_subsys() const override { return ceph_subsys_osd; } +} dpp; + +#define dout_context g_ceph_context + +TEST(ectransaction, two_writes_separated) +{ + hobject_t h; + PGTransactionUPtr t(new PGTransaction); + bufferlist a, b; + t->create(h); + a.append_zero(565760); + t->write(h, 0, a.length(), a, 0); + b.append_zero(2437120); + t->write(h, 669856, b.length(), b, 0); + + ECUtil::stripe_info_t sinfo(2, 8192); + auto plan = ECTransaction::get_write_plan( + sinfo, + std::move(t), + [&](const hobject_t &i) { + ECUtil::HashInfoRef ref(new ECUtil::HashInfo(1)); + return ref; + }, + &dpp); + generic_derr << "to_read " << plan.to_read << dendl; + generic_derr << "will_write " << plan.will_write << dendl; + + ASSERT_EQ(0u, plan.to_read.size()); + ASSERT_EQ(1u, plan.will_write.size()); +} + +TEST(ectransaction, two_writes_nearby) +{ + hobject_t h; + PGTransactionUPtr t(new PGTransaction); + bufferlist a, b; + t->create(h); + + // two nearby writes, both partly touching the same 8192-byte stripe + ECUtil::stripe_info_t sinfo(2, 8192); + a.append_zero(565760); + t->write(h, 0, a.length(), a, 0); + b.append_zero(2437120); + t->write(h, 569856, b.length(), b, 0); + + auto plan = ECTransaction::get_write_plan( + sinfo, + std::move(t), + [&](const hobject_t &i) { + ECUtil::HashInfoRef ref(new ECUtil::HashInfo(1)); + return ref; + }, + &dpp); + generic_derr << "to_read " << plan.to_read << dendl; + generic_derr << "will_write " << plan.will_write << dendl; + + ASSERT_EQ(0u, plan.to_read.size()); + ASSERT_EQ(1u, plan.will_write.size()); +}