Repository navigation
Conversation
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
ee2daa1 to
d1c4616
Compare
|
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.
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>;
|
d1c4616 to
2a0c03f
Compare
2a0c03f to
d186311
Compare
Signed-off-by: Zhang Song <[email protected]>
Signed-off-by: Zhang Song <[email protected]>
…apping Signed-off-by: Xuehan Xu <[email protected]>
Signed-off-by: Zhang Song <[email protected]>
Signed-off-by: Zhang Song <[email protected]>
Signed-off-by: Zhang Song <[email protected]>
Signed-off-by: Zhang Song <[email protected]>
Signed-off-by: Zhang Song <[email protected]>
d186311 to
ff9e6cf
Compare
…r LBAManager Signed-off-by: Zhang Song <[email protected]>
Signed-off-by: Zhang Song <[email protected]>
…BA Leaf extent Signed-off-by: Zhang Song <[email protected]>
|
Changes:
|
Signed-off-by: Zhang Song <[email protected]> Signed-off-by: Xuehan Xu <[email protected]>
Signed-off-by: Zhang Song <[email protected]>
cyx1231st
left a comment
There was a problem hiding this comment.
Still trying to understand new interfaces in lba_manager.h, I hope this is a reasonable angle to begin with.
There was a problem hiding this comment.
What is the meaning of "Erased" under the context of "BtreeIter" ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
ErasedBtreeItertoBtreeValueIterator. - Make
BtreeNodeMappingto own aBtreeValueIteratorinternally.
?
In another word, is it reasonable to (start to) leverage BtreeValueIterator to encapsulate/reuse btree mapping logics that are unrelated to lba indirections?
There was a problem hiding this comment.
The BtreeNodeMapping includes 3 parts for now:
- The information from
FixedKVBtree, which includes fieldsparentvaluerangeandpos. These fields are very similar toBtreeValueIterator. The difference is that the value type ofBtreeNodeMappingisladdr_torpaddr_tand the introducedBtreeValueIteratoruses the complete typelba_map_val_tandbackref_map_val_t. - The indirect properties of LBAMapping, which is handled by
lba_map_val_t::pladdr_tinternally in LBAManager. The problem here is thatBtreeNodeMappingonly contains oneparenthas direct mapping, which makes inconvenient when updating the original indirect mapping. The refactoredBtreeNodeMappingshould contains two iterators:BtreeValueIterator direct_iter, indirect_iter; - The handler of linked child logical extent:
PhysicalNodeMapping::get_logical_extent()andBtreeNodeMapping::ctx, seems it's better to move this part toTransactionManagercompletely. TheBtreeNodeMappingshould not have futurized methods.
There was a problem hiding this comment.
Ideally, the TransactionManager interface should accept BtreeNodeMapping, while the LBAManager interface should accept BtreeValueIterator.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
|
This PR will be split into two parts in next push, it only contains |
| */ | ||
| using make_iterator_iertr = base_iertr; | ||
| using make_iterator_ret = make_iterator_iertr::future<LBAIter>; | ||
| virtual make_iterator_ret make_iterator( |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
Yes, it always returns the direct iterator.
| /** | ||
| * refresh_iterator | ||
| * | ||
| * Ensures the iterator is valid. It's possible to start a new search internally. |
There was a problem hiding this comment.
Worth to elaborate the comments about why/how an iterator can become invalid, so an user understands when this interface should be used.
There was a problem hiding this comment.
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
-
If we were allowed to store the modification history of
FixedKVNodein invalid extents, we could eliminate this lookup. However, keeping meaningful information in invalid extents doesn’t seem like a good idea. ↩
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Does the returned iterator contain a valid lba tree value, or it is a "free" iterator without lba tree value?
There was a problem hiding this comment.
The iterator should always contain a valid lba tree value unless it's the at end of lba btree.
There was a problem hiding this comment.
- IIUC, how about: "... and an iterator to the right that can be ..."
- Can find_region_result_t.laddr be L_ADDR_NULL (I see there is a constructor)?
- Let's drop the constructors of
find_region_result_tbecause it is only used to group together return named values. - Why is
find_region_result_t()needed? As a return value, it should always be valid, right?
There was a problem hiding this comment.
- IIUC, how about: "... and an iterator to the right that can be ..."
Yeah.
- Can find_region_result_t.laddr be L_ADDR_NULL (I see there is a constructor)?
No, it returns non-null laddr.
- Let's drop the constructors of
find_region_result_tbecause it is only used to group together return named values.- 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>().
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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).
| virtual get_iterators_ret get_iterators( | ||
| Transaction &t, | ||
| laddr_t laddr, | ||
| extent_len_t length) = 0; |
There was a problem hiding this comment.
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.
| const LBAIter &iter, | ||
| laddr_t laddr, | ||
| lba_map_val_t value, | ||
| LogicalCachedExtent *nextent) = 0; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
- If laddr is direct, the nextent should be not null;
- If laddr is indirect, the nextent should be reserved ptr
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
"nextent should be reserved ptr if the original extent is retired"
I'm not fully following this part yet, is it related to RemappedExtentPlaceholder ?
There was a problem hiding this comment.
change_mapping has some use cases:
update_mapping, update the paddr of lba mapping in normal IO path;- remap lba mapping
a. change the length of lba mapping
b. change the lba maping to its sub-mapping - 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
update_paddr, accepting not nullnextent;remap_mapping, accepting not nullnextent;make_indirect, not requiringnextentparameter;
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Does the returned iterator contain a valid lba tree value, or it is a "free" iterator without lba tree value?
There was a problem hiding this comment.
Similarly: "... Return the iterator to the right ..."
| const LBAIter &iter, | ||
| laddr_t laddr, | ||
| lba_map_val_t value, | ||
| LogicalCachedExtent *nextent) { |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Yeah, I think named and strict interfaces are always better than one multi-functional interface which cannot be understood easily thus error-prone.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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:
ceph/src/crimson/os/seastore/transaction_manager.h
Lines 272 to 286 in 4d53a27
ceph/src/crimson/os/seastore/transaction_manager.h
Lines 530 to 546 in 4d53a27
What do you think?
There was a problem hiding this comment.
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 | ||
| }; |
There was a problem hiding this comment.
What's the meaning of partial vs full iterator?
There was a problem hiding this comment.
- full iterator: the
iterator::internalis up-to-date. - partial iterator: the
iterator::internalis empty, it's always built fromBtreeValueIterator
| ).si_then([](auto&&) { | ||
| ).si_then([&removed_mappings, paddr=backref_entry.paddr] | ||
| (auto&& res) { | ||
| removed_mappings.insert(paddr, res); |
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
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().
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Ok, #60814 (comment) will be added to code comment in the future.
|
Summary about
A simple approach to remove |
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
1 similar comment
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
|
I'll prioritize merging #61261 first. |
|
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. |
|
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! |
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
xbetween the brackets:[x]. Spaces and capitalization matter when checking off items this way.Checklist
Show available Jenkins commands
jenkins retest this pleasejenkins test classic perfjenkins test crimson perfjenkins test signedjenkins test make checkjenkins test make check arm64jenkins test submodulesjenkins test dashboardjenkins test dashboard cephadmjenkins test apijenkins test docsjenkins render docsjenkins test ceph-volume alljenkins test ceph-volume toxjenkins test windowsjenkins test rook e2e