]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
unittest_ec_transaction: test nearby writes touching the same stripe
authorSage Weil <sage@redhat.com>
Thu, 15 Jun 2017 21:23:49 +0000 (17:23 -0400)
committerSage Weil <sage@redhat.com>
Thu, 15 Jun 2017 21:23:49 +0000 (17:23 -0400)
Reproduces http://tracker.ceph.com/issues/19882

Signed-off-by: Sage Weil <sage@redhat.com>
src/test/osd/CMakeLists.txt
src/test/osd/test_ec_transaction.cc [new file with mode: 0644]

index f291026ad1bdc2acfcbdd247c8a105ab5f77d95a..10b59cb513a46dd205987f2c1eb13b8d1b6652ec 100644 (file)
@@ -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 (file)
index 0000000..0818cf3
--- /dev/null
@@ -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 <gtest/gtest.h>
+#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());
+}