Commit a5ed56cd authored by Marko Mäkelä's avatar Marko Mäkelä

Cleanup: Remove BTR_MODIFY_EXTERNAL

btr_blob_log_check_t::check(): Acquire an index U-latch upfront and
pass the flag BTR_MODIFY_LEAF_ALREADY_LATCHED to the search.
parent af7bd64e
...@@ -1254,7 +1254,6 @@ dberr_t btr_cur_search_to_nth_level(dict_index_t *index, ulint level, ...@@ -1254,7 +1254,6 @@ dberr_t btr_cur_search_to_nth_level(dict_index_t *index, ulint level,
ulint root_height = 0; /* remove warning */ ulint root_height = 0; /* remove warning */
btr_intention_t lock_intention; btr_intention_t lock_intention;
bool modify_external;
buf_block_t* tree_blocks[BTR_MAX_LEVELS]; buf_block_t* tree_blocks[BTR_MAX_LEVELS];
ulint tree_savepoints[BTR_MAX_LEVELS]; ulint tree_savepoints[BTR_MAX_LEVELS];
ulint n_blocks = 0; ulint n_blocks = 0;
...@@ -1303,11 +1302,9 @@ dberr_t btr_cur_search_to_nth_level(dict_index_t *index, ulint level, ...@@ -1303,11 +1302,9 @@ dberr_t btr_cur_search_to_nth_level(dict_index_t *index, ulint level,
cursor->low_match = ULINT_UNDEFINED; cursor->low_match = ULINT_UNDEFINED;
#endif /* UNIV_DEBUG */ #endif /* UNIV_DEBUG */
ibool s_latch_by_caller; const bool latch_by_caller = latch_mode & BTR_ALREADY_S_LATCHED;
s_latch_by_caller = latch_mode & BTR_ALREADY_S_LATCHED; ut_ad(!latch_by_caller
ut_ad(!s_latch_by_caller
|| srv_read_only_mode || srv_read_only_mode
|| mtr->memo_contains_flagged(&index->lock, MTR_MEMO_S_LOCK || mtr->memo_contains_flagged(&index->lock, MTR_MEMO_S_LOCK
| MTR_MEMO_SX_LOCK)); | MTR_MEMO_SX_LOCK));
...@@ -1344,14 +1341,10 @@ dberr_t btr_cur_search_to_nth_level(dict_index_t *index, ulint level, ...@@ -1344,14 +1341,10 @@ dberr_t btr_cur_search_to_nth_level(dict_index_t *index, ulint level,
lock_intention = btr_cur_get_and_clear_intention(&latch_mode); lock_intention = btr_cur_get_and_clear_intention(&latch_mode);
modify_external = latch_mode & BTR_MODIFY_EXTERNAL;
/* Turn the flags unrelated to the latch mode off. */ /* Turn the flags unrelated to the latch mode off. */
latch_mode = BTR_LATCH_MODE_WITHOUT_FLAGS(latch_mode); latch_mode = BTR_LATCH_MODE_WITHOUT_FLAGS(latch_mode);
ut_ad(!modify_external || latch_mode == BTR_MODIFY_LEAF); ut_ad(!latch_by_caller
ut_ad(!s_latch_by_caller
|| latch_mode == BTR_SEARCH_LEAF || latch_mode == BTR_SEARCH_LEAF
|| latch_mode == BTR_SEARCH_TREE || latch_mode == BTR_SEARCH_TREE
|| latch_mode == BTR_MODIFY_LEAF); || latch_mode == BTR_MODIFY_LEAF);
...@@ -1381,7 +1374,6 @@ dberr_t btr_cur_search_to_nth_level(dict_index_t *index, ulint level, ...@@ -1381,7 +1374,6 @@ dberr_t btr_cur_search_to_nth_level(dict_index_t *index, ulint level,
if (!btr_search_enabled) { if (!btr_search_enabled) {
} else if (autoinc == 0 } else if (autoinc == 0
&& latch_mode <= BTR_MODIFY_LEAF && latch_mode <= BTR_MODIFY_LEAF
&& !modify_external
# ifdef PAGE_CUR_LE_OR_EXTENDS # ifdef PAGE_CUR_LE_OR_EXTENDS
&& mode != PAGE_CUR_LE_OR_EXTENDS && mode != PAGE_CUR_LE_OR_EXTENDS
# endif /* PAGE_CUR_LE_OR_EXTENDS */ # endif /* PAGE_CUR_LE_OR_EXTENDS */
...@@ -1463,16 +1455,9 @@ dberr_t btr_cur_search_to_nth_level(dict_index_t *index, ulint level, ...@@ -1463,16 +1455,9 @@ dberr_t btr_cur_search_to_nth_level(dict_index_t *index, ulint level,
break; break;
default: default:
if (!srv_read_only_mode) { if (!srv_read_only_mode) {
if (s_latch_by_caller) { if (!latch_by_caller) {
} else if (!modify_external) {
/* BTR_SEARCH_TREE is intended to be used with
BTR_ALREADY_S_LATCHED */
ut_ad(latch_mode != BTR_SEARCH_TREE); ut_ad(latch_mode != BTR_SEARCH_TREE);
mtr_s_lock_index(index, mtr); mtr_s_lock_index(index, mtr);
} else {
/* BTR_MODIFY_EXTERNAL needs to be excluded */
mtr_sx_lock_index(index, mtr);
} }
upper_rw_latch = RW_S_LATCH; upper_rw_latch = RW_S_LATCH;
} else { } else {
...@@ -1540,10 +1525,9 @@ dberr_t btr_cur_search_to_nth_level(dict_index_t *index, ulint level, ...@@ -1540,10 +1525,9 @@ dberr_t btr_cur_search_to_nth_level(dict_index_t *index, ulint level,
each pages should be latched before reading. */ each pages should be latched before reading. */
if (height == ULINT_UNDEFINED if (height == ULINT_UNDEFINED
&& upper_rw_latch == RW_S_LATCH && upper_rw_latch == RW_S_LATCH
&& (modify_external || autoinc)) { && autoinc) {
/* needs sx-latch of root page /* needs sx-latch of root page
for fseg operation or for writing for writing PAGE_ROOT_AUTO_INC */
PAGE_ROOT_AUTO_INC */
rw_latch = RW_SX_LATCH; rw_latch = RW_SX_LATCH;
} else { } else {
rw_latch = upper_rw_latch; rw_latch = upper_rw_latch;
...@@ -1727,7 +1711,7 @@ dberr_t btr_cur_search_to_nth_level(dict_index_t *index, ulint level, ...@@ -1727,7 +1711,7 @@ dberr_t btr_cur_search_to_nth_level(dict_index_t *index, ulint level,
is latched differently from leaf pages. */ is latched differently from leaf pages. */
ut_ad(root_leaf_rw_latch != RW_NO_LATCH); ut_ad(root_leaf_rw_latch != RW_NO_LATCH);
ut_ad(rw_latch == RW_S_LATCH || rw_latch == RW_SX_LATCH); ut_ad(rw_latch == RW_S_LATCH || rw_latch == RW_SX_LATCH);
ut_ad(rw_latch == RW_S_LATCH || modify_external || autoinc); ut_ad(rw_latch == RW_S_LATCH || autoinc);
ut_ad(!autoinc || root_leaf_rw_latch == RW_X_LATCH); ut_ad(!autoinc || root_leaf_rw_latch == RW_X_LATCH);
ut_ad(n_blocks == 0); ut_ad(n_blocks == 0);
...@@ -1789,12 +1773,9 @@ dberr_t btr_cur_search_to_nth_level(dict_index_t *index, ulint level, ...@@ -1789,12 +1773,9 @@ dberr_t btr_cur_search_to_nth_level(dict_index_t *index, ulint level,
case BTR_CONT_SEARCH_TREE: case BTR_CONT_SEARCH_TREE:
break; break;
default: default:
if (!s_latch_by_caller if (!latch_by_caller
&& !srv_read_only_mode && !srv_read_only_mode) {
&& !modify_external) {
/* Release the tree s-latch */ /* Release the tree s-latch */
/* NOTE: BTR_MODIFY_EXTERNAL
needs to keep tree sx-latch */
mtr_release_s_latch_at_savepoint( mtr_release_s_latch_at_savepoint(
mtr, savepoint, mtr, savepoint,
&index->lock); &index->lock);
...@@ -1817,7 +1798,7 @@ dberr_t btr_cur_search_to_nth_level(dict_index_t *index, ulint level, ...@@ -1817,7 +1798,7 @@ dberr_t btr_cur_search_to_nth_level(dict_index_t *index, ulint level,
for (; n_releases < n_blocks; n_releases++) { for (; n_releases < n_blocks; n_releases++) {
if (n_releases == 0 if (n_releases == 0
&& (modify_external || autoinc)) { && (autoinc)) {
/* keep the root page latch */ /* keep the root page latch */
ut_ad(mtr->memo_contains_flagged( ut_ad(mtr->memo_contains_flagged(
tree_blocks[n_releases], tree_blocks[n_releases],
...@@ -2355,7 +2336,7 @@ dberr_t btr_cur_search_to_nth_level(dict_index_t *index, ulint level, ...@@ -2355,7 +2336,7 @@ dberr_t btr_cur_search_to_nth_level(dict_index_t *index, ulint level,
ut_ad(mtr->memo_contains_flagged(block, ut_ad(mtr->memo_contains_flagged(block,
upper_rw_latch)); upper_rw_latch));
if (s_latch_by_caller) { if (latch_by_caller) {
ut_ad(latch_mode == BTR_SEARCH_TREE); ut_ad(latch_mode == BTR_SEARCH_TREE);
/* to exclude modifying tree operations /* to exclude modifying tree operations
should sx-latch the index. */ should sx-latch the index. */
...@@ -2478,15 +2459,11 @@ btr_cur_open_at_index_side( ...@@ -2478,15 +2459,11 @@ btr_cur_open_at_index_side(
ut_ad(level != ULINT_UNDEFINED); ut_ad(level != ULINT_UNDEFINED);
bool s_latch_by_caller; const bool latch_by_caller = latch_mode & BTR_ALREADY_S_LATCHED;
s_latch_by_caller = latch_mode & BTR_ALREADY_S_LATCHED;
latch_mode &= ulint(~BTR_ALREADY_S_LATCHED); latch_mode &= ulint(~BTR_ALREADY_S_LATCHED);
lock_intention = btr_cur_get_and_clear_intention(&latch_mode); lock_intention = btr_cur_get_and_clear_intention(&latch_mode);
ut_ad(!(latch_mode & BTR_MODIFY_EXTERNAL));
/* 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 */
if (latch_mode == BTR_SEARCH_PREV) { if (latch_mode == BTR_SEARCH_PREV) {
latch_mode = BTR_SEARCH_LEAF; latch_mode = BTR_SEARCH_LEAF;
...@@ -2521,16 +2498,13 @@ btr_cur_open_at_index_side( ...@@ -2521,16 +2498,13 @@ btr_cur_open_at_index_side(
upper_rw_latch = RW_X_LATCH; upper_rw_latch = RW_X_LATCH;
break; break;
default: default:
ut_ad(!s_latch_by_caller ut_ad(!latch_by_caller
|| mtr->memo_contains_flagged(&index->lock, || mtr->memo_contains_flagged(&index->lock,
MTR_MEMO_SX_LOCK MTR_MEMO_SX_LOCK
| MTR_MEMO_S_LOCK)); | MTR_MEMO_S_LOCK));
if (!srv_read_only_mode) { if (!srv_read_only_mode) {
if (!s_latch_by_caller) { if (!latch_by_caller) {
/* BTR_SEARCH_TREE is intended to be used with
BTR_ALREADY_S_LATCHED */
ut_ad(latch_mode != BTR_SEARCH_TREE); ut_ad(latch_mode != BTR_SEARCH_TREE);
mtr_s_lock_index(index, mtr); mtr_s_lock_index(index, mtr);
} }
upper_rw_latch = RW_S_LATCH; upper_rw_latch = RW_S_LATCH;
...@@ -2631,7 +2605,7 @@ btr_cur_open_at_index_side( ...@@ -2631,7 +2605,7 @@ btr_cur_open_at_index_side(
if (UNIV_UNLIKELY(srv_read_only_mode)) { if (UNIV_UNLIKELY(srv_read_only_mode)) {
break; break;
} }
if (!s_latch_by_caller) { if (!latch_by_caller) {
/* Release the tree s-latch */ /* Release the tree s-latch */
mtr_release_s_latch_at_savepoint( mtr_release_s_latch_at_savepoint(
mtr, savepoint, &index->lock); mtr, savepoint, &index->lock);
...@@ -2649,12 +2623,12 @@ btr_cur_open_at_index_side( ...@@ -2649,12 +2623,12 @@ btr_cur_open_at_index_side(
&& UNIV_LIKELY(!srv_read_only_mode)) { && UNIV_LIKELY(!srv_read_only_mode)) {
/* We already have the block latched. */ /* We already have the block latched. */
ut_ad(latch_mode == BTR_SEARCH_TREE); ut_ad(latch_mode == BTR_SEARCH_TREE);
ut_ad(s_latch_by_caller); ut_ad(latch_by_caller);
ut_ad(upper_rw_latch == RW_S_LATCH); ut_ad(upper_rw_latch == RW_S_LATCH);
ut_ad(mtr->memo_contains_flagged(block, ut_ad(mtr->memo_contains_flagged(block,
MTR_MEMO_PAGE_S_FIX)); MTR_MEMO_PAGE_S_FIX));
if (s_latch_by_caller) { if (latch_by_caller) {
/* to exclude modifying tree operations /* to exclude modifying tree operations
should sx-latch the index. */ should sx-latch the index. */
ut_ad(mtr->memo_contains(index->lock, ut_ad(mtr->memo_contains(index->lock,
...@@ -2808,8 +2782,6 @@ btr_cur_open_at_rnd_pos( ...@@ -2808,8 +2782,6 @@ btr_cur_open_at_rnd_pos(
lock_intention = btr_cur_get_and_clear_intention(&latch_mode); lock_intention = btr_cur_get_and_clear_intention(&latch_mode);
ut_ad(!(latch_mode & BTR_MODIFY_EXTERNAL));
ulint savepoint = mtr_set_savepoint(mtr); ulint savepoint = mtr_set_savepoint(mtr);
rw_lock_type_t upper_rw_latch; rw_lock_type_t upper_rw_latch;
...@@ -6824,8 +6796,9 @@ struct btr_blob_log_check_t { ...@@ -6824,8 +6796,9 @@ struct btr_blob_log_check_t {
+ offs; + offs;
} else { } else {
ut_ad(m_pcur->rel_pos == BTR_PCUR_ON); ut_ad(m_pcur->rel_pos == BTR_PCUR_ON);
mtr_sx_lock_index(index, m_mtr);
ut_a(m_pcur->restore_position( ut_a(m_pcur->restore_position(
BTR_MODIFY_LEAF | BTR_MODIFY_EXTERNAL, BTR_MODIFY_LEAF_ALREADY_LATCHED,
m_mtr) == btr_pcur_t::SAME_ALL); m_mtr) == btr_pcur_t::SAME_ALL);
} }
......
...@@ -103,8 +103,8 @@ enum btr_latch_mode { ...@@ -103,8 +103,8 @@ enum btr_latch_mode {
BTR_SEARCH_TREE_ALREADY_S_LATCHED = BTR_SEARCH_TREE BTR_SEARCH_TREE_ALREADY_S_LATCHED = BTR_SEARCH_TREE
| BTR_ALREADY_S_LATCHED, | BTR_ALREADY_S_LATCHED,
/** Search and X-latch a leaf page, assuming that the /** Search and X-latch a leaf page, assuming that the
dict_index_t::lock S-latch is being held. */ dict_index_t::lock is being held in non-exclusive mode. */
BTR_MODIFY_LEAF_ALREADY_S_LATCHED = BTR_MODIFY_LEAF BTR_MODIFY_LEAF_ALREADY_LATCHED = BTR_MODIFY_LEAF
| BTR_ALREADY_S_LATCHED, | BTR_ALREADY_S_LATCHED,
/** Attempt to delete-mark a secondary index record. */ /** Attempt to delete-mark a secondary index record. */
...@@ -146,10 +146,6 @@ the insert buffer to speed up inserts */ ...@@ -146,10 +146,6 @@ the insert buffer to speed up inserts */
to find proper rec to undo insert.*/ to find proper rec to undo insert.*/
#define BTR_RTREE_UNDO_INS 4096U #define BTR_RTREE_UNDO_INS 4096U
/** In the case of BTR_MODIFY_LEAF, the caller intends to allocate or
free the pages of externally stored fields. */
#define BTR_MODIFY_EXTERNAL 16384U
/** Try to delete mark the record at the searched position when the /** Try to delete mark the record at the searched position when the
record is in spatial index */ record is in spatial index */
#define BTR_RTREE_DELETE_MARK 16384U #define BTR_RTREE_DELETE_MARK 16384U
...@@ -163,13 +159,11 @@ record is in spatial index */ ...@@ -163,13 +159,11 @@ record is in spatial index */
| BTR_IGNORE_SEC_UNIQUE \ | BTR_IGNORE_SEC_UNIQUE \
| BTR_ALREADY_S_LATCHED \ | BTR_ALREADY_S_LATCHED \
| BTR_LATCH_FOR_INSERT \ | BTR_LATCH_FOR_INSERT \
| BTR_LATCH_FOR_DELETE \ | BTR_LATCH_FOR_DELETE)))
| BTR_MODIFY_EXTERNAL)))
#define BTR_LATCH_MODE_WITHOUT_INTENTION(latch_mode) \ #define BTR_LATCH_MODE_WITHOUT_INTENTION(latch_mode) \
((latch_mode) & ulint(~(BTR_LATCH_FOR_INSERT \ ((latch_mode) & ulint(~(BTR_LATCH_FOR_INSERT \
| BTR_LATCH_FOR_DELETE \ | BTR_LATCH_FOR_DELETE)))
| BTR_MODIFY_EXTERNAL)))
/**************************************************************//** /**************************************************************//**
Checks and adjusts the root node of a tree during IMPORT TABLESPACE. Checks and adjusts the root node of a tree during IMPORT TABLESPACE.
......
...@@ -2574,7 +2574,7 @@ row_ins_clust_index_entry_low( ...@@ -2574,7 +2574,7 @@ row_ins_clust_index_entry_low(
} else { } else {
if (mode == BTR_MODIFY_LEAF if (mode == BTR_MODIFY_LEAF
&& dict_index_is_online_ddl(index)) { && dict_index_is_online_ddl(index)) {
mode = BTR_MODIFY_LEAF_ALREADY_S_LATCHED; mode = BTR_MODIFY_LEAF_ALREADY_LATCHED;
mtr_s_lock_index(index, &mtr); mtr_s_lock_index(index, &mtr);
} }
......
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