From 8aab9256b1a9575f3b0855c0dc467c01e47e4bf6 Mon Sep 17 00:00:00 2001 From: myoungwon oh Date: Fri, 3 Jun 2022 10:27:32 +0900 Subject: [PATCH] crimson/os/seastore/cbjournal: make journal_tail and written_to to use journal_seq_t instead of rbm_abs_addr Signed-off-by: Myoungwon Oh --- .../journal/circular_bounded_journal.cc | 60 +++++++++++-------- .../journal/circular_bounded_journal.h | 34 ++++++----- src/test/crimson/seastore/test_cbjournal.cc | 21 +++++-- 3 files changed, 70 insertions(+), 45 deletions(-) diff --git a/src/crimson/os/seastore/journal/circular_bounded_journal.cc b/src/crimson/os/seastore/journal/circular_bounded_journal.cc index c112fb4bf614e..07d13f69a5216 100644 --- a/src/crimson/os/seastore/journal/circular_bounded_journal.cc +++ b/src/crimson/os/seastore/journal/circular_bounded_journal.cc @@ -42,7 +42,11 @@ CircularBoundedJournal::mkfs(const mkfs_config_t& config) CircularBoundedJournal::cbj_header_t head; head.block_size = config.block_size; head.size = config.total_size - device->get_block_size(); - head.journal_tail = device->get_block_size(); + head.journal_tail = + journal_seq_t{0, + convert_abs_addr_to_paddr( + device->get_block_size(), + config.device_id)}; head.device_id = config.device_id; encode(head, bl); header = head; @@ -86,18 +90,13 @@ CircularBoundedJournal::open_for_mkfs() CircularBoundedJournal::open_for_mount_ret CircularBoundedJournal::open_for_mount() { - paddr_t paddr = convert_abs_addr_to_paddr( - get_written_to(), - header.device_id); ceph_assert(initialized); - if (circulation_seq == NULL_SEG_SEQ) { - circulation_seq = 0; + if (written_to.segment_seq == NULL_SEG_SEQ) { + written_to.segment_seq = 0; } return open_for_mount_ret( open_for_mount_ertr::ready_future_marker{}, - journal_seq_t{ - circulation_seq, - paddr}); + get_written_to()); } CircularBoundedJournal::close_ertr::future<> CircularBoundedJournal::close() @@ -120,7 +119,7 @@ CircularBoundedJournal::submit_record_ret CircularBoundedJournal::submit_record( { LOG_PREFIX(CircularBoundedJournal::submit_record); assert(write_pipeline); - assert(circulation_seq != NULL_SEG_SEQ); + assert(written_to.segment_seq != NULL_SEG_SEQ); auto r_size = record_group_size_t(record.size, get_block_size()); auto encoded_size = r_size.get_encoded_length(); if (encoded_size > get_available_size()) { @@ -128,10 +127,13 @@ CircularBoundedJournal::submit_record_ret CircularBoundedJournal::submit_record( encoded_size, get_available_size()); return crimson::ct_error::erange::make(); } - if (encoded_size + get_written_to() > get_journal_end()) { + if (encoded_size + get_rbm_addr(get_written_to()) > get_journal_end()) { DEBUG("roll"); - set_written_to(get_start_addr()); - ++circulation_seq; + paddr_t paddr = convert_abs_addr_to_paddr( + get_start_addr(), + header.device_id); + set_written_to( + journal_seq_t{++written_to.segment_seq, paddr}); if (encoded_size > get_available_size()) { ERROR("rolled, record size {}, but available size {}", encoded_size, get_available_size()); @@ -139,24 +141,27 @@ CircularBoundedJournal::submit_record_ret CircularBoundedJournal::submit_record( } } - journal_seq_t j_seq { - circulation_seq, - convert_abs_addr_to_paddr( - get_written_to(), - header.device_id)}; + journal_seq_t j_seq = get_written_to(); ceph::bufferlist to_write = encode_record( std::move(record), device->get_block_size(), j_seq, 0); assert(to_write.length() == encoded_size); - auto target = get_written_to(); + auto target = get_rbm_addr(get_written_to()); auto new_written_to = target + encoded_size; if (new_written_to >= get_journal_end()) { assert(new_written_to == get_journal_end()); DEBUG("roll"); - set_written_to(get_start_addr()); - ++circulation_seq; + paddr_t paddr = convert_abs_addr_to_paddr( + get_start_addr(), + header.device_id); + set_written_to( + journal_seq_t{++written_to.segment_seq, paddr}); } else { - set_written_to(new_written_to); + paddr_t paddr = convert_abs_addr_to_paddr( + new_written_to, + header.device_id); + set_written_to( + journal_seq_t{written_to.segment_seq, paddr}); } DEBUG("{}, target {}", r_size, target); @@ -266,11 +271,11 @@ Journal::replay_ret CircularBoundedJournal::replay( header = head; DEBUG("header : {}", header); initialized = true; - circulation_seq = NULL_SEG_SEQ; + written_to.segment_seq = NULL_SEG_SEQ; set_written_to(get_journal_tail()); return seastar::do_with( bool(false), - rbm_abs_addr(get_journal_tail()), + rbm_abs_addr(get_rbm_addr(get_journal_tail())), std::move(delta_handler), segment_seq_t(NULL_SEG_SEQ), [this, FNAME](auto &is_rolled, auto &cursor_addr, auto &d_handler, auto &expected_seq) { @@ -326,8 +331,11 @@ Journal::replay_ret CircularBoundedJournal::replay( ++expected_seq; is_rolled = true; } - set_written_to(cursor_addr); - circulation_seq = expected_seq; + paddr_t addr = convert_abs_addr_to_paddr( + cursor_addr, + header.device_id); + set_written_to( + journal_seq_t{expected_seq, addr}); return seastar::do_with( std::move(*maybe_record_deltas_list), [write_result, diff --git a/src/crimson/os/seastore/journal/circular_bounded_journal.h b/src/crimson/os/seastore/journal/circular_bounded_journal.h index 38d3d3d07acf6..09c28b1a2f79b 100644 --- a/src/crimson/os/seastore/journal/circular_bounded_journal.h +++ b/src/crimson/os/seastore/journal/circular_bounded_journal.h @@ -200,7 +200,7 @@ public: uint64_t size = 0; // max length of journal // start offset of CircularBoundedJournal in the device - rbm_abs_addr journal_tail = 0; + journal_seq_t journal_tail; device_id_t device_id; @@ -231,9 +231,12 @@ public: */ size_t get_used_size() const { - return get_written_to() >= get_journal_tail() ? - get_written_to() - get_journal_tail() : - get_written_to() + header.size + get_block_size() - get_journal_tail(); + auto rbm_written_to = get_rbm_addr(get_written_to()); + auto rbm_tail = get_rbm_addr(get_journal_tail()); + return rbm_written_to >= rbm_tail ? + rbm_written_to - rbm_tail : + rbm_written_to + header.size + get_block_size() + - rbm_tail; } size_t get_total_size() const { return header.size; @@ -245,11 +248,11 @@ public: return get_total_size() - get_used_size(); } - write_ertr::future<> update_journal_tail(rbm_abs_addr addr) { - header.journal_tail = addr; + write_ertr::future<> update_journal_tail(journal_seq_t seq) { + header.journal_tail = seq; return write_header(); } - rbm_abs_addr get_journal_tail() const { + journal_seq_t get_journal_tail() const { return header.journal_tail; } @@ -261,13 +264,17 @@ public: write_pipeline = _write_pipeline; } - rbm_abs_addr get_written_to() const { + journal_seq_t get_written_to() const { return written_to; } - void set_written_to(rbm_abs_addr addr) { + rbm_abs_addr get_rbm_addr(journal_seq_t seq) const { + return convert_paddr_to_abs_addr(seq.offset); + } + void set_written_to(journal_seq_t seq) { + rbm_abs_addr addr = convert_paddr_to_abs_addr(seq.offset); assert(addr >= get_start_addr()); assert(addr < get_journal_end()); - written_to = addr; + written_to = seq; } device_id_t get_device_id() const { return header.device_id; @@ -293,12 +300,11 @@ private: */ bool initialized = false; - // circulation seq to track the sequence to written records - segment_seq_t circulation_seq = NULL_SEG_SEQ; - // start address where the newest record will be written // should be in range [get_start_addr(), get_journal_end()) - rbm_abs_addr written_to = 0; + // written_to.segment_seq is circulation seq to track + // the sequence to written records + journal_seq_t written_to; }; std::ostream &operator<<(std::ostream &out, const CircularBoundedJournal::cbj_header_t &header); diff --git a/src/test/crimson/seastore/test_cbjournal.cc b/src/test/crimson/seastore/test_cbjournal.cc index dbcaf77855e39..808ae71f098e1 100644 --- a/src/test/crimson/seastore/test_cbjournal.cc +++ b/src/test/crimson/seastore/test_cbjournal.cc @@ -271,6 +271,9 @@ struct cbjournal_test_t : public seastar_test_suite_t, JournalTrimmer auto get_block_size() { return device->get_block_size(); } + auto get_written_to_rbm_addr() { + return cbj->get_rbm_addr(cbj->get_written_to()); + } auto get_written_to() { return cbj->get_written_to(); } @@ -281,10 +284,14 @@ struct cbjournal_test_t : public seastar_test_suite_t, JournalTrimmer return cbj->get_used_size(); } void update_journal_tail(rbm_abs_addr addr, uint32_t len) { - cbj->update_journal_tail(addr + len).unsafe_get0(); + cbj->update_journal_tail( + journal_seq_t{0, + convert_abs_addr_to_paddr( + addr + len, + cbj->get_device_id())}).unsafe_get0(); } - void set_written_to(rbm_abs_addr addr) { - cbj->set_written_to(addr); + void set_written_to(journal_seq_t seq) { + cbj->set_written_to(seq); } }; @@ -426,7 +433,7 @@ TEST_F(cbjournal_test_t, update_header) cbj->close().unsafe_get0(); replay(); - ASSERT_EQ(update_header.journal_tail, update_header.journal_tail); + ASSERT_EQ(update_header.journal_tail.offset, update_header.journal_tail.offset); ASSERT_EQ(header.block_size, update_header.block_size); ASSERT_EQ(header.size, update_header.size); }); @@ -489,7 +496,11 @@ TEST_F(cbjournal_test_t, replay_after_reset) } auto old_written_to = get_written_to(); auto old_used_size = get_used_size(); - set_written_to(4096); + set_written_to( + journal_seq_t{0, + convert_abs_addr_to_paddr( + 4096, + cbj->get_device_id())}); cbj->close().unsafe_get0(); replay(); ASSERT_EQ(old_written_to, get_written_to()); -- 2.39.5