MDEV-34848 Remove overhead from unnecessary MDL_context_owner inheritance#4808
MDEV-34848 Remove overhead from unnecessary MDL_context_owner inheritance#4808kevdn wants to merge 3 commits intoMariaDB:mainfrom
Conversation
Instead of using abstract MDL_context_owner* interface, use THD* directly to avoid virtual function call overhead in MDL wait loops. The MDL subsystem only interacts with THD objects, so using THD* directly eliminates unnecessary virtual function calls for enter_cond, exit_cond, is_killed, and notify_shared_lock.
There was a problem hiding this comment.
Pull request overview
This PR refactors parts of the MDL/THD interaction by switching several APIs from the MDL_context_owner* abstraction to direct THD* usage.
Changes:
- Updated
notify_shared_lock()to takeTHD*instead ofMDL_context_owner*and adjusted call sites/implementation accordingly. - Updated
MDL_wait::timed_wait()andMDL_contextownership plumbing to useTHD*directly. - Simplified a few
get_thd()-mediated field accesses (e.g.,rgi_slave,thd_is_connected).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| sql/sql_class.h | Changes THD::notify_shared_lock() signature to accept THD*. |
| sql/sql_class.cc | Adjusts THD::notify_shared_lock() implementation for new parameter type. |
| sql/mdl.h | Updates MDL_context_owner::notify_shared_lock(), MDL_wait::timed_wait(), and MDL_context owner storage/accessors to use THD*. |
| sql/mdl.cc | Updates MDL_wait::timed_wait() implementation and related THD accesses for the new THD* owner type. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
FooBarrior
left a comment
There was a problem hiding this comment.
I would actually prefer the opposite: architecturally, we should focus on decomposing thd, because it's bloated.
I understand though, that we might want to make de-architecturizing optimizations, if it's worth it.
If this is supposed to be a such, is there any benchmark demonstrating the commitment?
- Update documentation comments to reflect THD* usage - Remove redundant ctx_in_use alias in notify_shared_lock() - Add note about backward compatibility of MDL_context_owner interface Co-Authored-By: kevdn <lehuukhoa12@gmail.com>
|
Agree with @FooBarrior . For the unmeasurable performance benefit of removing virtual function we'll plant this THD dependency everywhere. We should actually de-THD as much as we can, it is too important class, which purpose nobody can explain well. |
gkodinov
left a comment
There was a problem hiding this comment.
Thank you for working on this! This is a preliminary review.
First, on the technicalities: Please squash your two commits into a single one and provide a commit message to it that compiles with CODING_STANDARDS.md.
Secondly, I kind of agree with the two developers that have commented that you need a strong case to remove layering like you did. A benchmark or profile info would help. And even in that case, there probably are alternatives to removing a base class for THD.
|
Said the above, I see mysql/mysql-server@b9766fe68bab as a step towards a wrong direction and I'm happy to see it reverted. I won't blindly buy the "performance benefit of removing virtual function". But still I see it as a valid encapsulation cleanup and it must make |
svoj
left a comment
There was a problem hiding this comment.
Looks, nice. A few requests inline.
Svoj, We either want MDL_context_owner or we don't. I will not participate in that debate. It's an architecture decision IMHO. If we want it, the whole diff should be about avoiding virtual functions and it being useful only as a THD base class. If we don't however, why not remove it altogether? In both cases, I believe the PR needs work. |
@gkodinov we don't need |
- Remove MDL_context_owner class from mdl.h - Remove inheritance from MDL_context_owner in THD class - Remove override keywords from THD methods - Rename ctx_in_use parameter to in_use in notify_shared_lock()
|
Hi @svoj , I have resolved your comments. BTW, @svoj @gkodinov @vaintroub @FooBarrior , I ran sysbench to compare the original vs optimized versions. Benchmark ResultsEnvironment
Command OriginalOptimized (after removing
|
There was a problem hiding this comment.
Pull request overview
This PR removes the MDL_context_owner abstraction and updates the metadata locking (MDL) subsystem to use THD* directly as the MDL context owner, simplifying the ownership model and related call paths.
Changes:
- Removed the
MDL_context_ownerinterface andTHDinheritance from it. - Updated MDL APIs and internal state to store/pass
THD*owners (MDL_context,MDL_wait::timed_wait,THD::notify_shared_lock). - Adjusted MDL wait/notify logic and comments to reflect the new
THD*-based ownership.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| sql/sql_class.h | Drops MDL_context_owner inheritance; updates MDL-related methods/signatures on THD. |
| sql/sql_class.cc | Updates THD::notify_shared_lock implementation to take THD* directly. |
| sql/mdl.h | Removes MDL_context_owner; changes MDL owner storage and public APIs to use THD*. |
| sql/mdl.cc | Updates MDL wait/notify and owner access to use THD* (including WSREP/debug sync call sites). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
I don't think one can produce anything meaningful with read-write benchmark. |
|
Ok, I will try another benchmark |
svoj
left a comment
There was a problem hiding this comment.
@kevdn thanks for updating your patch. We're almost there. Please squash commits into one and update commit message, then force push to your mdev-34848-mdl-optimize branch.
I suggest that commit message:
- gives some background about
MDL_context_ownerand why it was wrong, feel free to copy first two paragraphs of #4808 (comment) - advertises the patch as a cleanup rather than optimization
Benchmarking is optional: me and @vaintroub are not expecting any meaningful performance impact from this change.
| bool needs_non_slave_abort); | ||
|
|
||
| // End implementation of MDL_context_owner interface. | ||
| // End of MDL-related methods. |
There was a problem hiding this comment.
No, these methods don't relate to MDL. They rather form some sort of session state interface, not MDL. Please remove this line, it is misleading.
| @@ -59,67 +59,6 @@ typedef unsigned short mdl_bitmap_t; | |||
| */ | |||
| #define EXIT_COND(S) exit_cond(S, __func__, __FILE__, __LINE__) | |||
There was a problem hiding this comment.
It'd be nice if you could also move ENTER_COND() and EXIT_COND() macros to sql_class.h, somewhere around THD_ENTER_COND() and THD_EXIT_COND().
| void rollback_to_savepoint(const MDL_savepoint &mdl_savepoint); | ||
|
|
||
| MDL_context_owner *get_owner() { return m_owner; } | ||
| THD *get_owner() { return m_owner; } |
There was a problem hiding this comment.
This is essentially equivalent to MDL_context::get_thd(). Please remove this method and adjust callers to use get_thd().
Optimize MDL by using THD* directly instead of using abstract MDL_context_owner* interface, use THD* directly to avoid virtual function call overhead in MDL wait loops.
The MDL subsystem only interacts with THD objects, so using THD* directly eliminates unnecessary virtual function calls for enter_cond, exit_cond, is_killed, and notify_shared_lock.