]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/os/seastore: refactor get_encoded_length_after()
authorYingxin Cheng <yingxin.cheng@intel.com>
Mon, 29 Nov 2021 02:11:09 +0000 (10:11 +0800)
committerYingxin Cheng <yingxin.cheng@intel.com>
Thu, 9 Dec 2021 03:28:49 +0000 (11:28 +0800)
To return a more informative record_group_size_t.

Signed-off-by: Yingxin Cheng <yingxin.cheng@intel.com>
src/crimson/os/seastore/journal.cc
src/crimson/os/seastore/journal.h
src/crimson/os/seastore/seastore_types.h

index a6cb8ce1a7d6bdb138776768068ba09b9c0c364c..2fe3b33997667c70e72f9d1f6c00e4102253ad87 100644 (file)
@@ -437,18 +437,18 @@ Journal::RecordBatch::add_pending(
   record_t&& record,
   extent_len_t block_size)
 {
-  auto new_encoded_length = get_encoded_length_after(record, block_size);
+  auto new_size = get_encoded_length_after(record, block_size);
   logger().debug(
     "Journal::RecordBatch::add_pending: batches={}, write_size={}",
     pending.get_size() + 1,
-    new_encoded_length);
+    new_size.get_encoded_length());
   assert(state != state_t::SUBMITTING);
-  assert(can_batch(record, block_size) == new_encoded_length);
+  assert(can_batch(record, block_size).value() == new_size);
 
   auto dlength_offset = pending.current_dlength;
   pending.push_back(
       std::move(record), block_size);
-  assert(pending.size.get_encoded_length() == new_encoded_length);
+  assert(pending.size == new_size);
   if (state == state_t::EMPTY) {
     assert(!io_promise.has_value());
     io_promise = seastar::shared_promise<maybe_promise_result_t>();
@@ -537,17 +537,17 @@ Journal::RecordBatch::submit_pending_fast(
   const journal_seq_t& committed_to,
   segment_nonce_t segment_nonce)
 {
-  auto encoded_length = get_encoded_length_after(record, block_size);
+  auto new_size = get_encoded_length_after(record, block_size);
   logger().debug(
     "Journal::RecordBatch::submit_pending_fast: write_size={}",
-    encoded_length);
+    new_size.get_encoded_length());
   assert(state == state_t::EMPTY);
-  assert(can_batch(record, block_size) == encoded_length);
+  assert(can_batch(record, block_size).value() == new_size);
 
   auto group = record_group_t(std::move(record), block_size);
   auto size = group.size;
+  assert(size == new_size);
   auto bl = encode_records(group, committed_to, segment_nonce);
-  assert(bl.length() == encoded_length);
   assert(bl.length() == size.get_encoded_length());
   return std::make_pair(bl, size);
 }
@@ -727,14 +727,16 @@ Journal::RecordSubmitter::do_submit(
   if (state <= state_t::PENDING) {
     // can increment io depth
     assert(!wait_submit_promise.has_value());
-    auto batched_size = p_current_batch->can_batch(
+    auto maybe_new_size = p_current_batch->can_batch(
         record, journal_segment_manager.get_block_size());
-    if (batched_size == 0 ||
-        batched_size > journal_segment_manager.get_max_write_length()) {
+    if (!maybe_new_size.has_value() ||
+        (maybe_new_size->get_encoded_length() >
+         journal_segment_manager.get_max_write_length())) {
       assert(p_current_batch->is_pending());
       flush_current_batch();
       return do_submit(std::move(record), handle);
-    } else if (journal_segment_manager.needs_roll(batched_size)) {
+    } else if (journal_segment_manager.needs_roll(
+          maybe_new_size->get_encoded_length())) {
       if (p_current_batch->is_pending()) {
         flush_current_batch();
       }
@@ -749,11 +751,13 @@ Journal::RecordSubmitter::do_submit(
 
   assert(state == state_t::FULL);
   // cannot increment io depth
-  auto batched_size = p_current_batch->can_batch(
+  auto maybe_new_size = p_current_batch->can_batch(
       record, journal_segment_manager.get_block_size());
-  if (batched_size == 0 ||
-      batched_size > journal_segment_manager.get_max_write_length() ||
-      journal_segment_manager.needs_roll(batched_size)) {
+  if (!maybe_new_size.has_value() ||
+      (maybe_new_size->get_encoded_length() >
+       journal_segment_manager.get_max_write_length()) ||
+      journal_segment_manager.needs_roll(
+        maybe_new_size->get_encoded_length())) {
     if (!wait_submit_promise.has_value()) {
       wait_submit_promise = seastar::promise<>();
     }
index 2d2e54533e75e0c950561ad554e54acb4b285579..232455741ed165014f541a2844dc59517f232d46 100644 (file)
@@ -253,9 +253,9 @@ private:
       return pending.get_size();
     }
 
-    // return the expected write size if allows to batch,
-    // otherwise, return 0
-    std::size_t can_batch(
+    // return the expected write sizes if allows to batch,
+    // otherwise, return nullopt
+    std::optional<record_group_size_t> can_batch(
         const record_t& record,
         extent_len_t block_size) const {
       assert(state != state_t::SUBMITTING);
@@ -263,7 +263,7 @@ private:
           (pending.get_size() > 0 &&
            pending.size.get_encoded_length() > batch_flush_size)) {
         assert(state == state_t::PENDING);
-        return 0;
+        return std::nullopt;
       }
       return get_encoded_length_after(record, block_size);
     }
@@ -312,7 +312,7 @@ private:
         segment_nonce_t segment_nonce);
 
   private:
-    std::size_t get_encoded_length_after(
+    record_group_size_t get_encoded_length_after(
         const record_t& record,
         extent_len_t block_size) const {
       return pending.size.get_encoded_length_after(
index 3769d2bbf2b75b391061d0ca66431b48bcca7bf2..6e009e9b361c833921ec2945225e52cddd8586fc 100644 (file)
@@ -1211,6 +1211,7 @@ struct record_size_t {
 
   void account(const delta_info_t& delta);
 };
+WRITE_EQ_OPERATORS_2(record_size_t, plain_mdlength, dlength);
 
 struct record_t {
   std::vector<extent_t> extents;
@@ -1314,17 +1315,18 @@ struct record_group_size_t {
     return get_mdlength() + dlength;
   }
 
-  extent_len_t get_encoded_length_after(
+  record_group_size_t get_encoded_length_after(
       const record_size_t& rsize,
       extent_len_t block_size) const {
     record_group_size_t tmp = *this;
     tmp.account(rsize, block_size);
-    return tmp.get_encoded_length();
+    return tmp;
   }
 
   void account(const record_size_t& rsize,
                extent_len_t block_size);
 };
+WRITE_EQ_OPERATORS_3(record_group_size_t, plain_mdlength, dlength, block_size);
 
 struct record_group_t {
   std::vector<record_t> records;