From: Yingxin Cheng Date: Thu, 17 Mar 2022 08:32:12 +0000 (+0800) Subject: crimson/os/seastore/journal/segment_allocator: introduce open() and close() to Record... X-Git-Tag: v18.0.0~1193^2~2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=f09c23749dd69a8819351ae9ebc82f17391115fe;p=ceph.git crimson/os/seastore/journal/segment_allocator: introduce open() and close() to RecordSubmitter Signed-off-by: Yingxin Cheng --- diff --git a/src/crimson/os/seastore/extent_placement_manager.cc b/src/crimson/os/seastore/extent_placement_manager.cc index 660e8d554f4c3..538d8cd9929d2 100644 --- a/src/crimson/os/seastore/extent_placement_manager.cc +++ b/src/crimson/os/seastore/extent_placement_manager.cc @@ -34,12 +34,6 @@ SegmentedAllocator::Writer::Writer( { } -SegmentedAllocator::Writer::open_ertr::future<> -SegmentedAllocator::Writer::open() -{ - return segment_allocator.open().discard_result(); -} - SegmentedAllocator::Writer::write_ertr::future<> SegmentedAllocator::Writer::write_record( Transaction& t, diff --git a/src/crimson/os/seastore/extent_placement_manager.h b/src/crimson/os/seastore/extent_placement_manager.h index 9272e31caedfe..34368aca7d850 100644 --- a/src/crimson/os/seastore/extent_placement_manager.h +++ b/src/crimson/os/seastore/extent_placement_manager.h @@ -78,7 +78,9 @@ class SegmentedAllocator : public ExtentAllocator { Writer(std::string name, SegmentProvider& sp, SegmentManager& sm); Writer(Writer &&) = default; - open_ertr::future<> open() final; + open_ertr::future<> open() final { + return record_submitter.open().discard_result(); + } write_iertr::future<> write( Transaction& t, @@ -86,7 +88,7 @@ class SegmentedAllocator : public ExtentAllocator { stop_ertr::future<> stop() final { return write_guard.close().then([this] { - return segment_allocator.close(); + return record_submitter.close(); }).safe_then([this] { write_guard = seastar::gate(); }); diff --git a/src/crimson/os/seastore/journal/segment_allocator.cc b/src/crimson/os/seastore/journal/segment_allocator.cc index cf932e554cda4..99b51752cdfb9 100644 --- a/src/crimson/os/seastore/journal/segment_allocator.cc +++ b/src/crimson/os/seastore/journal/segment_allocator.cc @@ -38,14 +38,11 @@ void SegmentAllocator::set_next_segment_seq(segment_seq_t seq) next_segment_seq = seq; } -SegmentAllocator::open_ertr::future -SegmentAllocator::open() +SegmentAllocator::open_ret +SegmentAllocator::do_open() { - LOG_PREFIX(SegmentAllocator::open); + LOG_PREFIX(SegmentAllocator::do_open); ceph_assert(!current_segment); - std::ostringstream oss; - oss << "D" << device_id_printer_t{get_device_id()} << "_" << name; - print_name = oss.str(); segment_seq_t new_segment_seq = get_new_segment_seq_and_increment(); auto new_segment_id = segment_provider.get_segment( get_device_id(), new_segment_seq); @@ -53,7 +50,7 @@ SegmentAllocator::open() ).handle_error( open_ertr::pass_further{}, crimson::ct_error::assert_all{ - "Invalid error in SegmentAllocator::open open" + "Invalid error in SegmentAllocator::do_open open" } ).safe_then([this, FNAME, new_segment_seq](auto sref) { // initialize new segment @@ -97,7 +94,7 @@ SegmentAllocator::open() ).handle_error( open_ertr::pass_further{}, crimson::ct_error::assert_all{ - "Invalid error in SegmentAllocator::open write" + "Invalid error in SegmentAllocator::do_open write" } ).safe_then([this, FNAME, @@ -117,12 +114,23 @@ SegmentAllocator::open() }); } +SegmentAllocator::open_ret +SegmentAllocator::open() +{ + LOG_PREFIX(SegmentAllocator::open); + std::ostringstream oss; + oss << "D" << device_id_printer_t{get_device_id()} << "_" << name; + print_name = oss.str(); + INFO("{}", print_name); + return do_open(); +} + SegmentAllocator::roll_ertr::future<> SegmentAllocator::roll() { ceph_assert(can_write()); return close_segment(true).safe_then([this] { - return open().discard_result(); + return do_open().discard_result(); }); } @@ -173,6 +181,7 @@ SegmentAllocator::close() return [this] { LOG_PREFIX(SegmentAllocator::close); if (current_segment) { + INFO("{} close current segment", print_name); return close_segment(false); } else { INFO("{} no current segment", print_name); @@ -570,6 +579,26 @@ RecordSubmitter::submit(record_t&& record) return write_fut; } +RecordSubmitter::open_ret +RecordSubmitter::open() +{ + return segment_allocator.open(); +} + +RecordSubmitter::close_ertr::future<> +RecordSubmitter::close() +{ + assert(state == state_t::IDLE); + assert(num_outstanding_io == 0); + committed_to = JOURNAL_SEQ_NULL; + assert(p_current_batch != nullptr); + assert(p_current_batch->is_empty()); + assert(!wait_available_promise.has_value()); + has_io_error = false; + assert(!wait_unfull_flush_promise.has_value()); + return segment_allocator.close(); +} + void RecordSubmitter::update_state() { if (num_outstanding_io == 0) { diff --git a/src/crimson/os/seastore/journal/segment_allocator.h b/src/crimson/os/seastore/journal/segment_allocator.h index c96ebbf444358..c2ad13aa97022 100644 --- a/src/crimson/os/seastore/journal/segment_allocator.h +++ b/src/crimson/os/seastore/journal/segment_allocator.h @@ -84,7 +84,7 @@ class SegmentAllocator { return length + written_to > std::size_t(write_capacity); } - // open for write + // open for write and generate the correct print name using open_ertr = base_ertr; using open_ret = open_ertr::future; open_ret open(); @@ -105,6 +105,8 @@ class SegmentAllocator { close_ertr::future<> close(); private: + open_ret do_open(); + void reset() { current_segment.reset(); written_to = 0; @@ -425,6 +427,14 @@ public: committed_to = new_committed_to; } + // open for write, generate the correct print name, and register metrics + using open_ertr = base_ertr; + using open_ret = open_ertr::future; + open_ret open(); + + using close_ertr = base_ertr; + close_ertr::future<> close(); + private: void update_state(); diff --git a/src/crimson/os/seastore/journal/segmented_journal.cc b/src/crimson/os/seastore/journal/segmented_journal.cc index 175193e886762..ce76d14c22f1a 100644 --- a/src/crimson/os/seastore/journal/segmented_journal.cc +++ b/src/crimson/os/seastore/journal/segmented_journal.cc @@ -51,9 +51,7 @@ SegmentedJournal::SegmentedJournal( SegmentedJournal::open_for_write_ret SegmentedJournal::open_for_write() { - LOG_PREFIX(Journal::open_for_write); - INFO("device_id={}", journal_segment_allocator.get_device_id()); - return journal_segment_allocator.open(); + return record_submitter.open(); } SegmentedJournal::close_ertr::future<> SegmentedJournal::close() @@ -62,7 +60,7 @@ SegmentedJournal::close_ertr::future<> SegmentedJournal::close() INFO("closing, committed_to={}", record_submitter.get_committed_to()); metrics.clear(); - return journal_segment_allocator.close(); + return record_submitter.close(); } SegmentedJournal::prep_replay_segments_fut