Skip to content

crimson/os/seastore: export the iterator of FixedKVBtree to TransactionManager - #60814

Closed
zhscn wants to merge 13 commits into
ceph:mainfrom
zhscn:wip-btree-iter
Closed

zhscn wants to merge 13 commits into
ceph:mainfrom
zhscn:wip-btree-iter

Conversation

@zhscn

@zhscn zhscn commented Nov 25, 2024 •

Copy link
Copy Markdown
Member

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands
  • jenkins retest this please
  • jenkins test classic perf
  • jenkins test crimson perf
  • jenkins test signed
  • jenkins test make check
  • jenkins test make check arm64
  • jenkins test submodules
  • jenkins test dashboard
  • jenkins test dashboard cephadm
  • jenkins test api
  • jenkins test docs
  • jenkins render docs
  • jenkins test ceph-volume all
  • jenkins test ceph-volume tox
  • jenkins test windows
  • jenkins test rook e2e

@zhscn zhscn changed the title crimson/os/seatore: export the iterator of FixedKVBtree to TransactionManager crimson/os/seastore: export the iterator of FixedKVBtree to TransactionManager Nov 25, 2024
@zhscn

zhscn commented Nov 25, 2024

Copy link
Copy Markdown
Member Author

@cyx1231st

@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@zhscn

zhscn commented Dec 27, 2024 •

Copy link
Copy Markdown
Member Author

The new iterator based interfaces for LBAManager and the clone/rollback strategy of onode have finished basically, I think it's necessary to write a summary about the changes and new features in this PR to reach a consensus with community before investing more effort in fixing bugs and adding unit tests.

  1. The new iterator ErasedBtreeIter is a wrapper of FixedKVBtree::iterator, so it provides additional capabilities to operate the LBA/Backref btree compared to LBAMapping, we can change the value of a mapping directly without having to search for it from root. Unlike PhysicalNodeMapping, the ErasedBtreeIter doesn't contains the information about the target LogicalCachedExtent, such as intermediate_key or something else. Here's the definition of ErasedBtreeIter:
template <typename Key, typename Val>
struct ErasedBtreeIter {
  CachedExtent *parent;
  uint16_t pos;
  Key key;
  Val val;
  btree_iter_version_t ver;
};

using LBAIter = ErasedBtreeIter<laddr_t, lba_map_val_t>;
using BackrefIter = ErasedBtreeIter<paddr_t, backref_map_val_t>;
  1. The invalidation rule of ErasedBtreeIter: the iterator becomes invalid when its parent is not viewable(CachedExtent::is_viewable_by_trans()) by current transaction. The btree_iter_version_t field in ErasedBtreeIter records the version number of btree when it was created. This version is transaction-local and all insert and remove operations increment this version. The LBAManager and FixedKVBtree are responsible for making sure the iterator is valid.
  • When the parent is valid but unviewable by current transaction, we could use FixedKVNode::find_pending_version() to find the latest pending extent.
  • When the parent is invalid, start a new lookup to rebuild the iterator.
  1. Since ErasedBtreeIter only stores the leaf node, when we use it to get the next/prev iterator, we need to retrieve the required internal node by traversing the btree from the parent of leaf node extent, see FixedKVBtree::ensure_internal() in commit "crimson/os/seastore/FixedKVBtree: introduce partial iterator".

  2. RemappedExtentPlaceholder: we can use ErasedBtreeIter to implement the "move_mapping" feature described at crimson/os/seastore: introduce static layout of laddr_t #59476 (comment) . However, due to the missing extent type in the LBA B-tree, we don’t know the real extent type of the moved mappings. RemappedExtentPlaceholder is introduced to solve this issue, which works like EXIST_CLEAN extents. The extents at original position are retired, and the new placehold extents are linked to lba leaf node.

    When updating backref btree, tracks all removed mappings' extent type and restore it when reaching RemappedExtentPlaceholder extents, see the changes of async_cleaner.cc in commit "crimson/os/seastore: export the iterator of FixedKVBtree to TransactionManager"

  3. The RemappedExtentPlaceholder is linked to lba leaf extent, if the rest ops of current transaction need to read this extent, the concrete extent is built to replace the placeholder. These placeholders are not added to the cache, so they should be unlinked from the lba leaf node after the leaf has finished replacing the previous instance.

  4. The "pin head" feature from crimson/os/seastore: introduce static layout of laddr_t #59476 (comment) is implemented in commit "crimson/os/seastore: introduce new clone/rollback procedure"

