]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
Fix bracket error in _add_transaction
authortridao <daominhtri0503@gmail.com>
Sun, 18 Jun 2023 21:24:17 +0000 (18:24 -0300)
committertridao <daominhtri0503@gmail.com>
Tue, 20 Jun 2023 17:29:53 +0000 (14:29 -0300)
Signed-off-by: Tri Dao <daominhtri0503@gmail.com>
src/test/objectstore/CMakeLists.txt
src/test/objectstore/Fragmentation_simulator.cc
src/test/objectstore/ObjectStoreImitator.cc
src/test/objectstore/ObjectStoreImitator.h

index 99a88a654b6b15427647ec666682889620b6a44a..23c8f26a41b3c4cf6e2a1b863d08fa41311fbd3e 100644 (file)
@@ -139,6 +139,7 @@ if(WITH_BLUESTORE)
     DESTINATION bin)
 endif()
 
+# fragmentation simulator
 add_library(ObjectStoreImitator OBJECT ObjectStoreImitator.cc)
 
 add_executable(ceph_test_fragmentation_sim
@@ -146,3 +147,6 @@ add_executable(ceph_test_fragmentation_sim
   $<TARGET_OBJECTS:ObjectStoreImitator>)
 add_ceph_unittest(ceph_test_fragmentation_sim)
 target_link_libraries(ceph_test_fragmentation_sim os global)
+
+set_target_properties(unittest_fastbmap_allocator PROPERTIES COMPILE_FLAGS
+"${UNITTEST_CXX_FLAGS}")
index a1fa64c299b6a5162096a88c8cedcf2064750f58..7a51a47aaa1b62ac14e6f605282c1888f2cf309f 100644 (file)
@@ -8,6 +8,7 @@
 #include "common/common_init.h"
 #include "common/hobject.h"
 #include "global/global_init.h"
+#include "include/buffer_fwd.h"
 #include "os/ObjectStore.h"
 #include "test/objectstore/ObjectStoreImitator.h"
 #include <gtest/gtest.h>
 
 #define dout_context g_ceph_context
 
+constexpr uint64_t _1Kb = 1024;
+constexpr uint64_t _1Mb = 1024 * _1Kb;
+constexpr uint64_t _1Gb = 1024 * _1Mb;
+
+static bufferlist make_bl(size_t len, char c) {
+  bufferlist bl;
+  if (len > 0) {
+    bl.reserve(len);
+    bl.append(std::string(len, c));
+  }
+
+  return bl;
+}
+
+// --------- FragmentationSimulator ----------
+
 class FragmentationSimulator {
 public:
   struct WorkloadGenerator {
@@ -27,6 +44,7 @@ public:
   };
   using WorkloadGeneratorRef = std::shared_ptr<WorkloadGenerator>;
   std::vector<WorkloadGeneratorRef> generators;
+
   void add_generator(WorkloadGeneratorRef gen) {
     std::cout << "Generator: " << gen->name() << " added\n";
     generators.push_back(gen);
@@ -48,10 +66,15 @@ public:
     return 0;
   }
 
-  FragmentationSimulator() {
-    std::cout << "Initializing simulator\n" << std::endl;
-    os = new ObjectStoreImitator(g_ceph_context, "", 4096);
-    os->init_alloc("btree", 1024 * 1024 * 1024, 4096);
+  FragmentationSimulator(const std::string &alloc_type, uint64_t size,
+                         uint64_t min_alloc_size = 4096) {
+    std::cout << "Initializing simulator" << std::endl;
+
+    os = new ObjectStoreImitator(g_ceph_context, "", min_alloc_size);
+    std::cout << "Initializing allocator: " << alloc_type << " size: 0x"
+              << std::hex << size << std::dec << "\n"
+              << std::endl;
+    os->init_alloc(alloc_type, size);
   }
   ~FragmentationSimulator() { delete os; }
 
@@ -59,6 +82,8 @@ private:
   ObjectStoreImitator *os;
 };
 
+// --------- SimpleCWGenerator ----------
+
 struct SimpleCWGenerator : public FragmentationSimulator::WorkloadGenerator {
   std::string name() override { return "SimpleCW"; }
   int generate_txns(ObjectStore::CollectionHandle &ch,
@@ -67,21 +92,30 @@ struct SimpleCWGenerator : public FragmentationSimulator::WorkloadGenerator {
     h1.oid = "obj_1";
     h1.set_hash(1);
     h1.pool = 1;
+    auto oid = ghobject_t(h1);
 
     ObjectStore::Transaction t1;
-    t1.create(ch->cid, ghobject_t(h1));
+    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));
+
     return 0;
   }
 };
 
+// ----------- Tests -----------
+
 TEST(FragmentationSimulator, simple) {
-  auto sim = FragmentationSimulator();
+  auto sim = FragmentationSimulator("stupid", _1Gb);
   sim.add_generator(std::make_shared<SimpleCWGenerator>());
   sim.begin_simulation_with_generators();
 }
 
+// ----------- main -----------
+
 int main(int argc, char **argv) {
   auto args = argv_to_vec(argc, argv);
   auto cct =
index 5959293504d4e47a0a3d150a99b768dd717d79fc..47bd4c02727a3f4e14c0b35461b468d59e21421a 100644 (file)
 #define OBJECT_MAX_SIZE 0xffffffff // 32 bits
 
 void ObjectStoreImitator::init_alloc(const std::string &alloc_type,
-                                     int64_t size, uint64_t min_alloc_size) {
+                                     int64_t size) {
   alloc.reset(Allocator::create(cct, alloc_type, size, min_alloc_size));
 }
 
+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;
+}
+
 // ------- Transactions -------
 
 int ObjectStoreImitator::queue_transactions(CollectionHandle &ch,
@@ -55,7 +65,7 @@ void ObjectStoreImitator::_add_transaction(Transaction *t) {
 
   std::vector<ObjectRef> ovec(i.objects.size());
 
-  while (i.have_op()) {
+  for (int pos = 0; i.have_op(); ++pos) {
     Transaction::Op *op = i.decode_op();
     int r = 0;
 
@@ -68,8 +78,10 @@ void ObjectStoreImitator::_add_transaction(Transaction *t) {
 
     switch (op->op) {
     case Transaction::OP_RMCOLL: {
-      if (coll_map.find(c->cid) != coll_map.end())
-        coll_map.erase(c->cid);
+      const coll_t &cid = i.get_cid(op->cid);
+      r = _remove_collection(cid, &c);
+      if (!r)
+        continue;
     } break;
 
     case Transaction::OP_MKCOLL: {
@@ -148,10 +160,10 @@ void ObjectStoreImitator::_add_transaction(Transaction *t) {
 
     switch (op->op) {
     case Transaction::OP_CREATE:
-    case Transaction::OP_TOUCH:
+    case Transaction::OP_TOUCH: {
       _assign_nid(o);
       r = 0;
-      break;
+    } break;
 
     case Transaction::OP_WRITE: {
       uint64_t off = op->off;
@@ -213,48 +225,50 @@ void ObjectStoreImitator::_add_transaction(Transaction *t) {
       uint64_t dstoff = op->dest_off;
       r = _clone_range(c, o, no, srcoff, len, dstoff);
     } break;
-      {
-      case Transaction::OP_COLL_ADD:
-        ceph_abort_msg("not implemented");
-        break;
-
-      case Transaction::OP_COLL_REMOVE:
-        ceph_abort_msg("not implemented");
-        break;
-
-      case Transaction::OP_COLL_MOVE:
-        ceph_abort_msg("deprecated");
-        break;
-
-      case Transaction::OP_COLL_MOVE_RENAME:
-      case Transaction::OP_TRY_RENAME: {
-        ceph_assert(op->cid == op->dest_cid);
-        const ghobject_t &noid = i.get_oid(op->dest_oid);
-        ObjectRef &no = ovec[op->dest_oid];
-        if (!no) {
-          no = c->get_obj(noid, false);
-        }
-        r = _rename(c, o, no, noid);
-      } break;
-
-      case Transaction::OP_OMAP_CLEAR:
-      case Transaction::OP_OMAP_SETKEYS:
-      case Transaction::OP_OMAP_RMKEYS:
-      case Transaction::OP_OMAP_RMKEYRANGE:
-      case Transaction::OP_OMAP_SETHEADER:
-        break;
-
-      case Transaction::OP_SETALLOCHINT: {
-        r = _set_alloc_hint(c, o, op->expected_object_size,
-                            op->expected_write_size, op->hint);
-      } break;
-
-      default:
-        derr << __func__ << " bad op " << op->op << dendl;
-        ceph_abort();
+
+    case Transaction::OP_COLL_ADD:
+    case Transaction::OP_COLL_REMOVE:
+      ceph_abort_msg("not implemented");
+      break;
+
+    case Transaction::OP_COLL_MOVE:
+      ceph_abort_msg("deprecated");
+      break;
+
+    case Transaction::OP_COLL_MOVE_RENAME:
+    case Transaction::OP_TRY_RENAME: {
+      ceph_assert(op->cid == op->dest_cid);
+      const ghobject_t &noid = i.get_oid(op->dest_oid);
+      ObjectRef &no = ovec[op->dest_oid];
+      if (!no) {
+        no = c->get_obj(noid, false);
       }
-    endop:
-      return;
+      r = _rename(c, o, no, noid);
+    } break;
+
+    case Transaction::OP_OMAP_CLEAR:
+    case Transaction::OP_OMAP_SETKEYS:
+    case Transaction::OP_OMAP_RMKEYS:
+    case Transaction::OP_OMAP_RMKEYRANGE:
+    case Transaction::OP_OMAP_SETHEADER:
+      break;
+
+    case Transaction::OP_SETALLOCHINT: {
+      r = _set_alloc_hint(c, o, op->expected_object_size,
+                          op->expected_write_size, op->hint);
+    } break;
+
+    default:
+      derr << __func__ << " bad op " << op->op << dendl;
+      ceph_abort();
+    }
+
+  endop:
+    if (r < 0) {
+      derr << __func__ << " error " << cpp_strerror(r)
+           << " not handled on operation " << op->op << " (op " << pos
+           << ", counting from 0)" << dendl;
+      ceph_abort_msg("unexpected error");
     }
   }
 }
@@ -383,9 +397,13 @@ int ObjectStoreImitator::_do_alloc_write(CollectionRef coll, ObjectRef &o,
   int64_t prealloc_left =
       alloc->allocate(need, min_alloc_size, need, 0, &prealloc);
   if (prealloc_left < 0 || prealloc_left < (int64_t)need) {
-    if (prealloc.size()) {
+    derr << __func__ << " failed to allocate 0x" << std::hex << need
+         << " allocated 0x " << (prealloc_left < 0 ? 0 : prealloc_left)
+         << " min_alloc_size 0x" << min_alloc_size << " available 0x "
+         << alloc->get_free() << std::dec << dendl;
+    if (prealloc.size())
       alloc->release(prealloc);
-    }
+
     return -ENOSPC;
   }
 
@@ -671,6 +689,8 @@ int ObjectStoreImitator::collection_empty(CollectionHandle &ch, bool *empty) {
   int r =
       collection_list(ch, ghobject_t(), ghobject_t::get_max(), 1, &ls, &next);
   if (r < 0) {
+    derr << __func__ << " collection_list returned: " << cpp_strerror(r)
+         << dendl;
     return r;
   }
 
index cfe7658f98f608413f69c2925fcf46cbb01f3132..2f10df01973c97737022d15fded9e2267a67d6e6 100644 (file)
@@ -83,7 +83,6 @@ private:
   typedef boost::intrusive_ptr<Object> ObjectRef;
 
   struct Collection : public CollectionImpl {
-    ObjectStoreImitator *sim;
     bluestore_cnode_t cnode;
     std::map<ghobject_t, ObjectRef> objects;
 
@@ -155,8 +154,8 @@ private:
     }
 
     Collection(ObjectStoreImitator *sim_, coll_t cid_)
-        : CollectionImpl(sim_->cct, cid_), sim(sim_), exists(true),
-          commit_queue(nullptr) {}
+        : CollectionImpl(sim_->cct, cid_), exists(true), commit_queue(nullptr) {
+    }
   };
 
   CollectionRef _get_collection(const coll_t &cid);
@@ -227,11 +226,12 @@ public:
 
   ~ObjectStoreImitator() = default;
 
-  void init_alloc(const std::string &alloc_type, int64_t size,
-                  uint64_t min_alloc_size);
+  void init_alloc(const std::string &alloc_type, int64_t size);
+  void print_status();
 
   // Overrides
 
+  // This is often not called directly but through queue_transaction
   int queue_transactions(CollectionHandle &ch, std::vector<Transaction> &tls,
                          TrackedOpRef op = TrackedOpRef(),
                          ThreadPool::TPHandle *handle = NULL) override;