]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/os/seastore/transaction: introduce weak transactions
authorSamuel Just <sjust@redhat.com>
Wed, 26 Aug 2020 21:50:16 +0000 (14:50 -0700)
committerSamuel Just <sjust@redhat.com>
Mon, 19 Oct 2020 22:38:09 +0000 (15:38 -0700)
This way, we can do a bulk scan of the store without building up
an unbounded amount of state in Transaction::read_set.  Note that
such transactions will not be snapshot isolated.

Signed-off-by: Samuel Just <sjust@redhat.com>
src/crimson/os/seastore/transaction.h
src/crimson/os/seastore/transaction_manager.h
src/test/crimson/seastore/test_btree_lba_manager.cc
src/test/crimson/seastore/test_transaction_manager.cc

index 43500d0356c883f8be2998fc7d616251b8398fee..3c6d77520f14d508f4d276f56cee017c31f3d02f 100644 (file)
@@ -44,6 +44,7 @@ public:
   }
 
   void add_to_retired_set(CachedExtentRef ref) {
+    ceph_assert(!is_weak());
     if (!ref->is_initial_pending()) {
       // && retired_set.count(ref->get_paddr()) == 0
       // If it's already in the set, insert here will be a noop,
@@ -58,11 +59,14 @@ public:
   }
 
   void add_to_read_set(CachedExtentRef ref) {
+    if (is_weak()) return;
+
     ceph_assert(read_set.count(ref) == 0);
     read_set.insert(ref);
   }
 
   void add_fresh_extent(CachedExtentRef ref) {
+    ceph_assert(!is_weak());
     fresh_block_list.push_back(ref);
     ref->set_paddr(make_record_relative_paddr(offset));
     offset += ref->get_length();
@@ -70,6 +74,7 @@ public:
   }
 
   void add_mutated_extent(CachedExtentRef ref) {
+    ceph_assert(!is_weak());
     mutated_block_list.push_back(ref);
     write_set.insert(*ref);
   }
@@ -86,8 +91,20 @@ public:
     return retired_set;
   }
 
+  bool is_weak() const {
+    return weak;
+  }
+
 private:
   friend class Cache;
+  friend Ref make_transaction();
+  friend Ref make_weak_transaction();
+
+  /**
+   * If set, *this may not be used to perform writes and will not provide
+   * consistentency allowing operations using to avoid maintaining a read_set.
+   */
+  const bool weak;
 
   RootBlockRef root;        ///< ref to root if read or written by transaction
 
@@ -100,11 +117,17 @@ private:
   std::list<CachedExtentRef> mutated_block_list; ///< list of mutated blocks
 
   pextent_set_t retired_set; ///< list of extents mutated by this transaction
+
+  Transaction(bool weak) : weak(weak) {}
 };
 using TransactionRef = Transaction::Ref;
 
 inline TransactionRef make_transaction() {
-  return std::make_unique<Transaction>();
+  return std::unique_ptr<Transaction>(new Transaction(false));
+}
+
+inline TransactionRef make_weak_transaction() {
+  return std::unique_ptr<Transaction>(new Transaction(true));
 }
 
 }
index cd2696bf84d3e051ea769b4a41f46a5a7184cc92..4536f28e07f8fd1d7ddc9cc43bc7b5a813117974 100644 (file)
@@ -67,6 +67,11 @@ public:
     return make_transaction();
   }
 
+  /// Creates weak transaction
+  TransactionRef create_weak_transaction() {
+    return make_weak_transaction();
+  }
+
   /**
    * Read extents corresponding to specified lba range
    */
index 8740d62a71099478a034845d222ce8b954dc7875..91531b39f884dedc77d021badb997f1520293544 100644 (file)
@@ -131,6 +131,14 @@ struct btree_lba_manager_test :
     return t;
   }
 
+  auto create_weak_transaction() {
+    auto t = test_transaction_t{
+      make_weak_transaction(),
+      test_lba_mappings
+    };
+    return t;
+  }
+
   void submit_test_transaction(test_transaction_t t) {
     submit_transaction(std::move(t.t)).get0();
     test_lba_mappings.swap(t.mappings);
index 6e7a80942db8097e49e2d965e12e8a14e226dc19..e381e2007aae3e659582588d803f194138a1659c 100644 (file)
@@ -166,6 +166,10 @@ struct transaction_manager_test_t : public seastar_test_suite_t {
     return { tm->create_transaction(), test_mappings };
   }
 
+  test_transaction_t create_weak_transaction() {
+    return { tm->create_weak_transaction(), test_mappings };
+  }
+
   TestBlockRef alloc_extent(
     test_transaction_t &t,
     laddr_t hint,
@@ -203,7 +207,7 @@ struct transaction_manager_test_t : public seastar_test_suite_t {
   }
 
   void check_mappings() {
-    auto t = create_transaction();
+    auto t = create_weak_transaction();
     check_mappings(t);
   }
 
@@ -264,7 +268,7 @@ struct transaction_manager_test_t : public seastar_test_suite_t {
       auto ext = get_extent(t, i.first, i.second.desc.len);
       EXPECT_EQ(i.second, ext->get_desc());
     }
-    auto lt = create_lazy_transaction();
+    auto lt = create_weak_transaction();
     lba_manager->scan_mappings(
       *lt.t,
       0,