Commit 2f6df937 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-34458 wait_for_read in buf_page_get_low hurts performance

BTR_MODIFY_PREV: Remove. This mode was only used by the change buffer,
which commit f27e9c89 (MDEV-29694)
removed.

buf_page_get_gen(): Revert the change that was made in
commit 90b95c61 (MDEV-33543)
because it is not applicable after MDEV-29694. This fixes the
performance regression that Vladislav Vaintroub reported.

This is a 11.x specific fix; this needs to be fixed differently
in older major versions where the change buffer is present.
parent cc136307
...@@ -1220,7 +1220,7 @@ dberr_t btr_cur_t::search_leaf(const dtuple_t *tuple, page_cur_mode_t mode, ...@@ -1220,7 +1220,7 @@ dberr_t btr_cur_t::search_leaf(const dtuple_t *tuple, page_cur_mode_t mode,
ut_ad(rw_lock_type_t(latch_mode & ~12) == RW_X_LATCH); ut_ad(rw_lock_type_t(latch_mode & ~12) == RW_X_LATCH);
goto relatch_x; goto relatch_x;
} }
if (latch_mode != BTR_MODIFY_PREV) else
{ {
if (!latch_by_caller) if (!latch_by_caller)
/* Release the tree s-latch */ /* Release the tree s-latch */
...@@ -1292,8 +1292,6 @@ dberr_t btr_cur_t::search_leaf(const dtuple_t *tuple, page_cur_mode_t mode, ...@@ -1292,8 +1292,6 @@ dberr_t btr_cur_t::search_leaf(const dtuple_t *tuple, page_cur_mode_t mode,
switch (latch_mode) { switch (latch_mode) {
case BTR_SEARCH_PREV: case BTR_SEARCH_PREV:
case BTR_MODIFY_PREV:
static_assert(BTR_MODIFY_PREV & BTR_MODIFY_LEAF, "");
static_assert(BTR_SEARCH_PREV & BTR_SEARCH_LEAF, ""); static_assert(BTR_SEARCH_PREV & BTR_SEARCH_LEAF, "");
ut_ad(!latch_by_caller); ut_ad(!latch_by_caller);
ut_ad(rw_latch == ut_ad(rw_latch ==
...@@ -1470,7 +1468,6 @@ dberr_t btr_cur_t::search_leaf(const dtuple_t *tuple, page_cur_mode_t mode, ...@@ -1470,7 +1468,6 @@ dberr_t btr_cur_t::search_leaf(const dtuple_t *tuple, page_cur_mode_t mode,
case BTR_MODIFY_ROOT_AND_LEAF: case BTR_MODIFY_ROOT_AND_LEAF:
rw_latch= RW_X_LATCH; rw_latch= RW_X_LATCH;
break; break;
case BTR_MODIFY_PREV: /* btr_pcur_move_to_prev() */
case BTR_SEARCH_PREV: /* btr_pcur_move_to_prev() */ case BTR_SEARCH_PREV: /* btr_pcur_move_to_prev() */
ut_ad(rw_latch == RW_S_LATCH || rw_latch == RW_X_LATCH); ut_ad(rw_latch == RW_S_LATCH || rw_latch == RW_X_LATCH);
...@@ -1854,7 +1851,6 @@ dberr_t btr_cur_t::open_leaf(bool first, dict_index_t *index, ...@@ -1854,7 +1851,6 @@ dberr_t btr_cur_t::open_leaf(bool first, dict_index_t *index,
ut_ad(!(latch_mode & 8)); ut_ad(!(latch_mode & 8));
/* This function doesn't need to lock left page of the leaf page */ /* This function doesn't need to lock left page of the leaf page */
static_assert(int{BTR_SEARCH_PREV} == (4 | BTR_SEARCH_LEAF), ""); static_assert(int{BTR_SEARCH_PREV} == (4 | BTR_SEARCH_LEAF), "");
static_assert(int{BTR_MODIFY_PREV} == (4 | BTR_MODIFY_LEAF), "");
latch_mode= btr_latch_mode(latch_mode & (RW_S_LATCH | RW_X_LATCH)); latch_mode= btr_latch_mode(latch_mode & (RW_S_LATCH | RW_X_LATCH));
ut_ad(!latch_by_caller || ut_ad(!latch_by_caller ||
mtr->memo_contains_flagged(&index->lock, mtr->memo_contains_flagged(&index->lock,
......
...@@ -215,24 +215,18 @@ static bool btr_pcur_optimistic_latch_leaves(btr_pcur_t *pcur, ...@@ -215,24 +215,18 @@ static bool btr_pcur_optimistic_latch_leaves(btr_pcur_t *pcur,
btr_latch_mode *latch_mode, btr_latch_mode *latch_mode,
mtr_t *mtr) mtr_t *mtr)
{ {
static_assert(BTR_SEARCH_PREV & BTR_SEARCH_LEAF, "");
static_assert(BTR_MODIFY_PREV & BTR_MODIFY_LEAF, "");
static_assert((BTR_SEARCH_PREV ^ BTR_MODIFY_PREV) ==
(RW_S_LATCH ^ RW_X_LATCH), "");
buf_block_t *const block= buf_block_t *const block=
buf_page_optimistic_fix(pcur->btr_cur.page_cur.block, pcur->old_page_id); buf_page_optimistic_fix(pcur->btr_cur.page_cur.block, pcur->old_page_id);
if (!block) if (!block)
return false; return false;
if (*latch_mode == BTR_SEARCH_LEAF || *latch_mode == BTR_MODIFY_LEAF) if (*latch_mode != BTR_SEARCH_PREV)
{
ut_ad(*latch_mode == BTR_SEARCH_LEAF || *latch_mode == BTR_MODIFY_LEAF);
return buf_page_optimistic_get(block, rw_lock_type_t(*latch_mode), return buf_page_optimistic_get(block, rw_lock_type_t(*latch_mode),
pcur->modify_clock, mtr); pcur->modify_clock, mtr);
}
ut_ad(*latch_mode == BTR_SEARCH_PREV || *latch_mode == BTR_MODIFY_PREV);
const rw_lock_type_t mode=
rw_lock_type_t(*latch_mode & (RW_X_LATCH | RW_S_LATCH));
uint64_t modify_clock; uint64_t modify_clock;
uint32_t left_page_no; uint32_t left_page_no;
...@@ -258,7 +252,7 @@ static bool btr_pcur_optimistic_latch_leaves(btr_pcur_t *pcur, ...@@ -258,7 +252,7 @@ static bool btr_pcur_optimistic_latch_leaves(btr_pcur_t *pcur,
{ {
prev= buf_page_get_gen(page_id_t(pcur->old_page_id.space(), prev= buf_page_get_gen(page_id_t(pcur->old_page_id.space(),
left_page_no), block->zip_size(), left_page_no), block->zip_size(),
mode, nullptr, BUF_GET_POSSIBLY_FREED, mtr); RW_S_LATCH, nullptr, BUF_GET_POSSIBLY_FREED, mtr);
if (!prev || if (!prev ||
page_is_comp(prev->page.frame) != page_is_comp(block->page.frame) || page_is_comp(prev->page.frame) != page_is_comp(block->page.frame) ||
memcmp_aligned<2>(block->page.frame, prev->page.frame, 2) || memcmp_aligned<2>(block->page.frame, prev->page.frame, 2) ||
...@@ -269,7 +263,7 @@ static bool btr_pcur_optimistic_latch_leaves(btr_pcur_t *pcur, ...@@ -269,7 +263,7 @@ static bool btr_pcur_optimistic_latch_leaves(btr_pcur_t *pcur,
else else
prev= nullptr; prev= nullptr;
mtr->upgrade_buffer_fix(savepoint, mode); mtr->upgrade_buffer_fix(savepoint, RW_S_LATCH);
if (UNIV_UNLIKELY(block->modify_clock != modify_clock) || if (UNIV_UNLIKELY(block->modify_clock != modify_clock) ||
UNIV_UNLIKELY(block->page.is_freed()) || UNIV_UNLIKELY(block->page.is_freed()) ||
...@@ -343,11 +337,9 @@ btr_pcur_t::restore_position(btr_latch_mode restore_latch_mode, mtr_t *mtr) ...@@ -343,11 +337,9 @@ btr_pcur_t::restore_position(btr_latch_mode restore_latch_mode, mtr_t *mtr)
ut_a(old_n_fields); ut_a(old_n_fields);
static_assert(BTR_SEARCH_PREV == (4 | BTR_SEARCH_LEAF), ""); static_assert(BTR_SEARCH_PREV == (4 | BTR_SEARCH_LEAF), "");
static_assert(BTR_MODIFY_PREV == (4 | BTR_MODIFY_LEAF), "");
switch (restore_latch_mode | 4) { switch (restore_latch_mode | 4) {
case BTR_SEARCH_PREV: case BTR_SEARCH_PREV:
case BTR_MODIFY_PREV:
/* Try optimistic restoration. */ /* Try optimistic restoration. */
if (btr_pcur_optimistic_latch_leaves(this, &restore_latch_mode, if (btr_pcur_optimistic_latch_leaves(this, &restore_latch_mode,
mtr)) { mtr)) {
...@@ -579,7 +571,6 @@ btr_pcur_move_backward_from_page( ...@@ -579,7 +571,6 @@ btr_pcur_move_backward_from_page(
mtr_start(mtr); mtr_start(mtr);
static_assert(BTR_SEARCH_PREV == (4 | BTR_SEARCH_LEAF), ""); static_assert(BTR_SEARCH_PREV == (4 | BTR_SEARCH_LEAF), "");
static_assert(BTR_MODIFY_PREV == (4 | BTR_MODIFY_LEAF), "");
if (UNIV_UNLIKELY(cursor->restore_position( if (UNIV_UNLIKELY(cursor->restore_position(
btr_latch_mode(4 | latch_mode), mtr) btr_latch_mode(4 | latch_mode), mtr)
......
...@@ -2740,15 +2740,7 @@ buf_page_get_gen( ...@@ -2740,15 +2740,7 @@ buf_page_get_gen(
in buf_page_t::read_complete() or in buf_page_t::read_complete() or
buf_pool_t::corrupted_evict(), or buf_pool_t::corrupted_evict(), or
after buf_zip_decompress() in this function. */ after buf_zip_decompress() in this function. */
if (rw_latch != RW_NO_LATCH) {
block->page.lock.s_lock(); block->page.lock.s_lock();
} else if (!block->page.lock.s_lock_try()) {
/* For RW_NO_LATCH, we should not try to acquire S or X
latch directly as we could be violating the latching
order resulting in deadlock. Instead we try latching the
page and retry in case of a failure. */
goto wait_for_read;
}
state = block->page.state(); state = block->page.state();
ut_ad(state < buf_page_t::READ_FIX ut_ad(state < buf_page_t::READ_FIX
|| state >= buf_page_t::WRITE_FIX); || state >= buf_page_t::WRITE_FIX);
...@@ -2756,15 +2748,15 @@ buf_page_get_gen( ...@@ -2756,15 +2748,15 @@ buf_page_get_gen(
block->page.lock.s_unlock(); block->page.lock.s_unlock();
if (UNIV_UNLIKELY(state < buf_page_t::UNFIXED)) { if (UNIV_UNLIKELY(state < buf_page_t::UNFIXED)) {
block->page.unfix();
if (UNIV_UNLIKELY(id == page_id)) { if (UNIV_UNLIKELY(id == page_id)) {
/* The page read was completed, and /* The page read was completed, and
another thread marked the page as free another thread marked the page as free
while we were waiting. */ while we were waiting. */
goto ignore_block; goto ignore_unfixed;
} }
ut_ad(id == page_id_t{~0ULL}); ut_ad(id == page_id_t{~0ULL});
block->page.unfix();
if (++retries < BUF_PAGE_READ_MAX_RETRIES) { if (++retries < BUF_PAGE_READ_MAX_RETRIES) {
goto loop; goto loop;
...@@ -2803,7 +2795,6 @@ buf_page_get_gen( ...@@ -2803,7 +2795,6 @@ buf_page_get_gen(
if (UNIV_UNLIKELY(!block->page.frame)) { if (UNIV_UNLIKELY(!block->page.frame)) {
if (!block->page.lock.x_lock_try()) { if (!block->page.lock.x_lock_try()) {
wait_for_unzip: wait_for_unzip:
wait_for_read:
/* The page is being read or written, or /* The page is being read or written, or
another thread is executing buf_zip_decompress() another thread is executing buf_zip_decompress()
in buf_page_get_gen() on it. */ in buf_page_get_gen() on it. */
......
...@@ -604,7 +604,6 @@ dberr_t rtr_search_to_nth_level(btr_cur_t *cur, que_thr_t *thr, ...@@ -604,7 +604,6 @@ dberr_t rtr_search_to_nth_level(btr_cur_t *cur, que_thr_t *thr,
upper_rw_latch= RW_X_LATCH; upper_rw_latch= RW_X_LATCH;
break; break;
default: default:
ut_ad(latch_mode != BTR_MODIFY_PREV);
ut_ad(latch_mode != BTR_SEARCH_PREV); ut_ad(latch_mode != BTR_SEARCH_PREV);
if (!latch_by_caller) if (!latch_by_caller)
mtr_s_lock_index(index, mtr); mtr_s_lock_index(index, mtr);
......
...@@ -68,9 +68,6 @@ enum btr_latch_mode { ...@@ -68,9 +68,6 @@ enum btr_latch_mode {
/** Search the previous record. /** Search the previous record.
Used in btr_pcur_move_backward_from_page(). */ Used in btr_pcur_move_backward_from_page(). */
BTR_SEARCH_PREV = 4 | BTR_SEARCH_LEAF, BTR_SEARCH_PREV = 4 | BTR_SEARCH_LEAF,
/** Modify the previous record.
Used in btr_pcur_move_backward_from_page(). */
BTR_MODIFY_PREV = 4 | BTR_MODIFY_LEAF,
/** Start modifying the entire B-tree. */ /** Start modifying the entire B-tree. */
BTR_MODIFY_TREE = 8 | BTR_MODIFY_LEAF, BTR_MODIFY_TREE = 8 | BTR_MODIFY_LEAF,
/** Continue modifying the entire R-tree. /** Continue modifying the entire R-tree.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment