Skip to content

Commit 3d4a801

Browse files
committed
MDEV-12353 preparation: Replace mtr_x_lock() and friends
Apart from page latches (buf_block_t::lock), mini-transactions are keeping track of at most one dict_index_t::lock and fil_space_t::latch at a time, and in a rare case, purge_sys.latch. Let us introduce interfaces for acquiring an index latch or a tablespace latch. In a later version, we may want to introduce mtr_t members for holding a latched dict_index_t* and fil_space_t*, and replace the remaining use of mtr_t::m_memo with std::set<buf_block_t*> or with a map<buf_block_t*,byte*> pointing to log records.
1 parent 4ded5fb commit 3d4a801

22 files changed

+148
-163
lines changed

storage/innobase/btr/btr0btr.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4727,13 +4727,13 @@ btr_validate_level(
47274727
ulint parent_right_page_no = FIL_NULL;
47284728
bool rightmost_child = false;
47294729

4730-
mtr_start(&mtr);
4730+
mtr.start();
47314731

47324732
if (!srv_read_only_mode) {
47334733
if (lockout) {
4734-
mtr_x_lock(dict_index_get_lock(index), &mtr);
4734+
mtr_x_lock_index(index, &mtr);
47354735
} else {
4736-
mtr_sx_lock(dict_index_get_lock(index), &mtr);
4736+
mtr_sx_lock_index(index, &mtr);
47374737
}
47384738
}
47394739

@@ -4822,9 +4822,9 @@ btr_validate_level(
48224822
offsets = offsets2 = NULL;
48234823
if (!srv_read_only_mode) {
48244824
if (lockout) {
4825-
mtr_x_lock(dict_index_get_lock(index), &mtr);
4825+
mtr_x_lock_index(index, &mtr);
48264826
} else {
4827-
mtr_sx_lock(dict_index_get_lock(index), &mtr);
4827+
mtr_sx_lock_index(index, &mtr);
48284828
}
48294829
}
48304830

@@ -5122,13 +5122,13 @@ btr_validate_level(
51225122
/* Commit the mini-transaction to release the latch on 'page'.
51235123
Re-acquire the latch on right_page, which will become 'page'
51245124
on the next loop. The page has already been checked. */
5125-
mtr_commit(&mtr);
5125+
mtr.commit();
51265126

51275127
if (trx_is_interrupted(trx)) {
51285128
/* On interrupt, return the current status. */
51295129
} else if (right_page_no != FIL_NULL) {
51305130

5131-
mtr_start(&mtr);
5131+
mtr.start();
51325132

51335133
if (!lockout) {
51345134
if (rightmost_child) {
@@ -5178,9 +5178,9 @@ btr_validate_spatial_index(
51785178
mtr_t mtr;
51795179
bool ok = true;
51805180

5181-
mtr_start(&mtr);
5181+
mtr.start();
51825182

5183-
mtr_x_lock(dict_index_get_lock(index), &mtr);
5183+
mtr_x_lock_index(index, &mtr);
51845184

51855185
page_t* root = btr_root_get(index, &mtr);
51865186
ulint n = btr_page_get_level(root);
@@ -5200,7 +5200,7 @@ btr_validate_spatial_index(
52005200
}
52015201
}
52025202

5203-
mtr_commit(&mtr);
5203+
mtr.commit();
52045204

52055205
return(ok);
52065206
}
@@ -5236,9 +5236,9 @@ btr_validate_index(
52365236

52375237
if (!srv_read_only_mode) {
52385238
if (lockout) {
5239-
mtr_x_lock(dict_index_get_lock(index), &mtr);
5239+
mtr_x_lock_index(index, &mtr);
52405240
} else {
5241-
mtr_sx_lock(dict_index_get_lock(index), &mtr);
5241+
mtr_sx_lock_index(index, &mtr);
52425242
}
52435243
}
52445244

storage/innobase/btr/btr0bulk.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ BtrBulk::finish(dberr_t err)
10141014

10151015
mtr.start();
10161016
m_index->set_modified(mtr);
1017-
mtr_x_lock(&m_index->lock, &mtr);
1017+
mtr_x_lock_index(m_index, &mtr);
10181018

10191019
ut_ad(last_page_no != FIL_NULL);
10201020
last_block = btr_block_get(

storage/innobase/btr/btr0cur.cc

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,16 +1316,16 @@ btr_cur_search_to_nth_level_func(
13161316
if (lock_intention == BTR_INTENTION_DELETE
13171317
&& trx_sys.history_size() > BTR_CUR_FINE_HISTORY_LENGTH
13181318
&& buf_get_n_pending_read_ios()) {
1319-
mtr_x_lock(dict_index_get_lock(index), mtr);
1320-
} else if (dict_index_is_spatial(index)
1319+
x_latch_index:
1320+
mtr_x_lock_index(index, mtr);
1321+
} else if (index->is_spatial()
13211322
&& lock_intention <= BTR_INTENTION_BOTH) {
13221323
/* X lock the if there is possibility of
13231324
pessimistic delete on spatial index. As we could
13241325
lock upward for the tree */
1325-
1326-
mtr_x_lock(dict_index_get_lock(index), mtr);
1326+
goto x_latch_index;
13271327
} else {
1328-
mtr_sx_lock(dict_index_get_lock(index), mtr);
1328+
mtr_sx_lock_index(index, mtr);
13291329
}
13301330
upper_rw_latch = RW_X_LATCH;
13311331
break;
@@ -1357,10 +1357,10 @@ btr_cur_search_to_nth_level_func(
13571357
BTR_ALREADY_S_LATCHED */
13581358
ut_ad(latch_mode != BTR_SEARCH_TREE);
13591359

1360-
mtr_s_lock(dict_index_get_lock(index), mtr);
1360+
mtr_s_lock_index(index, mtr);
13611361
} else {
13621362
/* BTR_MODIFY_EXTERNAL needs to be excluded */
1363-
mtr_sx_lock(dict_index_get_lock(index), mtr);
1363+
mtr_sx_lock_index(index, mtr);
13641364
}
13651365
upper_rw_latch = RW_S_LATCH;
13661366
} else {
@@ -2450,9 +2450,9 @@ btr_cur_open_at_index_side_func(
24502450
if (lock_intention == BTR_INTENTION_DELETE
24512451
&& trx_sys.history_size() > BTR_CUR_FINE_HISTORY_LENGTH
24522452
&& buf_get_n_pending_read_ios()) {
2453-
mtr_x_lock(dict_index_get_lock(index), mtr);
2453+
mtr_x_lock_index(index, mtr);
24542454
} else {
2455-
mtr_sx_lock(dict_index_get_lock(index), mtr);
2455+
mtr_sx_lock_index(index, mtr);
24562456
}
24572457
upper_rw_latch = RW_X_LATCH;
24582458
break;
@@ -2468,7 +2468,7 @@ btr_cur_open_at_index_side_func(
24682468
BTR_ALREADY_S_LATCHED */
24692469
ut_ad(latch_mode != BTR_SEARCH_TREE);
24702470

2471-
mtr_s_lock(dict_index_get_lock(index), mtr);
2471+
mtr_s_lock_index(index, mtr);
24722472
}
24732473
upper_rw_latch = RW_S_LATCH;
24742474
} else {
@@ -2779,7 +2779,7 @@ btr_cur_open_at_rnd_pos_func(
27792779
ulint* offsets = offsets_;
27802780
rec_offs_init(offsets_);
27812781

2782-
ut_ad(!dict_index_is_spatial(index));
2782+
ut_ad(!index->is_spatial());
27832783

27842784
lock_intention = btr_cur_get_and_clear_intention(&latch_mode);
27852785

@@ -2795,9 +2795,9 @@ btr_cur_open_at_rnd_pos_func(
27952795
if (lock_intention == BTR_INTENTION_DELETE
27962796
&& trx_sys.history_size() > BTR_CUR_FINE_HISTORY_LENGTH
27972797
&& buf_get_n_pending_read_ios()) {
2798-
mtr_x_lock(dict_index_get_lock(index), mtr);
2798+
mtr_x_lock_index(index, mtr);
27992799
} else {
2800-
mtr_sx_lock(dict_index_get_lock(index), mtr);
2800+
mtr_sx_lock_index(index, mtr);
28012801
}
28022802
upper_rw_latch = RW_X_LATCH;
28032803
break;
@@ -2813,7 +2813,7 @@ btr_cur_open_at_rnd_pos_func(
28132813
/* fall through */
28142814
default:
28152815
if (!srv_read_only_mode) {
2816-
mtr_s_lock(dict_index_get_lock(index), mtr);
2816+
mtr_s_lock_index(index, mtr);
28172817
upper_rw_latch = RW_S_LATCH;
28182818
} else {
28192819
upper_rw_latch = RW_NO_LATCH;
@@ -4892,7 +4892,7 @@ btr_cur_pessimistic_update(
48924892
MTR_MEMO_X_LOCK |
48934893
MTR_MEMO_SX_LOCK));
48944894

4895-
mtr_sx_lock(dict_index_get_lock(index), mtr);
4895+
mtr_sx_lock_index(index, mtr);
48964896
}
48974897

48984898
/* Was the record to be updated positioned as the first user

storage/innobase/btr/btr0defragment.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ DECLARE_THREAD(btr_defragment_thread)(void*)
751751
index->set_modified(mtr);
752752
/* To follow the latching order defined in WL#6326, acquire index->lock X-latch.
753753
This entitles us to acquire page latches in any order for the index. */
754-
mtr_x_lock(&index->lock, &mtr);
754+
mtr_x_lock_index(index, &mtr);
755755
/* This will acquire index->lock SX-latch, which per WL#6363 is allowed
756756
when we are already holding the X-latch. */
757757
btr_pcur_restore_position(BTR_MODIFY_TREE, pcur, &mtr);

storage/innobase/btr/btr0scrub.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ btr_scrub_recheck_page(
742742
}
743743

744744
mtr_start(mtr);
745-
mtr_x_lock(dict_index_get_lock(scrub_data->current_index), mtr);
745+
mtr_x_lock_index(scrub_data->current_index, mtr);
746746
/** set savepoint for X-latch of block */
747747
scrub_data->savepoint = mtr_set_savepoint(mtr);
748748
return BTR_SCRUB_PAGE;

storage/innobase/dict/dict0defrag_bg.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,11 @@ dict_stats_save_defrag_stats(
281281
mtr_t mtr;
282282
ulint n_leaf_pages;
283283
ulint n_leaf_reserved;
284-
mtr_start(&mtr);
285-
mtr_s_lock(dict_index_get_lock(index), &mtr);
284+
mtr.start();
285+
mtr_s_lock_index(index, &mtr);
286286
n_leaf_reserved = btr_get_size_and_reserved(index, BTR_N_LEAF_PAGES,
287287
&n_leaf_pages, &mtr);
288-
mtr_commit(&mtr);
288+
mtr.commit();
289289

290290
if (n_leaf_reserved == ULINT_UNDEFINED) {
291291
// The index name is different during fast index creation,

storage/innobase/dict/dict0stats.cc

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -854,10 +854,8 @@ dict_stats_update_transient_for_index(
854854
mtr_t mtr;
855855
ulint size;
856856

857-
mtr_start(&mtr);
858-
859-
mtr_s_lock(dict_index_get_lock(index), &mtr);
860-
857+
mtr.start();
858+
mtr_s_lock_index(index, &mtr);
861859
size = btr_get_size(index, BTR_TOTAL_SIZE, &mtr);
862860

863861
if (size != ULINT_UNDEFINED) {
@@ -867,7 +865,7 @@ dict_stats_update_transient_for_index(
867865
index, BTR_N_LEAF_PAGES, &mtr);
868866
}
869867

870-
mtr_commit(&mtr);
868+
mtr.commit();
871869

872870
switch (size) {
873871
case ULINT_UNDEFINED:
@@ -1929,10 +1927,8 @@ dict_stats_analyze_index(
19291927

19301928
dict_stats_empty_index(index, false);
19311929

1932-
mtr_start(&mtr);
1933-
1934-
mtr_s_lock(dict_index_get_lock(index), &mtr);
1935-
1930+
mtr.start();
1931+
mtr_s_lock_index(index, &mtr);
19361932
size = btr_get_size(index, BTR_TOTAL_SIZE, &mtr);
19371933

19381934
if (size != ULINT_UNDEFINED) {
@@ -1941,7 +1937,7 @@ dict_stats_analyze_index(
19411937
}
19421938

19431939
/* Release the X locks on the root page taken by btr_get_size() */
1944-
mtr_commit(&mtr);
1940+
mtr.commit();
19451941

19461942
switch (size) {
19471943
case ULINT_UNDEFINED:
@@ -1954,10 +1950,8 @@ dict_stats_analyze_index(
19541950

19551951
index->stat_n_leaf_pages = size;
19561952

1957-
mtr_start(&mtr);
1958-
1959-
mtr_sx_lock(dict_index_get_lock(index), &mtr);
1960-
1953+
mtr.start();
1954+
mtr_sx_lock_index(index, &mtr);
19611955
root_level = btr_height_get(index, &mtr);
19621956

19631957
n_uniq = dict_index_get_n_unique(index);
@@ -1997,7 +1991,7 @@ dict_stats_analyze_index(
19971991
index->stat_n_sample_sizes[i] = total_pages;
19981992
}
19991993

2000-
mtr_commit(&mtr);
1994+
mtr.commit();
20011995

20021996
dict_stats_assert_initialized_index(index);
20031997
DBUG_VOID_RETURN;
@@ -2043,9 +2037,9 @@ dict_stats_analyze_index(
20432037

20442038
/* Commit the mtr to release the tree S lock to allow
20452039
other threads to do some work too. */
2046-
mtr_commit(&mtr);
2047-
mtr_start(&mtr);
2048-
mtr_sx_lock(dict_index_get_lock(index), &mtr);
2040+
mtr.commit();
2041+
mtr.start();
2042+
mtr_sx_lock_index(index, &mtr);
20492043
if (root_level != btr_height_get(index, &mtr)) {
20502044
/* Just quit if the tree has changed beyond
20512045
recognition here. The old stats from previous
@@ -2183,7 +2177,7 @@ dict_stats_analyze_index(
21832177
data, &mtr);
21842178
}
21852179

2186-
mtr_commit(&mtr);
2180+
mtr.commit();
21872181

21882182
UT_DELETE_ARRAY(n_diff_boundaries);
21892183

storage/innobase/fsp/fsp0fsp.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ void fsp_header_init(fil_space_t* space, ulint size, mtr_t* mtr)
657657
const page_id_t page_id(space->id, 0);
658658
const page_size_t page_size(space->flags);
659659

660-
mtr_x_lock(&space->latch, mtr);
660+
mtr_x_lock_space(space, mtr);
661661
buf_block_t* block = buf_page_create(page_id, page_size, mtr);
662662
buf_page_get(page_id, page_size, RW_SX_LATCH, mtr);
663663
buf_block_dbg_add_level(block, SYNC_FSP_PAGE);
@@ -1944,7 +1944,7 @@ fseg_create(
19441944
ut_ad(byte_offset + FSEG_HEADER_SIZE
19451945
<= srv_page_size - FIL_PAGE_DATA_END);
19461946

1947-
mtr_x_lock(&space->latch, mtr);
1947+
mtr_x_lock_space(space, mtr);
19481948
const page_size_t page_size(space->flags);
19491949
ut_d(space->modify_check(*mtr));
19501950

@@ -2649,7 +2649,7 @@ fsp_reserve_free_extents(
26492649
ut_ad(mtr);
26502650
*n_reserved = n_ext;
26512651

2652-
mtr_x_lock(&space->latch, mtr);
2652+
mtr_x_lock_space(space, mtr);
26532653
const page_size_t page_size(space->flags);
26542654

26552655
space_header = fsp_get_space_header(space, page_size, mtr);
@@ -2940,7 +2940,7 @@ fseg_free_page_func(
29402940
DBUG_ENTER("fseg_free_page");
29412941
fseg_inode_t* seg_inode;
29422942
buf_block_t* iblock;
2943-
mtr_x_lock(&space->latch, mtr);
2943+
mtr_x_lock_space(space, mtr);
29442944
const page_size_t page_size(space->flags);
29452945

29462946
DBUG_LOG("fseg_free_page", "space_id: " << space->id
@@ -2970,7 +2970,7 @@ fseg_page_is_free(fil_space_t* space, unsigned page)
29702970
page_no_t dpage = xdes_calc_descriptor_page(page_size, page);
29712971

29722972
mtr.start();
2973-
mtr_s_lock(&space->latch, &mtr);
2973+
mtr_s_lock_space(space, &mtr);
29742974

29752975
if (page >= space->free_limit || page >= space->size_in_header) {
29762976
is_free = true;

storage/innobase/gis/gis0rtree.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1846,7 +1846,7 @@ rtr_estimate_n_rows_in_range(
18461846

18471847
mtr.start();
18481848
index->set_modified(mtr);
1849-
mtr_s_lock(&index->lock, &mtr);
1849+
mtr_s_lock_index(index, &mtr);
18501850

18511851
buf_block_t* block = btr_block_get(
18521852
page_id_t(index->table->space_id, index->page),

storage/innobase/gis/gis0sea.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ rtr_pcur_getnext_from_path(
137137
if (!index_locked) {
138138
ut_ad(latch_mode & BTR_SEARCH_LEAF
139139
|| latch_mode & BTR_MODIFY_LEAF);
140-
mtr_s_lock(dict_index_get_lock(index), mtr);
140+
mtr_s_lock_index(index, mtr);
141141
} else {
142142
ut_ad(mtr_memo_contains_flagged(mtr, &index->lock,
143143
MTR_MEMO_SX_LOCK

0 commit comments

Comments
 (0)