From: Samuel Just Date: Wed, 26 Aug 2020 21:50:16 +0000 (-0700) Subject: crimson/os/seastore/transaction: introduce weak transactions X-Git-Tag: v16.1.0~807^2~27 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=274e962bfec0088b21cc712de15bfd69132dbfbb;p=ceph.git crimson/os/seastore/transaction: introduce weak transactions 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 --- diff --git a/src/crimson/os/seastore/transaction.h b/src/crimson/os/seastore/transaction.h index 43500d0356c8..3c6d77520f14 100644 --- a/src/crimson/os/seastore/transaction.h +++ b/src/crimson/os/seastore/transaction.h @@ -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 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(); + return std::unique_ptr(new Transaction(false)); +} + +inline TransactionRef make_weak_transaction() { + return std::unique_ptr(new Transaction(true)); } } diff --git a/src/crimson/os/seastore/transaction_manager.h b/src/crimson/os/seastore/transaction_manager.h index cd2696bf84d3..4536f28e07f8 100644 --- a/src/crimson/os/seastore/transaction_manager.h +++ b/src/crimson/os/seastore/transaction_manager.h @@ -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 */ diff --git a/src/test/crimson/seastore/test_btree_lba_manager.cc b/src/test/crimson/seastore/test_btree_lba_manager.cc index 8740d62a7109..91531b39f884 100644 --- a/src/test/crimson/seastore/test_btree_lba_manager.cc +++ b/src/test/crimson/seastore/test_btree_lba_manager.cc @@ -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); diff --git a/src/test/crimson/seastore/test_transaction_manager.cc b/src/test/crimson/seastore/test_transaction_manager.cc index 6e7a80942db8..e381e2007aae 100644 --- a/src/test/crimson/seastore/test_transaction_manager.cc +++ b/src/test/crimson/seastore/test_transaction_manager.cc @@ -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,