]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
Add more thorough simple test
authortridao <daominhtri0503@gmail.com>
Mon, 19 Jun 2023 04:00:11 +0000 (01:00 -0300)
committertridao <daominhtri0503@gmail.com>
Tue, 20 Jun 2023 17:30:14 +0000 (14:30 -0300)
Fix failing tests, including logical bug with punch_hole and alignment
error in do_alloc_write

Signed-off-by: Tri Dao <daominhtri0503@gmail.com>
src/test/objectstore/Fragmentation_simulator.cc
src/test/objectstore/ObjectStoreImitator.cc
src/test/objectstore/ObjectStoreImitator.h

index 1e5b3764b70d9827d8a9d1caff4268b3f43a7b9b..f29404dfe55d4710e67ed417e6d23fe1a6a226e2 100644 (file)
@@ -11,6 +11,7 @@
 #include "include/buffer_fwd.h"
 #include "os/ObjectStore.h"
 #include "test/objectstore/ObjectStoreImitator.h"
+#include <fmt/core.h>
 #include <gtest/gtest.h>
 #include <iostream>
 
@@ -64,6 +65,7 @@ private:
 
 void FragmentationSimulator::init(const std::string &alloc_type, uint64_t size,
                                   uint64_t min_alloc_size) {
+  std::cout << std::endl;
   std::cout << "Initializing ObjectStoreImitator" << std::endl;
   os = new ObjectStoreImitator(g_ceph_context, "", min_alloc_size);
 
@@ -101,20 +103,54 @@ struct SimpleCWGenerator : public FragmentationSimulator::WorkloadGenerator {
   std::string name() override { return "SimpleCW"; }
   int generate_txns(ObjectStore::CollectionHandle &ch,
                     ObjectStoreImitator *os) override {
-    hobject_t h1;
-    h1.oid = "obj_1";
-    h1.set_hash(1);
-    h1.pool = 1;
-    auto oid = ghobject_t(h1);
-
-    ObjectStore::Transaction t1;
-    t1.create(ch->get_cid(), oid);
-    os->queue_transaction(ch, std::move(t1));
-
-    ObjectStore::Transaction t2;
-    t2.write(ch->get_cid(), oid, 0, _1Mb, make_bl(_1Mb, 'c'));
-    os->queue_transaction(ch, std::move(t2));
 
+    std::vector<ghobject_t> objs;
+    for (unsigned i{0}; i < 100; ++i) {
+      hobject_t h;
+      h.oid = fmt::format("obj_{}", i);
+      h.set_hash(1);
+      h.pool = 1;
+      objs.emplace_back(h);
+    }
+
+    std::vector<ObjectStore::Transaction> tls;
+    for (unsigned i{0}; i < 100; ++i) {
+      ObjectStore::Transaction t1;
+      t1.create(ch->get_cid(), objs[i]);
+      tls.emplace_back(std::move(t1));
+
+      ObjectStore::Transaction t2;
+      t2.write(ch->get_cid(), objs[i], 0, _1Mb, make_bl(_1Mb, 'c'));
+      tls.emplace_back(std::move(t2));
+    }
+
+    os->queue_transactions(ch, tls);
+
+    // reapply
+    os->queue_transactions(ch, tls);
+    tls.clear();
+
+    // Overwrite on object
+    for (unsigned i{0}; i < 100; ++i) {
+      ObjectStore::Transaction t;
+      t.write(ch->get_cid(), objs[i], _1Kb * i, _1Mb * 3,
+              make_bl(_1Mb * 3, 'x'));
+      tls.emplace_back(std::move(t));
+    }
+
+    os->queue_transactions(ch, tls);
+    tls.clear();
+
+    for (unsigned i{0}; i < 50; ++i) {
+      ObjectStore::Transaction t1, t2;
+      t1.clone(ch->get_cid(), objs[i], objs[i + 50]);
+      tls.emplace_back(std::move(t1));
+
+      t2.clone(ch->get_cid(), objs[i + 50], objs[i]);
+      tls.emplace_back(std::move(t2));
+    }
+
+    os->queue_transactions(ch, tls);
     return 0;
   }
 };
@@ -141,6 +177,8 @@ int main(int argc, char **argv) {
                   CINIT_FLAG_NO_DEFAULT_CONFIG_FILE);
   common_init_finish(FragmentationSimulator::cct->get());
 
+  FragmentationSimulator::cct->_conf->bluestore_clone_cow = false;
+
   ::testing::InitGoogleTest(&argc, argv);
   return RUN_ALL_TESTS();
 }
index 55620c3eb154666892e19509be12998d9a67b059..f95389786aca8e3c8bb26c29bf16a885be6e6cdc 100644 (file)
@@ -7,6 +7,7 @@
 #include "test/objectstore/ObjectStoreImitator.h"
 #include "common/errno.h"
 #include "include/ceph_assert.h"
+#include "include/intarith.h"
 
 #define dout_context cct
 #define OBJECT_MAX_SIZE 0xffffffff // 32 bits
@@ -22,10 +23,10 @@ void ObjectStoreImitator::print_status() {
   std::cout << std::hex
             << "Fragmentation score: " << alloc->get_fragmentation_score()
             << " , fragmentation: " << alloc->get_fragmentation()
-            << ", allocator name " << alloc->get_name() << ", allocator type "
-            << alloc->get_type() << ", capacity 0x" << alloc->get_capacity()
-            << ", block size 0x" << alloc->get_block_size() << ", free 0x"
-            << alloc->get_free() << std::dec << std::endl;
+            << ", allocator type " << alloc->get_type() << ", capacity 0x"
+            << alloc->get_capacity() << ", block size 0x"
+            << alloc->get_block_size() << ", free 0x" << alloc->get_free()
+            << std::dec << std::endl;
 }
 
 // ------- Transactions -------
@@ -393,7 +394,7 @@ int ObjectStoreImitator::_do_alloc_write(CollectionRef coll, ObjectRef &o,
                                          bufferlist &bl) {
 
   // No compression for now
-  uint64_t need = bl.length();
+  uint64_t need = p2roundup(static_cast<uint64_t>(bl.length()), min_alloc_size);
 
   PExtentVector prealloc;
 
index 2f10df01973c97737022d15fded9e2267a67d6e6..a26deef277ff5a4c95286e5b227773ef9a30cae9 100644 (file)
@@ -50,9 +50,13 @@ private:
 
     void punch_hole(uint64_t offset, uint64_t length,
                     PExtentVector &old_extents) {
-      if (offset > size || length == 0)
+      if (offset >= size || length == 0)
         return;
 
+      if (offset + length >= size) {
+        length = size - offset;
+      }
+
       uint64_t l_offset{0}, punched_length{0};
       PExtentVector to_be_punched, remains;
       for (auto e : extents) {
@@ -61,7 +65,8 @@ private:
 
         // Found where we need to punch
         if (l_offset >= offset) {
-          if (e.length + punched_length >= length) {
+          // We only punched a portion of the extent
+          if (e.length + punched_length > length) {
             uint64_t left = e.length + punched_length - length;
             e.length = length - punched_length;
             remains.emplace_back(e.offset + e.length, left);