server icon indicating copy to clipboard operation
server copied to clipboard

MDEV-34759: buf_page_get_low() is unnecessarily acquiring exclusive latch

Open dr-m opened this issue 1 year ago • 1 comments
trafficstars

  • [x] The Jira issue number for this PR is: MDEV-34759

Description

Basically any request on a secondary index leaf page would unnecessarily first acquire an exclusive page latch, in case any buffered changes would have to be merged into the page. This would unnecessarily slow down read operations.

buf_page_ibuf_merge_try(): A separate function for invoking ibuf_merge_or_delete_for_page() when needed. Use the already requested page latch for determining if the call is necessary. If it is and if we are currently holding rw_latch==RW_S_LATCH, upgrading to an exclusive latch may involve waiting that another thread acquires and releases a U or X latch on the page. If we have to wait, we must recheck if the call to ibuf_merge_or_delete_for_page() is still needed. If the page turns out to be corrupted, we will release and fail the operation. Finally, the exclusive page latch will be downgraded to the originally requested latch.

ssux_lock_impl::rd_u_upgrade_try(), sux_lock::s_x_upgrade_try(): Attempt to upgrade a shared lock to an update lock.

ssux_lock_impl::u_rd_downgrade(), sux_lock::u_s_downgrade(): Downgrade an update lock to shared.

Release Notes

The performance of secondary index read operations was improved.

How can this PR be tested?

This is a low-level change that is well covered by ./mtr, except for the change buffer.

The change buffer needs to be subjected to a stress test, with innodb_change_buffering=all.

Performance can be tested with Sysbench select_random_ranges using --tables=1 --table_size=10000. On my system with 2×10×2 threads, I tested --threads=20 against the baseline:

revision throughput/qps
267c0fce5696a6be7f2e04bc01035db855cc970f 43141.66
3bf05a4c201c5393e7707ae4c1662e1f2cf0f65e 70529.46

Basing the PR against the correct MariaDB version

  • [ ] This is a new feature or a refactoring, and the PR is based against the latest MariaDB development branch.
  • [ ] This is a bug fix, and the PR is based against the earliest maintained branch in which the bug can be reproduced.

This is also applicable to the 10.5 branch, but this fix depends on 2bd661ca1038e78296289d9285d54b57954d48e6 (#3317), which depends on prior refactoring that was done in the 10.6 branch.

PR quality check

  • [x] I checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.
  • [ ] For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.

dr-m avatar Aug 16 '24 14:08 dr-m

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar Aug 16 '24 14:08 CLAassistant