@zhscn
zhscn marked this pull request as ready for review December 30, 2024 10:19
@zhscn
zhscn requested a review from a team as a code owner December 30, 2024 10:19
@zhscn

zhscn commented Jan 6, 2025

Copy link
Copy Markdown
Member Author

Changes:

  1. pass LBAIter to LBAManager by reference;
  2. only reserve region once when doing clone onode. Ideally, it only needs to search the LBA tree twice to finish the clone operation.
  3. use LBAIter in LBAManager::update_mappings

@cyx1231st cyx1231st left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still trying to understand new interfaces in lba_manager.h, I hope this is a reasonable angle to begin with.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the meaning of "Erased" under the context of "BtreeIter" ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is "erased" from the full signature FixedKVBtree<node_key_t, node_val_t, internal_node_t, leaf_node_t, pin_t, node_size, leaf_has_children>::iterator, and we cannot use it in the interface of TransactionManager.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A similar suggestion to #60814 (comment), seems to me the fields&responsibilities in BtreeNodeMapping (i.e. the part of parent/value/len/range/pos) is identical to this ErasedBtreeIter (parent/val/len/key/pos(/ver)).

Looks they both represents a raw btree mapping regardless of lba indirections. Is it reasonable to, probably:

  • Rename ErasedBtreeIter to BtreeValueIterator.
  • Make BtreeNodeMapping to own a BtreeValueIterator internally.

?

In another word, is it reasonable to (start to) leverage BtreeValueIterator to encapsulate/reuse btree mapping logics that are unrelated to lba indirections?

@zhscn zhscn Jan 7, 2025 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The BtreeNodeMapping includes 3 parts for now:

  1. The information from FixedKVBtree, which includes fields parent value range and pos. These fields are very similar to BtreeValueIterator. The difference is that the value type of BtreeNodeMapping is laddr_t or paddr_t and the introduced BtreeValueIterator uses the complete type lba_map_val_t and backref_map_val_t.
  2. The indirect properties of LBAMapping, which is handled by lba_map_val_t::pladdr_t internally in LBAManager. The problem here is that BtreeNodeMapping only contains one parent has direct mapping, which makes inconvenient when updating the original indirect mapping. The refactored BtreeNodeMapping should contains two iterators: BtreeValueIterator direct_iter, indirect_iter;
  3. The handler of linked child logical extent: PhysicalNodeMapping::get_logical_extent() and BtreeNodeMapping::ctx, seems it's better to move this part to TransactionManager completely. The BtreeNodeMapping should not have futurized methods.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, the TransactionManager interface should accept BtreeNodeMapping, while the LBAManager interface should accept BtreeValueIterator.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I feel the similar way. Let's see how to adjust towards this direction. (Probably cannot be completed in this PR).

uint16_t pos;
Key key;
Val val;
btree_iter_version_t ver;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The btree_iter_version_t field in ErasedBtreeIter records the version number of btree when it was created. This version is transaction-local and all insert and remove operations increment this version. The LBAManager and FixedKVBtree are responsible for making sure the iterator is valid.

