]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/os/seastore/segment_cleaner: don't consider journal segments reclaimable
authorSamuel Just <sjust@redhat.com>
Tue, 23 Mar 2021 21:27:33 +0000 (14:27 -0700)
committerSamuel Just <sjust@redhat.com>
Wed, 24 Mar 2021 05:41:11 +0000 (22:41 -0700)
Otherwise, we might end up looping trying to gc based on the reclaimable
metric but be unable to actually find a reclaimable segment.  Mainly a
problem in unit tests that artificially force replay prior rolling the
first journal segment.

Signed-off-by: Samuel Just <sjust@redhat.com>
src/crimson/os/seastore/segment_cleaner.h
src/crimson/os/seastore/transaction_manager.cc

index 284867c4967d25f26b0f3ba702b392b5d160cd05..5ef9e8d4505fed01f96c6ca6ed460dc84995baf2 100644 (file)
@@ -388,12 +388,22 @@ public:
     journal_tail_target = journal_tail_committed = tail;
   }
 
+  void init_mkfs(journal_seq_t head) {
+    journal_tail_target = head;
+    journal_tail_committed = head;
+    journal_head = head;
+  }
+
   void set_journal_head(journal_seq_t head) {
     assert(journal_head == journal_seq_t() || head >= journal_head);
     journal_head = head;
     gc_process.maybe_wake_on_space_used();
   }
 
+  journal_seq_t get_journal_head() const {
+    return journal_head;
+  }
+
   void init_mark_segment_closed(segment_id_t segment, segment_seq_t seq) final {
     crimson::get_logger(ceph_subsys_filestore).debug(
       "SegmentCleaner::init_mark_segment_closed: segment {}, seq {}",
@@ -623,7 +633,6 @@ private:
   gc_reclaim_space_ret gc_reclaim_space();
 
   size_t get_bytes_used_current_segment() const {
-    assert(journal_head != journal_seq_t());
     return journal_head.offset.offset;
   }
 
@@ -663,9 +672,25 @@ private:
     return used_bytes;
   }
 
-  /// Returns the number of bytes in unavailable segments that are not live
+  /// Return bytes contained in segments in journal
+  size_t get_journal_segment_bytes() const {
+    assert(journal_head >= journal_tail_committed);
+    return (journal_head.segment_seq - journal_tail_committed.segment_seq + 1) *
+      config.segment_size;
+  }
+
+  /**
+   * get_reclaimable_bytes
+   *
+   * Returns the number of bytes in unavailable segments that can be
+   * reclaimed.
+   */
   size_t get_reclaimable_bytes() const {
-    return get_unavailable_bytes() - get_used_bytes();
+    auto ret = get_unavailable_bytes() - get_used_bytes();
+    if (ret > get_journal_segment_bytes())
+      return ret - get_journal_segment_bytes();
+    else
+      return 0;
   }
 
   /**
index 62abb76efcc7af97eb74b69bd88590476bc8f004..b0faea77583dc3aa302784186a59e47635169433 100644 (file)
@@ -38,7 +38,7 @@ TransactionManager::mkfs_ertr::future<> TransactionManager::mkfs()
 {
   return journal->open_for_write().safe_then([this](auto addr) {
     logger().debug("TransactionManager::mkfs: about to do_with");
-    segment_cleaner->set_journal_head(addr);
+    segment_cleaner->init_mkfs(addr);
     return seastar::do_with(
       create_transaction(),
       [this](auto &transaction) {