From: Yingxin Cheng Date: Mon, 29 Nov 2021 02:11:09 +0000 (+0800) Subject: crimson/os/seastore: refactor get_encoded_length_after() X-Git-Tag: v17.1.0~268^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=a689a0ff4c6e185472e9f9f4228818c994b2f890;p=ceph.git crimson/os/seastore: refactor get_encoded_length_after() To return a more informative record_group_size_t. Signed-off-by: Yingxin Cheng --- diff --git a/src/crimson/os/seastore/journal.cc b/src/crimson/os/seastore/journal.cc index a6cb8ce1a7d6b..2fe3b33997667 100644 --- a/src/crimson/os/seastore/journal.cc +++ b/src/crimson/os/seastore/journal.cc @@ -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(); @@ -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<>(); } diff --git a/src/crimson/os/seastore/journal.h b/src/crimson/os/seastore/journal.h index 2d2e54533e75e..232455741ed16 100644 --- a/src/crimson/os/seastore/journal.h +++ b/src/crimson/os/seastore/journal.h @@ -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 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( diff --git a/src/crimson/os/seastore/seastore_types.h b/src/crimson/os/seastore/seastore_types.h index 3769d2bbf2b75..6e009e9b361c8 100644 --- a/src/crimson/os/seastore/seastore_types.h +++ b/src/crimson/os/seastore/seastore_types.h @@ -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 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 records;