Skip to content

Commit a032f14

Browse files
committed
MDEV-33559 matched_rec::block should be allocated from the buffer pool
matched_rec::rec_buf[], matched_rec::bufp: Remove. matched_rec::block: Make this a pointer to something that is allocated by buf_block_alloc(). In this way, the only case where buf_block_t is constructed outside buf_pool is ALTER TABLE...IMPORT TABLESPACE. rtr_info::heap: Remove. This was only used for allocating matched_rec, which now is smaller. mtr_t::memmove(): Simplify some code to avoid GCC 9.4.0 -Wconversion in the 10.6 branch as a result of these changes. Reviewed by: Debarun Banerjee
1 parent ea810b0 commit a032f14

File tree

4 files changed

+36
-86
lines changed

4 files changed

+36
-86
lines changed

storage/innobase/gis/gis0sea.cc

Lines changed: 17 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ rtr_pcur_move_to_next(
498498
mutex_exit(&rtr_info->matches->rtr_match_mutex);
499499

500500
cursor->btr_cur.page_cur.rec = rec.r_rec;
501-
cursor->btr_cur.page_cur.block = &rtr_info->matches->block;
501+
cursor->btr_cur.page_cur.block = rtr_info->matches->block;
502502

503503
DEBUG_SYNC_C("rtr_pcur_move_to_next_return");
504504
return(true);
@@ -939,22 +939,14 @@ rtr_create_rtr_info(
939939
rtr_info->index = index;
940940

941941
if (init_matches) {
942-
rtr_info->heap = mem_heap_create(sizeof(*(rtr_info->matches)));
943942
rtr_info->matches = static_cast<matched_rec_t*>(
944-
mem_heap_zalloc(
945-
rtr_info->heap,
946-
sizeof(*rtr_info->matches)));
943+
ut_zalloc_nokey(sizeof *rtr_info->matches));
947944

948945
rtr_info->matches->matched_recs
949946
= UT_NEW_NOKEY(rtr_rec_vector());
950947

951-
rtr_info->matches->bufp = page_align(rtr_info->matches->rec_buf
952-
+ UNIV_PAGE_SIZE_MAX + 1);
953948
mutex_create(LATCH_ID_RTR_MATCH_MUTEX,
954949
&rtr_info->matches->rtr_match_mutex);
955-
rw_lock_create(PFS_NOT_INSTRUMENTED,
956-
&(rtr_info->matches->block.lock),
957-
SYNC_LEVEL_VARYING);
958950
}
959951

960952
rtr_info->path = UT_NEW_NOKEY(rtr_node_path_t());
@@ -1016,7 +1008,6 @@ rtr_init_rtr_info(
10161008
rtr_info->mbr.ymin = 0.0;
10171009
rtr_info->mbr.ymax = 0.0;
10181010
rtr_info->thr = NULL;
1019-
rtr_info->heap = NULL;
10201011
rtr_info->cursor = NULL;
10211012
rtr_info->index = NULL;
10221013
rtr_info->need_prdt_lock = false;
@@ -1095,17 +1086,15 @@ rtr_clean_rtr_info(
10951086

10961087
if (free_all) {
10971088
if (rtr_info->matches) {
1098-
if (rtr_info->matches->matched_recs != NULL) {
1099-
UT_DELETE(rtr_info->matches->matched_recs);
1089+
if (rtr_info->matches->block) {
1090+
buf_block_free(rtr_info->matches->block);
1091+
rtr_info->matches->block = nullptr;
11001092
}
11011093

1102-
rw_lock_free(&(rtr_info->matches->block.lock));
1094+
UT_DELETE(rtr_info->matches->matched_recs);
11031095

11041096
mutex_destroy(&rtr_info->matches->rtr_match_mutex);
1105-
}
1106-
1107-
if (rtr_info->heap) {
1108-
mem_heap_free(rtr_info->heap);
1097+
ut_free(rtr_info->matches);
11091098
}
11101099

11111100
if (initialized) {
@@ -1215,7 +1204,7 @@ rtr_check_discard_page(
12151204
if (rtr_info->matches) {
12161205
mutex_enter(&rtr_info->matches->rtr_match_mutex);
12171206

1218-
if ((&rtr_info->matches->block)->page.id().page_no()
1207+
if (rtr_info->matches->block->page.id().page_no()
12191208
== pageno) {
12201209
if (!rtr_info->matches->matched_recs->empty()) {
12211210
rtr_info->matches->matched_recs->clear();
@@ -1425,7 +1414,7 @@ rtr_leaf_push_match_rec(
14251414
ulint data_len;
14261415
rtr_rec_trtr_rec;
14271416

1428-
buf = match_rec->block.frame + match_rec->used;
1417+
buf = match_rec->block->frame + match_rec->used;
14291418
ut_ad(page_rec_is_leaf(rec));
14301419

14311420
copy = rec_copy(buf, rec, offsets);
@@ -1522,43 +1511,6 @@ rtr_non_leaf_insert_stack_push(
15221511
new_seq, level, child_no, my_cursor, mbr_inc);
15231512
}
15241513

1525-
/** Copy a buf_block_t, except "block->lock".
1526-
@param[in,out] matches copy to match->block
1527-
@param[in] block block to copy */
1528-
static
1529-
void
1530-
rtr_copy_buf(
1531-
matched_rec_t* matches,
1532-
const buf_block_t* block)
1533-
{
1534-
/* Copy all members of "block" to "matches->block" except "lock".
1535-
We skip "lock" because it is not used
1536-
from the dummy buf_block_t we create here and because memcpy()ing
1537-
it generates (valid) compiler warnings that the vtable pointer
1538-
will be copied. */
1539-
new (&matches->block.page) buf_page_t(block->page);
1540-
matches->block.frame = block->frame;
1541-
matches->block.unzip_LRU = block->unzip_LRU;
1542-
1543-
ut_d(matches->block.in_unzip_LRU_list = block->in_unzip_LRU_list);
1544-
ut_d(matches->block.in_withdraw_list = block->in_withdraw_list);
1545-
1546-
/* Skip buf_block_t::lock */
1547-
matches->block.modify_clock = block->modify_clock;
1548-
#ifdef BTR_CUR_HASH_ADAPT
1549-
matches->block.n_hash_helps = block->n_hash_helps;
1550-
matches->block.n_fields = block->n_fields;
1551-
matches->block.left_side = block->left_side;
1552-
#if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
1553-
matches->block.n_pointers = 0;
1554-
#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
1555-
matches->block.curr_n_fields = block->curr_n_fields;
1556-
matches->block.curr_left_side = block->curr_left_side;
1557-
matches->block.index = block->index;
1558-
#endif /* BTR_CUR_HASH_ADAPT */
1559-
ut_d(matches->block.debug_latch = NULL);
1560-
}
1561-
15621514
/****************************************************************//**
15631515
Generate a shadow copy of the page block header to save the
15641516
matched records */
@@ -1572,17 +1524,18 @@ rtr_init_match(
15721524
{
15731525
ut_ad(matches->matched_recs->empty());
15741526
matches->locked = false;
1575-
rtr_copy_buf(matches, block);
1576-
matches->block.frame = matches->bufp;
15771527
matches->valid = false;
1578-
/* We have to copy PAGE_W*_SUPREMUM_END bytes so that we can
1528+
if (!matches->block) {
1529+
matches->block = buf_block_alloc();
1530+
}
1531+
1532+
matches->block->page.init(block->page.id());
1533+
/* We have to copy PAGE_*_SUPREMUM_END bytes so that we can
15791534
use infimum/supremum of this page as normal btr page for search. */
1580-
memcpy(matches->block.frame, page, page_is_comp(page)
1581-
? PAGE_NEW_SUPREMUM_END
1582-
: PAGE_OLD_SUPREMUM_END);
15831535
matches->used = page_is_comp(page)
15841536
? PAGE_NEW_SUPREMUM_END
15851537
: PAGE_OLD_SUPREMUM_END;
1538+
memcpy(matches->block->frame, page, matches->used);
15861539
#ifdef RTR_SEARCH_DIAGNOSTIC
15871540
ulint pageno = page_get_page_no(page);
15881541
fprintf(stderr, "INNODB_RTR: Searching leaf page %d\n",
@@ -2002,7 +1955,7 @@ rtr_cur_search_with_match(
20021955
#endif /* UNIV_DEBUG */
20031956
/* Pop the last match record and position on it */
20041957
match_rec->matched_recs->pop_back();
2005-
page_cur_position(test_rec.r_rec, &match_rec->block,
1958+
page_cur_position(test_rec.r_rec, match_rec->block,
20061959
cursor);
20071960
}
20081961
} else {

storage/innobase/include/gis0type.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ typedef std::vector<rtr_rec_t, ut_allocator<rtr_rec_t> > rtr_rec_vector;
6666

6767
/* Structure for matched records on the leaf page */
6868
typedefstruct matched_rec {
69-
byte* bufp;/*!< aligned buffer point */
70-
byte rec_buf[UNIV_PAGE_SIZE_MAX * 2];
71-
/*!< buffer used to copy matching rec */
72-
buf_block_tblock;/*!< the shadow buffer block */
69+
buf_block_t* block;/*!< the shadow buffer block */
7370
ulint used;/*!< memory used */
7471
rtr_rec_vector* matched_recs;/*!< vector holding the matching rec */
7572
ib_mutex_trtr_match_mutex;/*!< mutex protect the match_recs
@@ -113,7 +110,6 @@ typedef struct rtr_info{
113110
on each level and leaf level */
114111
rtr_mbr_tmbr;/*!< the search MBR */
115112
que_thr_t* thr;/*!< the search thread */
116-
mem_heap_t* heap;/*!< memory heap */
117113
btr_cur_t* cursor;/*!< cursor used for search */
118114
dict_index_t* index;/*!< index it is searching */
119115
boolneed_prdt_lock;

storage/innobase/include/mtr0log.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -347,29 +347,30 @@ inline void mtr_t::memmove(const buf_block_t &b, ulint d, ulint s, ulint len)
347347
ut_ad(d >= 8);
348348
ut_ad(s >= 8);
349349
ut_ad(len);
350-
ut_ad(s <= ulint(srv_page_size));
351-
ut_ad(s + len <= ulint(srv_page_size));
350+
ut_d(const ulint ps= srv_page_size);
351+
ut_ad(s <= ps);
352+
ut_ad(s + len <= ps);
352353
ut_ad(s != d);
353-
ut_ad(d <= ulint(srv_page_size));
354-
ut_ad(d + len <= ulint(srv_page_size));
354+
ut_ad(d <= ps);
355+
ut_ad(d + len <= ps);
355356

356357
set_modified(b);
357358
if (m_log_mode != MTR_LOG_ALL)
358359
return;
359360
static_assert(MIN_4BYTE > UNIV_PAGE_SIZE_MAX, "consistency");
360361
size_t lenlen= (len < MIN_2BYTE ? 1 : len < MIN_3BYTE ? 2 : 3);
361362
/* The source offset is encoded relative to the destination offset,
362-
with the sign in the least significant bit. */
363-
if (s > d)
364-
s= (s - d) << 1;
365-
else
366-
s= (d - s) << 1 | 1;
363+
with the sign in the least significant bit.
364+
Because the source offset 0 is not possible, our encoding
365+
subtracts 1 from the offset. */
366+
const uint16_t S= s > d
367+
? uint16_t((s - d - 1) << 1)
368+
: uint16_t((d - s - 1) << 1 | 1);
367369
/* The source offset 0 is not possible. */
368-
s-= 1 << 1;
369-
size_t slen= (s < MIN_2BYTE ? 1 : s < MIN_3BYTE ? 2 : 3);
370+
size_t slen= (S < MIN_2BYTE ? 1 : S < MIN_3BYTE ? 2 : 3);
370371
byte *l= log_write<MEMMOVE>(b.page.id(), &b.page, lenlen + slen, true, d);
371372
l= mlog_encode_varint(l, len);
372-
l= mlog_encode_varint(l, s);
373+
l= mlog_encode_varint(l, S);
373374
m_log.close(l);
374375
m_last_offset= static_cast<uint16_t>(d + len);
375376
}

storage/innobase/row/row0sel.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,10 +1151,10 @@ sel_set_rtr_rec_lock(
11511151
ut_ad(page_align(first_rec) == cur_block->frame);
11521152
ut_ad(match->valid);
11531153

1154-
rw_lock_x_lock(&(match->block.lock));
1154+
rw_lock_x_lock(&match->block->lock);
11551155
retry:
11561156
cur_block = btr_pcur_get_block(pcur);
1157-
ut_ad(rw_lock_own_flagged(&match->block.lock,
1157+
ut_ad(rw_lock_own_flagged(&match->block->lock,
11581158
RW_LOCK_FLAG_X | RW_LOCK_FLAG_S));
11591159
ut_ad(page_is_leaf(buf_block_get_frame(cur_block)));
11601160

@@ -1255,7 +1255,7 @@ sel_set_rtr_rec_lock(
12551255
ULINT_UNDEFINED, &heap);
12561256

12571257
err = lock_sec_rec_read_check_and_lock(
1258-
0, &match->block, rtr_rec->r_rec, index,
1258+
0, match->block, rtr_rec->r_rec, index,
12591259
my_offsets, static_cast<lock_mode>(mode),
12601260
type, thr);
12611261

@@ -1271,7 +1271,7 @@ sel_set_rtr_rec_lock(
12711271
match->locked = true;
12721272

12731273
func_end:
1274-
rw_lock_x_unlock(&(match->block.lock));
1274+
rw_lock_x_unlock(&match->block->lock);
12751275
if (heap != NULL) {
12761276
mem_heap_free(heap);
12771277
}
@@ -3352,7 +3352,7 @@ Row_sel_get_clust_rec_for_mysql::operator()(
33523352
if (dict_index_is_spatial(sec_index)
33533353
&& btr_cur->rtr_info->matches
33543354
&& (page_align(rec)
3355-
== btr_cur->rtr_info->matches->block.frame
3355+
== btr_cur->rtr_info->matches->block->frame
33563356
|| rec != btr_pcur_get_rec(prebuilt->pcur))) {
33573357
#ifdef UNIV_DEBUG
33583358
rtr_info_t* rtr_info = btr_cur->rtr_info;

0 commit comments

Comments
 (0)