Skip to content

Commit 572e53d

Browse files
MDEV-22931 mtr_t::mtr_t() allocates some memory
mtr_t::m_freed_pages: Renamed from m_freed_ranges and made it as pointer indirection. mtr_t::add_freed_offset(): Allocates m_freed_pages. mtr_t:clear_freed_ranges(): Removed. mtr_t::init(): Added debug assertion to check whether m_freed_pages is not yet initialized. btr_page_alloc_low(): Remove #ifdef UNIV_DEBUG_SCRUBBING. mtr_t::commit(): Delete m_freed_pages, reset m_trim_pages and m_freed_in_system_tablespace. fil_space_t::clear_freed_ranges(): Added a comment to explain how undo log tablespaces uses it.
1 parent 451bd32 commit 572e53d

File tree

5 files changed

+21
-42
lines changed

5 files changed

+21
-42
lines changed

storage/innobase/btr/btr0btr.cc

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -537,22 +537,6 @@ btr_page_alloc_low(
537537
seg_header, hint_page_no, file_direction,
538538
true, mtr, init_mtr);
539539

540-
#ifdef UNIV_DEBUG_SCRUBBING
541-
if (block != NULL) {
542-
fprintf(stderr,
543-
"alloc %lu:%lu to index: %lu root: %lu\n",
544-
buf_block_get_page_no(block),
545-
buf_block_get_space(block),
546-
index->id,
547-
dict_index_get_page(index));
548-
} else {
549-
fprintf(stderr,
550-
"failed alloc index: %lu root: %lu\n",
551-
index->id,
552-
dict_index_get_page(index));
553-
}
554-
#endif /* UNIV_DEBUG_SCRUBBING */
555-
556540
return block;
557541
}
558542

storage/innobase/include/fil0fil.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,8 @@ struct fil_space_t
502502
last_freed_lsn= lsn;
503503
}
504504

505-
/** Clear all freed ranges */
505+
/** Clear all freed ranges for undo tablespace when InnoDB
506+
encounters TRIM redo log record */
506507
void clear_freed_ranges()
507508
{
508509
std::lock_guard<std::mutex> freed_lock(freed_range_mutex);

storage/innobase/include/mtr0log.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ inline void mtr_t::memcpy(const buf_block_t &b, void *dest, const void *str,
511511
@param[in,out] b buffer page */
512512
inline void mtr_t::init(buf_block_t *b)
513513
{
514+
ut_ad(!m_freed_pages);
514515
b->page.status= buf_page_t::INIT_ON_FLUSH;
515516

516517
if (m_log_mode != MTR_LOG_ALL)

storage/innobase/include/mtr0mtr.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -580,16 +580,11 @@ struct mtr_t {
580580
void add_freed_offset(page_id_t id)
581581
{
582582
ut_ad(m_user_space == NULL || id.space() == m_user_space->id);
583-
m_freed_ranges.add_value(id.page_no());
583+
if (!m_freed_pages)
584+
m_freed_pages= new range_set();
585+
m_freed_pages->add_value(id.page_no());
584586
}
585587

586-
/** Clear the freed pages */
587-
void clear_freed_ranges()
588-
{
589-
m_freed_ranges.clear();
590-
m_freed_in_system_tablespace= 0;
591-
m_trim_pages= false;
592-
}
593588
private:
594589
/** Log a write of a byte string to a page.
595590
@param block buffer page
@@ -685,7 +680,7 @@ struct mtr_t {
685680
lsn_t m_commit_lsn;
686681

687682
/** set of freed page ids */
688-
range_set m_freed_ranges;
683+
range_set *m_freed_pages= nullptr;
689684
};
690685

691686
#include "mtr0mtr.ic"

storage/innobase/mtr/mtr0mtr.cc

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,8 @@ struct mtr_write_log_t {
354354
/** Start a mini-transaction. */
355355
void mtr_t::start()
356356
{
357-
#ifdef HAVE_valgrind_or_MSAN
358-
char m_freed_ranges_vbits[sizeof m_freed_ranges];
359-
#endif
360-
MEM_GET_VBITS(&m_freed_ranges, m_freed_ranges_vbits, sizeof m_freed_ranges);
361357
UNIV_MEM_INVALID(this, sizeof *this);
362-
MEM_SET_VBITS(&m_freed_ranges, m_freed_ranges_vbits, sizeof m_freed_ranges);
358+
UNIV_MEM_VALID(&m_freed_pages, sizeof(m_freed_pages));
363359

364360
ut_d(m_start= true);
365361
ut_d(m_commit= false);
@@ -378,6 +374,7 @@ void mtr_t::start()
378374
m_user_space= nullptr;
379375
m_commit_lsn= 0;
380376
m_freed_in_system_tablespace= m_trim_pages= false;
377+
ut_ad(!m_freed_pages);
381378
}
382379

383380
/** Release the resources */
@@ -387,7 +384,6 @@ inline void mtr_t::release_resources()
387384
ut_d(m_memo.for_each_block_in_reverse(CIterate<DebugCheck>()));
388385
m_log.erase();
389386
m_memo.erase();
390-
clear_freed_ranges();
391387
ut_d(m_commit= true);
392388
}
393389

@@ -420,8 +416,9 @@ void mtr_t::commit()
420416
to insert into the flush list. */
421417
log_mutex_exit();
422418

423-
if (!m_freed_ranges.empty())
419+
if (m_freed_pages)
424420
{
421+
ut_ad(!m_freed_pages->empty());
425422
fil_space_t *freed_space= m_user_space;
426423
/* Get the freed tablespace in case of predefined tablespace */
427424
if (!freed_space)
@@ -434,14 +431,15 @@ void mtr_t::commit()
434431
/* Update the last freed lsn */
435432
freed_space->update_last_freed_lsn(m_commit_lsn);
436433

437-
for (const auto &range : m_freed_ranges)
438-
freed_space->add_free_range(range);
439-
}
440-
441-
if (is_trim_pages())
442-
{
443-
ut_ad(m_user_space != nullptr);
444-
m_user_space->clear_freed_ranges();
434+
if (!is_trim_pages())
435+
for (const auto &range : *m_freed_pages)
436+
freed_space->add_free_range(range);
437+
else
438+
freed_space->clear_freed_ranges();
439+
delete m_freed_pages;
440+
m_freed_pages= nullptr;
441+
/* Reset of m_trim_pages and m_freed_in_system_tablespace
442+
happens in mtr_t::start() */
445443
}
446444

447445
m_memo.for_each_block_in_reverse(CIterate<const ReleaseBlocks>
@@ -472,7 +470,7 @@ void mtr_t::commit_files(lsn_t checkpoint_lsn)
472470
ut_ad(!m_made_dirty);
473471
ut_ad(m_memo.size() == 0);
474472
ut_ad(!srv_read_only_mode);
475-
ut_ad(m_freed_ranges.empty());
473+
ut_ad(!m_freed_pages);
476474
ut_ad(!m_freed_in_system_tablespace);
477475

478476
if (checkpoint_lsn) {

0 commit comments

Comments
 (0)