Can you further elaborate why this is needed (how things won't work without this version)?

Seems it is tree-level modification version, which means any modifications to the entire tree especially in unrelated subtree can cause version mismatch (although it is transaction-local), which doesn't sound very reasonable to me.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the original design, the validity of the iterator (both parent and pos) was checked by the version. Now, the validity of parent is handled by CachedExtent::is_viewable_by_trans(), and the version is only used to check if pos is valid.

Similar to the iterator invalidation behavior of std::vector, inserting a mapping at the beginning of a vector or extent will invalidate all existing iterators, requiring a re-search for the required mapping. See BtreeLBAManager::make_btree_iter and FixedKVBtree::make_partial_iter.

Using an extent-local version would be preferable over a transaction-local version, but given that complex usage involving multiple iterators does not exist at this point, a transaction-local version might be sufficient for now.


As suggested by @xxhdx1985126 , it could be replaced by FixedKVLeafNode::modifications.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As suggested by @xxhdx1985126, it could be replaced by FixedKVLeafNode::modifications.

I prefer to reuse the same strategy for the same goal, detecting the validity of a mapping or an iterator seems mostly identical (correct me if wrong). This isn't a simple consideration, introducing yet another different solution is challenging to maintain.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also see #60814 (comment), in a larger sense, probably "detecting the validity of a mapping or an iterator" is fully reusable under the concept of BtreeValueIterator (if it is owned by BtreeNodeMapping), what do you think?

@zhscn

zhscn commented Jan 7, 2025 •

Copy link
Copy Markdown
Member Author

This PR will be split into two parts in next push, it only contains BtreeValueIterator and changes about BtreeNodeMapping, the rest changes about accelerating clone procedure will be moved to a new PR.

*/
using make_iterator_iertr = base_iertr;
using make_iterator_ret = make_iterator_iertr::future<LBAIter>;
virtual make_iterator_ret make_iterator(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it always return an iterator with paddr value (i.e. a direct iterator) ?

If so, should it be named as make_direct_iterator() like below ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it always returns the direct iterator.

Comment thread src/crimson/os/seastore/lba_manager.h Resolved
/**
* refresh_iterator
*
* Ensures the iterator is valid. It's possible to start a new search internally.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth to elaborate the comments about why/how an iterator can become invalid, so an user understands when this interface should be used.

@zhscn zhscn Jan 7, 2025 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All iterators might become invalid after modifying values in lba btree. Only the iterator returned by the mutate operation of LBAManager are guaranteed to be up-to-date.

For example, a user might hold two iterators whose parent is same and stable. If a new mapping is inserted into the btree using one of these iterators, the insertion will invoke LBALeafNode::duplicate_for_write() to create a new pending extent. As a result, the parent of the original two iterators will no longer be visible to the transaction so that the iterators will become invalid. In this case, refresh_iterator() is requried to reuse the existing iterator, the implementation will use FixedKVNode::find_pending_version() to get latest pending extent and avoid searching from lba btree root.

When the parent of an existing iterator is pending, it will become invalid if the next insertion cause a leaf split. In this case, refresh_iterator() will rebuild the iterator by searching for the mapping from scratch. 1

It's not easy to summarize the precise rules for determining when to check the validity of iterator, so the simplest approach is always refresh the iterator when it is suspected to be outdated. The user provided iterator is refreshed atomically in other APIs' implementations, see BtreeLBAManager::make_btree_iter() and its references.

Footnotes

  1. If we were allowed to store the modification history of FixedKVNode in invalid extents, we could eliminate this lookup. However, keeping meaningful information in invalid extents doesn’t seem like a good idea. ↩

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be sufficient to help user to understand when this interface should be used. How about adding this into the comment?

User is allowed to hold the iterator and use it later. But if the tree can be modified in the middle,
user must refresh the iterator to make sure it keeps valid. Note this is usually more efficient
than finding the iterator from the tree again.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable.

The user provided iterator is refreshed atomically in other APIs' implementations

What do you think about this behavior, refresh it atomically or only assert the iterator is valid?

@cyx1231st cyx1231st Jan 8, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about this behavior, refresh it atomically or only assert the iterator is valid?

IIUC it was automatic because the refresh case was not pervasive previously. With this PR, probably we can be consistent to require user to refresh rather than the automatic way.

* Search for a free region which can hold the specified length
* of lba mappings.
* Returns the starting laddr of the found region and an iterator
* that can be used to insert mappings.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the returned iterator contain a valid lba tree value, or it is a "free" iterator without lba tree value?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The iterator should always contain a valid lba tree value unless it's the at end of lba btree.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. IIUC, how about: "... and an iterator to the right that can be ..."
  2. Can find_region_result_t.laddr be L_ADDR_NULL (I see there is a constructor)?
  3. Let's drop the constructors of find_region_result_t because it is only used to group together return named values.
  4. Why is find_region_result_t() needed? As a return value, it should always be valid, right?

@zhscn zhscn Jan 8, 2025 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. IIUC, how about: "... and an iterator to the right that can be ..."

Yeah.

  1. Can find_region_result_t.laddr be L_ADDR_NULL (I see there is a constructor)?

No, it returns non-null laddr.

  1. Let's drop the constructors of find_region_result_t because it is only used to group together return named values.
  2. Why is find_region_result_t() needed? As a return value, it should always be valid, right?

It's required by with_btree_ret<LBABtree, find_region_result_t>().

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, how about keeping the struct simple as POD (plain old data) :

struct find_region_result_t {
  laddr_t start_laddr = L_ADDR_NULL; // Must be valid upon returning
  LBAIter insert_iter;
};

using get_iterator_ret = get_mapping_iertr::future<LBAIter>;
virtual get_iterator_ret get_iterator(
Transaction &t,
laddr_t laddr) = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep virtual methods of LBAManager as minimum as possible:

Seems the implementation can be based on lower_bound() above (i.e. no need to be a virtual method).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update in next push.

virtual get_iterators_ret get_iterators(
Transaction &t,
laddr_t laddr,
extent_len_t length) = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is get_iterators() necessary as a virtual interface of LBAManager? Seems it can always be replaced by existing next_iterator() or prev_iterator() etc. with an iterative loop.

Also, the comment "retrieves the iterators in range [laddr, laddr + length)" looks vague about the corner cases, for example:

  • Whether a valid mapping [A, lenA) will be included, when A < laddr && A+lenA >= laddr
  • etc.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update in next push.

const LBAIter &iter,
laddr_t laddr,
lba_map_val_t value,
LogicalCachedExtent *nextent) = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the invarient of *nextent be defined?

E.g. when it should be nullptr and when shouldn't. How the fields should match the preceding parameters for correctness.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. If laddr is direct, the nextent should be not null;
  2. If laddr is indirect, the nextent should be reserved ptr

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's clarify this in the method comments.

* change_mapping
*
* Change the mapping at the provided LBAIter to the new key value pair.
* nextent should be reserved ptr if the original extent is retired.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"nextent should be reserved ptr if the original extent is retired"

I'm not fully following this part yet, is it related to RemappedExtentPlaceholder ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change_mapping has some use cases:

  1. update_mapping, update the paddr of lba mapping in normal IO path;
  2. remap lba mapping
    a. change the length of lba mapping
    b. change the lba maping to its sub-mapping
  3. make lba mapping indirect. the original lba mapping is direct and change the pladdr to laddr. It is used by "pin head" feature.

Seems we should divide it into

  1. update_paddr, accepting not null nextent;
  2. remap_mapping, accepting not null nextent;
  3. make_indirect, not requiring nextent parameter;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Sounds better than the original one.

* remove_mapping
*
* Remove the lba mapping at the provided LBAIter.
* Return the iterator of mapping at the removed position.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the returned iterator contain a valid lba tree value, or it is a "free" iterator without lba tree value?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's similar to #60814 (comment)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly: "... Return the iterator to the right ..."

const LBAIter &iter,
laddr_t laddr,
lba_map_val_t value,
LogicalCachedExtent *nextent) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have pratical suggestions yet.

I understand that the iterative interfaces to operate mappings are essential for performance reasons, but I feel the current way exposes&couples the details of SeaStore physical layer beyound the TransactionManager level (i.e. to the logical layer which is above TM, mostly ObjectDataHandler), for example:

  • Physical addresses, lba_map_val_t
  • Low-level details of clone implementations (refcount management, lba indirection details)
  • How logical extent should be linked in the lba tree (An optimization to Cache and LBA tree which works below TM)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might not be easy to isolate these information strictly. If we put these details into TransactionManager and restrict the ObjectDataHandler to only access non-iterative BtreeNodeMapping interface, we would face the issue of multiple iterators existing simultaneously (as described in this discussion), making iterator invalidation a common occurrence.

I will try to make BtreeNodeMapping more reasonable and readable.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can avoid exposing the extent pointer to outside LBAManager by splitting these pointer-accepting interfaces into ones that MUST accept extents and ones that doesn't not. And interfaces that accept extents accept them by reference, instead of extent pointers, just like the current LBAManager::alloc_extents() and LBAManager::reserve_region() both of which alloc lba mappings while the former accept an extent reference and the latter doesn't. @cyx1231st What do you think?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think named and strict interfaces are always better than one multi-functional interface which cannot be understood easily thus error-prone.

@zhscn zhscn Jan 9, 2025 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a simple approach to reduce the cost of iterator rebuild: given that the lba mappings held by ObjectDataHandler are always contiguous in the lba btree and the mutate operation returns an up-to-date iterator, we could assume the returned iterator is close to the invalid one, which allows us to introduce a std::map::emplace_hint like interface:

make_iter_ret refresh_iterator_hint(BtreeValueIterator hint_iter, BtreeValueIterator old_iter);

With hint, we can search for the required iterator from leaf to root in the btree, which is more efficient than searching from the root.

For clone related operations in ObjectDataHandler, the mappings might span multiple onode. However, the locality of lba mappings still exists, making the hint-based approach feasible.

Consider the worst-case scenario:

An onode contains 16MiB of data, with each extent is 4KiB long, the count of extents is 4096. The fan-out of LBALeafNode is 110, the lba mappings of this onode will span approximately 4096/110=38 leaf nodes. When a valid hint is available, we only need to search the parent of relevant leaf node to locate the requried lba mapping within the same onode, which is more efficient than searching from the root.

A 5-level btree could index TiB of data, and when searching for a mapping using hints from the same onode, the process will traverse at most two levels of btree nodes.

A 3-level btree could index GiB of data that is efficient to search different clones of an object.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhscn Sounds reasonable to me.

Let's make this a separate commit (or even a PR if needs efforts) after making the existing approach reusable (#60814 (comment)) in this PR.

BTW, I suppose the following code might be able to be (mostly) encapsulated in pin/interator during the refactoring:

if (!pin->is_parent_viewable()) {
if (pin->is_parent_valid()) {
pin = pin->refresh_with_pending_parent();
fut = base_iertr::make_ready_future<LBAMappingRef>(std::move(pin));
} else {
fut = get_pin(t, pin->get_key()
).handle_error_interruptible(
crimson::ct_error::enoent::assert_failure{"unexpected enoent"},
crimson::ct_error::input_output_error::pass_further{}
);
}
} else {
pin->maybe_fix_pos();
fut = base_iertr::make_ready_future<LBAMappingRef>(std::move(pin));
}

if (!pin->is_parent_viewable()) {
if (pin->is_parent_valid()) {
pin = pin->refresh_with_pending_parent();
} else {
fut = get_pin(t, pin->get_key()
).si_then([&pin](auto npin) {
assert(npin);
pin = std::move(npin);
return seastar::now();
}).handle_error_interruptible(
crimson::ct_error::enoent::assert_failure{"unexpected enoent"},
crimson::ct_error::input_output_error::pass_further{}
);
}
} else {
pin->maybe_fix_pos();
}

What do you think?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, I suppose the following code might be able to be (mostly) encapsulated in pin/interator during the refactoring:

Yeah, both of cases could be handled by refresh_iterator() or refresh_mapping(), I'm working on it.

enum class state_t {
PARTIAL,
FULL
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the meaning of partial vs full iterator?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. full iterator: the iterator::internal is up-to-date.
  2. partial iterator: the iterator::internal is empty, it's always built from BtreeValueIterator

).si_then([](auto&&) {
).si_then([&removed_mappings, paddr=backref_entry.paddr]
(auto&& res) {
removed_mappings.insert(paddr, res);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhscn I see the point of RemappedExtentPlaceholder now, let's split it out to a separate PR first to look separately.

This is probably good to me, because otherwise we'll need to store "type" in the lba tree instead. Which means the "type" information is duplicated in the disk (in both lba and backref), and it is another problem in case they don't match each other persistently.

@zhscn zhscn Jan 8, 2025 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about only storing the extent type in lba btree? The backref tree could use a flag to indicate the extent is logical or not for TransactionManager::get_extents_if_live().

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, seems this is not very different from storing "type" in both trees.

Anyway, I don't see major concerns in either way (RemappedPlaceholder or storing "type" also in lba).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, #60814 (comment) will be added to code comment in the future.

@zhscn

zhscn commented Jan 8, 2025 •

Copy link
Copy Markdown
Member Author

Summary about RemappedExtentPlaceholder:

  1. It's required by "relocate logical extent" or "move lba mapping" feature which is from "pin head" and "rename" requirements for static layout of laddr_t.
  2. The relocate procedure works as follow:
    1. get to be relocated lba mapping m1<laddr1, paddr1>
    2. remove lba mapping m1
    3. insert the mapping of paddr1 to laddr2
    4. construct a RetiredPlaceholder for paddr1 due to the lack of concrete CachedExtent
    5. construct a RemappedExtentPlaceholder to represent lba mapping <laddr2, paddr1> because we don't know the real extent type at paddr1
    6. generate backref delta <paddr1, L_ADDR_NULL> and <paddr1, laddr2, extent_types_t::REMAP_PLACEHOLDER>, then submit deltas to Cache::backref_entry_mset
    7. When updating backref btree, tracks all removed mappings' extent type and restore it when reaching RemappedExtentPlaceholder extent type
  3. Differences from RetiredPlaceholder:
    1. RetiredPlaceholder is invalid while RemappedExtentPlaceholder is valid.
    2. RetiredPlaceholder is added into Cache after constructing it, it's shared among all transactions. While RemappedExtentPlaceholder is transaction-local and won't be added into Cache. After the parent of RemappedExtentPlaceholder finishes replacing its prior instance, unlink the parent and placeholder, otherwise the children ptr in parent will become dangling pointer.
    3. The other transaction is possible to read a RetiredPlaceholder and replace it in Cache. Reading a RemappedExtentPlaceholder is possible required by the current transaction.

A simple approach to remove RemappedExtentPlaceholder is adding extent type to lba mapping.

@github-actions

github-actions Bot commented Jan 9, 2025

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

1 similar comment
@github-actions

github-actions Bot commented Jan 9, 2025

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@cyx1231st

Copy link
Copy Markdown
Member

I'll prioritize merging #61261 first.

@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs for another 30 days.
If you are a maintainer or core committer, please follow-up on this pull request to identify what steps should be taken by the author to move this proposed change forward.
If you are the author of this pull request, thank you for your proposed contribution. If you believe this change is still appropriate, please ensure that any feedback has been addressed and ask for a code review.

@github-actions github-actions Bot added the stale label Mar 11, 2025
@github-actions

Copy link
Copy Markdown

This pull request has been automatically closed because there has been no activity for 90 days. Please feel free to reopen this pull request (or open a new one) if the proposed change is still appropriate. Thank you for your contribution!

@github-actions github-actions Bot closed this Apr 10, 2025
@Matan-B Matan-B moved this from In Progress to Unassigned / Drafts / Discussion in Crimson Jul 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Unassigned / Drafts / Discussion

Development

Successfully merging this pull request may close these issues.

3 participants