]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test/allocator_replay_test: implement "try_alloc" command. 42895/head
authorIgor Fedotov <ifedotov@suse.com>
Mon, 23 Aug 2021 14:46:10 +0000 (17:46 +0300)
committerIgor Fedotov <ifedotov@suse.com>
Mon, 23 Aug 2021 14:55:33 +0000 (17:55 +0300)
This permits trying multiple allocations of chosen size on allocator
being at specific state (which is determined by free-dump report replay)

Signed-off-by: Igor Fedotov <ifedotov@suse.com>
src/test/objectstore/allocator_replay_test.cc

index f9a35bbe4be378c3b8952677edcdc8f239a1721c..7927790c485f31f175d8229c217bf25817afb1ef 100644 (file)
@@ -18,7 +18,7 @@
 using namespace std;
 
 void usage(const string &name) {
-  cerr << "Usage: " << name << " <log_to_replay> <raw_duplicate|free_dump>"
+  cerr << "Usage: " << name << " <log_to_replay> <raw_duplicate|free_dump|try_alloc count want alloc_unit>"
        << std::endl;
 }
 
@@ -252,11 +252,11 @@ int replay_free_dump_and_apply(char* fname,
   JSONObj::data_val v;
   ceph_assert(p.is_object());
 
-  auto *o = p.find_obj("allocator_type");
+  auto *o = p.find_obj("alloc_type");
   ceph_assert(o);
   alloc_type = o->get_data_val().str;
 
-  o = p.find_obj("allocator_name");
+  o = p.find_obj("alloc_name");
   ceph_assert(o);
   alloc_name = o->get_data_val().str;
 
@@ -353,5 +353,41 @@ int main(int argc, char **argv)
         }
         return 0;
       });
+  } else if (strcmp(argv[2], "try_alloc") == 0) {
+    if (argc < 6) {
+      std::cerr << "Error: insufficient arguments for \"try_alloc\" operation."
+                << std::endl;
+      usage(argv[0]);
+      return 1;
+    }
+    auto count = strtoul(argv[3], nullptr, 10);
+    auto want = strtoul(argv[4], nullptr, 10);
+    auto alloc_unit = strtoul(argv[5], nullptr, 10);
+
+    return replay_free_dump_and_apply(argv[1],
+      [&](Allocator* a, const string& aname) {
+        ceph_assert(a);
+        std::cout << "Fragmentation:" << a->get_fragmentation()
+                  << std::endl;
+        std::cout << "Fragmentation score:" << a->get_fragmentation_score()
+                  << std::endl;
+        std::cout << "Free:" << std::hex << a->get_free() << std::dec
+                  << std::endl;
+        {
+          PExtentVector extents;
+          for(size_t i = 0; i < count; i++) {
+              extents.clear();
+              auto r = a->allocate(want, alloc_unit, 0, &extents);
+              if (r < 0) {
+                  std::cerr << "Error: allocation failure at step:" << i + 1
+                            << ", ret = " << r << std::endl;
+              return -1;
+            }
+         }
+        }
+        std::cout << "Successfully allocated: " << count << " * " << want
+                  << ", unit:" << alloc_unit << std::endl;
+        return 0;
+      });
   }
 }