]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
seastore/rbm: remove changes related to transaction/cache 41041/head
authormyoungwon oh <ohmyoungwon@gmail.com>
Tue, 15 Jun 2021 15:43:34 +0000 (00:43 +0900)
committermyoungwon oh <ohmyoungwon@gmail.com>
Tue, 15 Jun 2021 15:43:34 +0000 (00:43 +0900)
Signed-off-by: Myoungwon Oh <myoungwon.oh@samsung.com>
src/crimson/os/seastore/cache.cc
src/crimson/os/seastore/random_block_manager/nvme_manager.cc
src/crimson/os/seastore/random_block_manager/nvme_manager.h
src/crimson/os/seastore/transaction.h
src/test/crimson/seastore/test_randomblock_manager.cc

index 9b895900437ee8876ffb66a9416000ef97548a43..ea0fb10b5ddd3a9ef495c30775022ab857bd83a8 100644 (file)
@@ -313,15 +313,6 @@ std::optional<record_t> Cache::try_construct_record(Transaction &t)
       });
   }
 
-  for (auto b : t.allocated_blocks) {
-    bufferlist bl;
-    encode(b.alloc_blk_ids, bl);
-    delta_info_t delta;
-    delta.type = extent_types_t::RBM_ALLOC_INFO;
-    delta.bl = bl;
-    record.deltas.push_back(delta);
-  }
-
   return std::make_optional<record_t>(std::move(record));
 }
 
