]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/os/seastore/journal/segment_allocator: introduce open() and close() to Record...
authorYingxin Cheng <yingxin.cheng@intel.com>
Thu, 17 Mar 2022 08:32:12 +0000 (16:32 +0800)
committerYingxin Cheng <yingxin.cheng@intel.com>
Fri, 18 Mar 2022 06:13:46 +0000 (14:13 +0800)
Signed-off-by: Yingxin Cheng <yingxin.cheng@intel.com>
src/crimson/os/seastore/extent_placement_manager.cc
src/crimson/os/seastore/extent_placement_manager.h
src/crimson/os/seastore/journal/segment_allocator.cc
src/crimson/os/seastore/journal/segment_allocator.h
src/crimson/os/seastore/journal/segmented_journal.cc

index 660e8d554f4c32c53f6364c15abd93657fbb30ad..538d8cd9929d281a61386d5b7eb64f09b97757de 100644 (file)
@@ -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,
index 9272e31caedfe53f17b84930cd860db84f51177b..34368aca7d85030e2d386480456af5c97de9f169 100644 (file)
@@ -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();
       });
index cf932e554cda42b37f02c7a7265047448f4344c3..99b51752cdfb9df20622db3233d343c61b095f6f 100644 (file)
@@ -38,14 +38,11 @@ void SegmentAllocator::set_next_segment_seq(segment_seq_t seq)
   next_segment_seq = seq;
 }
 
-SegmentAllocator::open_ertr::future<journal_seq_t>
-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) {
index c96ebbf4443589905967402e6a38fde88cf586b3..c2ad13aa97022e642b2d31efc614f347a4bf4859 100644 (file)
@@ -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<journal_seq_t>;
   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<journal_seq_t>;
+  open_ret open();
+
+  using close_ertr = base_ertr;
+  close_ertr::future<> close();
+
 private:
   void update_state();
 
index 175193e886762933015f188a0a2c0e680d1c9432..ce76d14c22f1abfb418f00afe99d22860aa8da0d 100644 (file)
@@ -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