#include "include/buffer.h"
#include "crimson/os/seastore/seastore_types.h"
+#include "crimson/os/seastore/transaction.h"
#include "crimson/os/seastore/segment_manager.h"
#include "crimson/common/errorator.h"
#include "crimson/os/seastore/cached_extent.h"
namespace crimson::os::seastore {
-/**
- * Transaction
- *
- * Representation of in-progress mutation. Used exclusively through Cache methods.
- */
-class Transaction {
- friend class Cache;
-
- RootBlockRef root; ///< ref to root if mutated by transaction
-
- segment_off_t offset = 0; ///< relative offset of next block
-
- pextent_set_t read_set; ///< set of extents read by paddr
- ExtentIndex write_set; ///< set of extents written by paddr
-
- std::list<CachedExtentRef> fresh_block_list; ///< list of fresh blocks
- std::list<CachedExtentRef> mutated_block_list; ///< list of mutated blocks
-
- pextent_set_t retired_set; ///< list of extents mutated by this transaction
-
- CachedExtentRef get_extent(paddr_t addr) {
- if (auto iter = write_set.find_offset(addr);
- iter != write_set.end()) {
- return CachedExtentRef(&*iter);
- } else if (
- auto iter = read_set.find(addr);
- iter != read_set.end()) {
- return *iter;
- } else {
- return CachedExtentRef();
- }
- }
-
- void add_to_retired_set(CachedExtentRef ref) {
- 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,
- // which is what we want.
- retired_set.insert(ref);
- }
- }
-
- void add_to_read_set(CachedExtentRef ref) {
- ceph_assert(read_set.count(ref) == 0);
- read_set.insert(ref);
- }
-
- void add_fresh_extent(CachedExtentRef ref) {
- fresh_block_list.push_back(ref);
- ref->set_paddr(make_record_relative_paddr(offset));
- offset += ref->get_length();
- write_set.insert(*ref);
- }
-
- void add_mutated_extent(CachedExtentRef ref) {
- mutated_block_list.push_back(ref);
- write_set.insert(*ref);
- }
-};
-using TransactionRef = std::unique_ptr<Transaction>;
-
/**
* Cache
*
Cache(SegmentManager &segment_manager);
~Cache();
- TransactionRef get_transaction() {
- return std::make_unique<Transaction>();
- }
-
/// Declare ref retired in t
void retire_extent(Transaction &t, CachedExtentRef ref) {
t.add_to_retired_set(ref);
laddr_t addr) = 0;
// TODO: probably unused, removed
- using submit_lba_transaction_ertr = crimson::errorator<
+ using complete_transaction_ertr = crimson::errorator<
crimson::ct_error::input_output_error>;
- using submit_lba_transaction_ret = submit_lba_transaction_ertr::future<>;
- virtual submit_lba_transaction_ret submit_lba_transaction(
+ using complete_transaction_ret = complete_transaction_ertr::future<>;
+ virtual complete_transaction_ret complete_transaction(
Transaction &t) = 0;
- virtual TransactionRef create_transaction() = 0;
-
virtual ~LBAManager() {}
};
using LBAManagerRef = std::unique_ptr<LBAManager>;
});
}
-BtreeLBAManager::submit_lba_transaction_ret
-BtreeLBAManager::submit_lba_transaction(
+BtreeLBAManager::complete_transaction_ret
+BtreeLBAManager::complete_transaction(
Transaction &t)
{
// This is a noop for now and may end up not being necessary
- return submit_lba_transaction_ertr::now();
+ return complete_transaction_ertr::now();
}
BtreeLBAManager::BtreeLBAManager(
return update_refcount(t, addr, 1);
}
- submit_lba_transaction_ret submit_lba_transaction(
+ complete_transaction_ret complete_transaction(
Transaction &t) final;
- TransactionRef create_transaction() final {
- auto t = new Transaction;
- return TransactionRef(t);
- }
-
private:
SegmentManager &segment_manager;
Cache &cache;
#include "os/Transaction.h"
#include "crimson/os/futurized_store.h"
+#include "transaction.h"
namespace crimson::os::seastore {
class Journal;
class LBAManager;
class TransactionManager;
-class Transaction;
-using TransactionRef = std::unique_ptr<Transaction>;
class Cache;
class SeaStore final : public FuturizedStore {
--- /dev/null
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#pragma once
+
+#include <iostream>
+
+#include "crimson/os/seastore/seastore_types.h"
+#include "crimson/os/seastore/cached_extent.h"
+#include "crimson/os/seastore/root_block.h"
+
+namespace crimson::os::seastore {
+
+/**
+ * Transaction
+ *
+ * Representation of in-progress mutation. Used exclusively through Cache methods.
+ */
+class Transaction {
+ friend class Cache;
+
+ RootBlockRef root; ///< ref to root if mutated by transaction
+
+ segment_off_t offset = 0; ///< relative offset of next block
+
+ pextent_set_t read_set; ///< set of extents read by paddr
+ ExtentIndex write_set; ///< set of extents written by paddr
+
+ std::list<CachedExtentRef> fresh_block_list; ///< list of fresh blocks
+ std::list<CachedExtentRef> mutated_block_list; ///< list of mutated blocks
+
+ pextent_set_t retired_set; ///< list of extents mutated by this transaction
+
+public:
+ CachedExtentRef get_extent(paddr_t addr) {
+ if (auto iter = write_set.find_offset(addr);
+ iter != write_set.end()) {
+ return CachedExtentRef(&*iter);
+ } else if (
+ auto iter = read_set.find(addr);
+ iter != read_set.end()) {
+ return *iter;
+ } else {
+ return CachedExtentRef();
+ }
+ }
+
+ void add_to_retired_set(CachedExtentRef ref) {
+ 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,
+ // which is what we want.
+ retired_set.insert(ref);
+ }
+ }
+
+ void add_to_read_set(CachedExtentRef ref) {
+ ceph_assert(read_set.count(ref) == 0);
+ read_set.insert(ref);
+ }
+
+ void add_fresh_extent(CachedExtentRef ref) {
+ fresh_block_list.push_back(ref);
+ ref->set_paddr(make_record_relative_paddr(offset));
+ offset += ref->get_length();
+ write_set.insert(*ref);
+ }
+
+ void add_mutated_extent(CachedExtentRef ref) {
+ mutated_block_list.push_back(ref);
+ write_set.insert(*ref);
+ }
+};
+using TransactionRef = std::unique_ptr<Transaction>;
+
+inline TransactionRef make_transaction() {
+ return std::make_unique<Transaction>();
+}
+
+}
return journal.open_for_write().safe_then([this] {
logger().debug("TransactionManager::mkfs: about to do_with");
return seastar::do_with(
- lba_manager.create_transaction(),
+ create_transaction(),
[this](auto &transaction) {
logger().debug("TransactionManager::mkfs: about to cache.mkfs");
cache.init();
logger().debug("TransactionManager::submit_transaction");
return journal.submit_record(std::move(*record)).safe_then(
- [this, t=std::move(t)](paddr_t addr) {
+ [this, t=std::move(t)](paddr_t addr) mutable {
cache.complete_commit(*t, addr);
},
submit_transaction_ertr::pass_further{},
/// Creates empty transaction
TransactionRef create_transaction() {
- return lba_manager.create_transaction();
+ return make_transaction();
}
/**
}
return journal.submit_record(std::move(*record)).safe_then(
- [this, t=std::move(t)](paddr_t addr) {
+ [this, t=std::move(t)](paddr_t addr) mutable {
cache.complete_commit(*t, addr);
},
crimson::ct_error::all_same_way([](auto e) {
return journal.open_for_write();
}).safe_then([this] {
return seastar::do_with(
- lba_manager->create_transaction(),
+ make_transaction(),
[this](auto &transaction) {
cache.init();
return cache.mkfs(*transaction
auto create_transaction() {
auto t = test_transaction_t{
- lba_manager->create_transaction(),
+ make_transaction(),
test_lba_mappings
};
cache.alloc_new_extent<TestBlockPhysical>(*t.t, TestBlockPhysical::SIZE);
std::move(bl),
true
).safe_then(
- [this, prev, t=std::move(t)] {
+ [this, prev, t=std::move(t)]() mutable {
cache.complete_commit(*t, prev);
return seastar::make_ready_future<std::optional<paddr_t>>(prev);
},
}
auto get_transaction() {
- return TransactionRef(new Transaction);
+ return make_transaction();
}
seastar::future<> set_up_fut() final {
return segment_manager.init().safe_then(
[this] {
return seastar::do_with(
- TransactionRef(new Transaction()),
+ make_transaction(),
[this](auto &transaction) {
cache.init();
return cache.mkfs(*transaction).safe_then(