Skip to content

Commit

Permalink
MDEV-34458: Remove more traces of BTR_MODIFY_PREV
Browse files Browse the repository at this point in the history
In commit 2f6df93
we fixed an observed case of the bug by removing
some code related to the no longer needed
BTR_MODIFY_PREV mode.

In commit 73ad436
an alternative fix was applied that also fixes the
BTR_SEARCH_PREV case.

Let us clean up some implicit references to BTR_MODIFY_PREV
that were missed in 2f6df93.

btr_pcur_move_backward_from_page(): Assume that the latch mode was
BTR_SEARCH_LEAF.

btr_pcur_move_to_prev(): Assert that the latch mode is BTR_SEARCH_LEAF.
This function is mostly invoked in row0sel.cc for read operations,
as well as in row0merge.cc for reading from the clustered index.
All callers indeed use a cursor in the BTR_SEARCH_LEAF mode.
  • Loading branch information
dr-m committed Jul 29, 2024
1 parent 88711ee commit 7ead48a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
8 changes: 3 additions & 5 deletions storage/innobase/btr/btr0cur.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1301,11 +1301,9 @@ dberr_t btr_cur_t::search_leaf(const dtuple_t *tuple, page_cur_mode_t mode,
}

switch (latch_mode) {
case BTR_SEARCH_PREV:
static_assert(BTR_SEARCH_PREV & BTR_SEARCH_LEAF, "");
case BTR_SEARCH_PREV: /* btr_pcur_move_to_prev() */
ut_ad(!latch_by_caller);
ut_ad(rw_latch ==
rw_lock_type_t(latch_mode & (RW_X_LATCH | RW_S_LATCH)));
ut_ad(rw_latch == RW_S_LATCH);

/* latch also siblings from left to right */
if (page_has_prev(block->page.frame) &&
Expand Down Expand Up @@ -1479,7 +1477,7 @@ dberr_t btr_cur_t::search_leaf(const dtuple_t *tuple, page_cur_mode_t mode,
rw_latch= RW_X_LATCH;
break;
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);

if (!not_first_access)
buf_read_ahead_linear(page_id, zip_size);
Expand Down
17 changes: 5 additions & 12 deletions storage/innobase/btr/btr0pcur.cc
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,9 @@ btr_pcur_t::restore_position(btr_latch_mode restore_latch_mode, mtr_t *mtr)
ut_a(old_n_core_fields <= index->n_core_fields);
ut_a(old_n_fields);

static_assert(BTR_SEARCH_PREV == (4 | BTR_SEARCH_LEAF), "");
static_assert(int{BTR_SEARCH_PREV} == (4 | BTR_SEARCH_LEAF), "");

switch (restore_latch_mode | 4) {
case BTR_SEARCH_PREV:
if ((restore_latch_mode | 4) == BTR_SEARCH_PREV) {
/* Try optimistic restoration. */
if (btr_pcur_optimistic_latch_leaves(this, &restore_latch_mode,
mtr)) {
Expand Down Expand Up @@ -561,19 +560,13 @@ btr_pcur_move_backward_from_page(
ut_ad(btr_pcur_is_before_first_on_page(cursor));
ut_ad(!btr_pcur_is_before_first_in_tree(cursor));

const auto latch_mode = cursor->latch_mode;
ut_ad(latch_mode == BTR_SEARCH_LEAF || latch_mode == BTR_MODIFY_LEAF);

btr_pcur_store_position(cursor, mtr);

mtr_commit(mtr);

mtr_start(mtr);

static_assert(BTR_SEARCH_PREV == (4 | BTR_SEARCH_LEAF), "");

if (UNIV_UNLIKELY(cursor->restore_position(
btr_latch_mode(4 | latch_mode), mtr)
if (UNIV_UNLIKELY(cursor->restore_position(BTR_SEARCH_PREV, mtr)
== btr_pcur_t::CORRUPTED)) {
return true;
}
Expand Down Expand Up @@ -605,7 +598,7 @@ btr_pcur_move_backward_from_page(

mtr->rollback_to_savepoint(1);
ut_ad(block == mtr->at_savepoint(0));
cursor->latch_mode = latch_mode;
cursor->latch_mode = BTR_SEARCH_LEAF;
cursor->old_rec = nullptr;
return false;
}
Expand All @@ -622,7 +615,7 @@ btr_pcur_move_to_prev(
mtr_t* mtr) /*!< in: mtr */
{
ut_ad(cursor->pos_state == BTR_PCUR_IS_POSITIONED);
ut_ad(cursor->latch_mode != BTR_NO_LATCHES);
ut_ad(cursor->latch_mode == BTR_SEARCH_LEAF);

cursor->old_rec = nullptr;

Expand Down

0 comments on commit 7ead48a

Please sign in to comment.