index 5207dbee4ae89f99b623007082257245c6ebd3ee..af521abdb8c8f0d6c836751ce5339b3befc5627d 100644 (file)
@@ -192,20 +192,9 @@ NVMeManager::find_block_ret NVMeManager::find_free_block(Transaction &t, size_t
              bl_bitmap_block.append(bp);
              decode(b_block, bl_bitmap_block);
              auto max = max_block_by_bitmap_block();
-             auto allocated_blocks = t.get_rbm_allocated_blocks();
              for (uint64_t i = 0;
                  i < max && (uint64_t)size/super.block_size > allocated; i++) {
                auto block_id = convert_bitmap_block_no_to_block_id(i, addr);
-               bool out = false;
-               for (auto b : allocated_blocks) {
-                 if (b.alloc_blk_ids.intersects(block_id, 1)) {
-                   out = true;
-                   break;
-                 }
-               }
-               if (out) {
-                 continue;
-               }
                if (b_block.is_allocated(i)) {
                  continue;
                }
@@ -273,13 +262,12 @@ NVMeManager::allocate_ertr::future<> NVMeManager::alloc_extent(
        -> allocate_ertr::future<> {
        logger().debug("after find_free_block: allocated {}", alloc_extent);
        if (!alloc_extent.empty()) {
-         // add alloc info to delta
          rbm_alloc_delta_t alloc_info {
            extent_types_t::RBM_ALLOC_INFO,
            alloc_extent,
            rbm_alloc_delta_t::op_types_t::SET
          };
-         t.add_rbm_allocated_blocks(alloc_info);
+         // TODO: add alloc info to delta
        } else {
          return crimson::ct_error::enospc::make();
        }
@@ -295,6 +283,12 @@ NVMeManager::allocate_ertr::future<> NVMeManager::alloc_extent(
 
 NVMeManager::free_block_ertr::future<> NVMeManager::free_extent(
     Transaction &t, blk_paddr_t from, size_t len)
+{
+  return free_block_ertr::now();
+}
+
+NVMeManager::free_block_ertr::future<> NVMeManager::add_free_extent(
+    std::vector<rbm_alloc_delta_t>& v, blk_paddr_t from, size_t len)
 {
   ceph_assert(!(len % super.block_size));
   blk_id_t blk_id_start = from / super.block_size;
@@ -306,7 +300,7 @@ NVMeManager::free_block_ertr::future<> NVMeManager::free_extent(
     free_extent,
     rbm_alloc_delta_t::op_types_t::CLEAR
   };
-  t.add_rbm_allocated_blocks(alloc_info);
+  v.push_back(alloc_info);
   return free_block_ertr::now();
 }
 
@@ -419,14 +413,18 @@ NVMeManager::abort_allocation_ertr::future<> NVMeManager::abort_allocation(
   /*
    * TODO: clear all allocation infos associated with transaction in in-memory allocator
    */
-  t.clear_rbm_allocated_blocks();
   return abort_allocation_ertr::now();
 }
 
 NVMeManager::write_ertr::future<> NVMeManager::complete_allocation(
     Transaction &t)
 {
-  auto alloc_blocks = t.get_rbm_allocated_blocks();
+  return write_ertr::now();
+}
+
+NVMeManager::write_ertr::future<> NVMeManager::sync_allocation(
+    std::vector<rbm_alloc_delta_t> &alloc_blocks)
+{
   if (alloc_blocks.empty()) {
     return write_ertr::now();
   }
index 7015e351e30b74851f14a8859f1f9e38b17276f3..ca45eedd49c862e76813cf0e40cfaacae4268bc0 100644 (file)
@@ -355,6 +355,10 @@ public:
   }
 
   write_ertr::future<> write(blk_paddr_t addr, bufferlist &bl);
+  write_ertr::future<> sync_allocation(
+      std::vector<rbm_alloc_delta_t>& alloc_blocks);
+  free_block_ertr::future<> add_free_extent(
+      std::vector<rbm_alloc_delta_t>& v, blk_paddr_t from, size_t len);
 
 private:
   /*
index 941e61bb127817c839a271d8acc3ee09c794f022..7a46e5c299374efff472e5137dae7e09f8ad25fb 100644 (file)
@@ -116,18 +116,6 @@ public:
     return weak;
   }
 
-  void add_rbm_allocated_blocks(rbm_alloc_delta_t &d) {
-    allocated_blocks.push_back(d);
-  }
-  void clear_rbm_allocated_blocks() {
-    if (!allocated_blocks.empty()) {
-      allocated_blocks.clear();
-    }
-  }
-  const auto &get_rbm_allocated_blocks() {
-    return allocated_blocks;
-  }
-
 private:
   friend class Cache;
   friend Ref make_test_transaction();
@@ -159,8 +147,6 @@ private:
 
   retired_extent_gate_t::token_t retired_gate_token;
 
-  std::vector<rbm_alloc_delta_t> allocated_blocks;
-
 public:
   Transaction(
     OrderingHandle &&handle,
index 994a9b8afdf4c24f5fcb579095aba7ad70ea10e2..ca21453ddd1d1524af8ef08b3f7e841bf73ad2b1 100644 (file)
@@ -33,6 +33,21 @@ struct rbm_test_t : public  seastar_test_suite_t,
   std::unique_ptr<NVMeManager> rbm_manager;
   nvme_device::NVMeBlockDevice *device;
 
+  struct rbm_transaction {
+    void add_rbm_allocated_blocks(rbm_alloc_delta_t &d) {
+      allocated_blocks.push_back(d);
+    }
+    void clear_rbm_allocated_blocks() {
+      if (!allocated_blocks.empty()) {
+       allocated_blocks.clear();
+      }
+    }
+    const auto &get_rbm_allocated_blocks() {
+      return allocated_blocks;
+    }
+    std::vector<rbm_alloc_delta_t> allocated_blocks;
+  };
+
   std::default_random_engine generator;
 
   const uint64_t block_size = DEFAULT_BLOCK_SIZE;
@@ -83,33 +98,33 @@ struct rbm_test_t : public  seastar_test_suite_t,
     return rbm_manager->read(addr, ptr).unsafe_get0();
   }
 
-  auto create_transaction() {
-    return tm->create_transaction();
+  auto create_rbm_transaction() {
+    return std::make_unique<rbm_transaction>();
   }
 
-  auto alloc_extent(Transaction &t, size_t size) {
-    return rbm_manager->alloc_extent(t, size).unsafe_get0();
+  auto alloc_extent(rbm_transaction &t, size_t size) {
+    auto tt = tm->create_transaction(); // dummy transaction
+    auto extent = rbm_manager->find_free_block(*tt, size).unsafe_get0();
+    if (!extent.empty()) {
+      rbm_alloc_delta_t alloc_info {
+       extent_types_t::RBM_ALLOC_INFO,
+         extent,
+         rbm_alloc_delta_t::op_types_t::SET
+      };
+      t.add_rbm_allocated_blocks(alloc_info);
+    }
   }
 
-  auto free_extent(Transaction &t, interval_set<blk_id_t> range) {
+  auto free_extent(rbm_transaction &t, interval_set<blk_id_t> range) {
     for (auto r : range) {
       logger().debug("free_extent: start {} len {}", r.first * DEFAULT_BLOCK_SIZE,
                      r.second * DEFAULT_BLOCK_SIZE);
-      return rbm_manager->free_extent(t, r.first * DEFAULT_BLOCK_SIZE,
-            r.second * DEFAULT_BLOCK_SIZE).unsafe_get0();
-    }
-  }
-
-  auto submit_transaction(Transaction &t) {
-    auto record = cache.try_construct_record(t);
-    if (!record) {
-      return false;
+      rbm_manager->add_free_extent(t.allocated_blocks, r.first * DEFAULT_BLOCK_SIZE,
+                                   r.second * DEFAULT_BLOCK_SIZE);
     }
-    // TODO: write record on journal
-    return true;
   }
 
-  interval_set<blk_id_t> get_allocated_blk_ids(Transaction &t) {
+  interval_set<blk_id_t> get_allocated_blk_ids(rbm_transaction &t) {
     auto allocated_blocks = t.get_rbm_allocated_blocks();
     interval_set<blk_id_t> alloc_ids;
     for (auto p : allocated_blocks) {
@@ -152,8 +167,9 @@ struct rbm_test_t : public  seastar_test_suite_t,
     return ret;
   }
 
-  auto complete_allocation(Transaction &t) {
-    return rbm_manager->complete_allocation(t).unsafe_get0();
+  auto complete_allocation(rbm_transaction &t) {
+    auto alloc_blocks = t.get_rbm_allocated_blocks();
+    return rbm_manager->sync_allocation(alloc_blocks).unsafe_get0();
   }
 
   bufferptr generate_extent(size_t blocks) {
@@ -215,17 +231,15 @@ TEST_F(rbm_test_t, block_alloc_test)
  run_async([this] {
    mkfs();
    open();
-   auto t = tm->create_transaction();
+   auto t = create_rbm_transaction();
    alloc_extent(*t, DEFAULT_BLOCK_SIZE);
    auto alloc_ids = get_allocated_blk_ids(*t);
-   ASSERT_TRUE(submit_transaction(*t));
    complete_allocation(*t);
    ASSERT_TRUE(check_ids_are_allocated(alloc_ids));
 
-   auto t2 = tm->create_transaction();
+   auto t2 = create_rbm_transaction();
    alloc_extent(*t2, DEFAULT_BLOCK_SIZE * 3);
    alloc_ids = get_allocated_blk_ids(*t2);
-   ASSERT_TRUE(submit_transaction(*t2));
    complete_allocation(*t2);
    ASSERT_TRUE(check_ids_are_allocated(alloc_ids));
  });
@@ -236,32 +250,28 @@ TEST_F(rbm_test_t, block_alloc_free_test)
  run_async([this] {
    mkfs();
    open();
-   auto t = tm->create_transaction();
+   auto t = create_rbm_transaction();
    alloc_extent(*t, DEFAULT_BLOCK_SIZE);
    auto alloc_ids = get_allocated_blk_ids(*t);
    free_extent(*t, alloc_ids);
-   ASSERT_TRUE(submit_transaction(*t));
    complete_allocation(*t);
    ASSERT_TRUE(check_ids_are_allocated(alloc_ids, false));
 
-   auto t2 = tm->create_transaction();
+   auto t2 = create_rbm_transaction();
    alloc_extent(*t2, DEFAULT_BLOCK_SIZE * 4);
    alloc_ids = get_allocated_blk_ids(*t2);
    free_extent(*t2, alloc_ids);
-   ASSERT_TRUE(submit_transaction(*t2));
    complete_allocation(*t2);
    ASSERT_TRUE(check_ids_are_allocated(alloc_ids, false));
 
-   auto t3 = tm->create_transaction();
+   auto t3 = create_rbm_transaction();
    alloc_extent(*t3, DEFAULT_BLOCK_SIZE * 8);
    alloc_ids = get_allocated_blk_ids(*t3);
-   ASSERT_TRUE(submit_transaction(*t3));
    complete_allocation(*t3);
    ASSERT_TRUE(check_ids_are_allocated(alloc_ids));
 
-   auto t4 = tm->create_transaction();
+   auto t4 = create_rbm_transaction();
    free_extent(*t4, alloc_ids);
-   ASSERT_TRUE(submit_transaction(*t4));
    complete_allocation(*t4);
    ASSERT_TRUE(check_ids_are_allocated(alloc_ids, false));
  });
@@ -333,17 +343,15 @@ TEST_F(rbm_test_t, check_free_blocks)
    ASSERT_TRUE(rbm_manager->get_free_blocks() == DEFAULT_TEST_SIZE/DEFAULT_BLOCK_SIZE - 5);
    auto free = rbm_manager->get_free_blocks();
    interval_set<blk_id_t> alloc_ids;
-   auto t = tm->create_transaction();
+   auto t = create_rbm_transaction();
    alloc_extent(*t, DEFAULT_BLOCK_SIZE * 4);
    alloc_ids = get_allocated_blk_ids(*t);
-   ASSERT_TRUE(submit_transaction(*t));
    complete_allocation(*t);
    ASSERT_TRUE(rbm_manager->get_free_blocks() == free - 4);
 
    free = rbm_manager->get_free_blocks();
-   auto t2 = tm->create_transaction();
+   auto t2 = create_rbm_transaction();
    free_extent(*t2, alloc_ids);
-   ASSERT_TRUE(submit_transaction(*t2));
    complete_allocation(*t2);
    ASSERT_TRUE(rbm_manager->get_free_blocks() == free + 4);
  });