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.
parent 451bd326
...@@ -537,22 +537,6 @@ btr_page_alloc_low( ...@@ -537,22 +537,6 @@ btr_page_alloc_low(
seg_header, hint_page_no, file_direction, seg_header, hint_page_no, file_direction,
true, mtr, init_mtr); true, mtr, init_mtr);
#ifdef UNIV_DEBUG_SCRUBBING
if (block != NULL) {
fprintf(stderr,
"alloc %lu:%lu to index: %lu root: %lu\n",
buf_block_get_page_no(block),
buf_block_get_space(block),
index->id,
dict_index_get_page(index));
} else {
fprintf(stderr,
"failed alloc index: %lu root: %lu\n",
index->id,
dict_index_get_page(index));
}
#endif /* UNIV_DEBUG_SCRUBBING */
return block; return block;
} }
......
...@@ -502,7 +502,8 @@ struct fil_space_t ...@@ -502,7 +502,8 @@ struct fil_space_t
last_freed_lsn= lsn; last_freed_lsn= lsn;
} }
/** Clear all freed ranges */ /** Clear all freed ranges for undo tablespace when InnoDB
encounters TRIM redo log record */
void clear_freed_ranges() void clear_freed_ranges()
{ {
std::lock_guard<std::mutex> freed_lock(freed_range_mutex); std::lock_guard<std::mutex> freed_lock(freed_range_mutex);
......
...@@ -511,6 +511,7 @@ inline void mtr_t::memcpy(const buf_block_t &b, void *dest, const void *str, ...@@ -511,6 +511,7 @@ inline void mtr_t::memcpy(const buf_block_t &b, void *dest, const void *str,
@param[in,out] b buffer page */ @param[in,out] b buffer page */
inline void mtr_t::init(buf_block_t *b) inline void mtr_t::init(buf_block_t *b)
{ {
ut_ad(!m_freed_pages);
b->page.status= buf_page_t::INIT_ON_FLUSH; b->page.status= buf_page_t::INIT_ON_FLUSH;
if (m_log_mode != MTR_LOG_ALL) if (m_log_mode != MTR_LOG_ALL)
......
...@@ -580,16 +580,11 @@ struct mtr_t { ...@@ -580,16 +580,11 @@ struct mtr_t {
void add_freed_offset(page_id_t id) void add_freed_offset(page_id_t id)
{ {
ut_ad(m_user_space == NULL || id.space() == m_user_space->id); ut_ad(m_user_space == NULL || id.space() == m_user_space->id);
m_freed_ranges.add_value(id.page_no()); if (!m_freed_pages)
m_freed_pages= new range_set();
m_freed_pages->add_value(id.page_no());
} }
/** Clear the freed pages */
void clear_freed_ranges()
{
m_freed_ranges.clear();
m_freed_in_system_tablespace= 0;
m_trim_pages= false;
}
private: private:
/** Log a write of a byte string to a page. /** Log a write of a byte string to a page.
@param block buffer page @param block buffer page
...@@ -685,7 +680,7 @@ struct mtr_t { ...@@ -685,7 +680,7 @@ struct mtr_t {
lsn_t m_commit_lsn; lsn_t m_commit_lsn;
/** set of freed page ids */ /** set of freed page ids */
range_set m_freed_ranges; range_set *m_freed_pages= nullptr;
}; };
#include "mtr0mtr.ic" #include "mtr0mtr.ic"
......
...@@ -354,12 +354,8 @@ struct mtr_write_log_t { ...@@ -354,12 +354,8 @@ struct mtr_write_log_t {
/** Start a mini-transaction. */ /** Start a mini-transaction. */
void mtr_t::start() void mtr_t::start()
{ {
#ifdef HAVE_valgrind_or_MSAN
char m_freed_ranges_vbits[sizeof m_freed_ranges];
#endif
MEM_GET_VBITS(&m_freed_ranges, m_freed_ranges_vbits, sizeof m_freed_ranges);
UNIV_MEM_INVALID(this, sizeof *this); UNIV_MEM_INVALID(this, sizeof *this);
MEM_SET_VBITS(&m_freed_ranges, m_freed_ranges_vbits, sizeof m_freed_ranges); UNIV_MEM_VALID(&m_freed_pages, sizeof(m_freed_pages));
ut_d(m_start= true); ut_d(m_start= true);
ut_d(m_commit= false); ut_d(m_commit= false);
...@@ -378,6 +374,7 @@ void mtr_t::start() ...@@ -378,6 +374,7 @@ void mtr_t::start()
m_user_space= nullptr; m_user_space= nullptr;
m_commit_lsn= 0; m_commit_lsn= 0;
m_freed_in_system_tablespace= m_trim_pages= false; m_freed_in_system_tablespace= m_trim_pages= false;
ut_ad(!m_freed_pages);
} }
/** Release the resources */ /** Release the resources */
...@@ -387,7 +384,6 @@ inline void mtr_t::release_resources() ...@@ -387,7 +384,6 @@ inline void mtr_t::release_resources()
ut_d(m_memo.for_each_block_in_reverse(CIterate<DebugCheck>())); ut_d(m_memo.for_each_block_in_reverse(CIterate<DebugCheck>()));
m_log.erase(); m_log.erase();
m_memo.erase(); m_memo.erase();
clear_freed_ranges();
ut_d(m_commit= true); ut_d(m_commit= true);
} }
...@@ -420,8 +416,9 @@ void mtr_t::commit() ...@@ -420,8 +416,9 @@ void mtr_t::commit()
to insert into the flush list. */ to insert into the flush list. */
log_mutex_exit(); log_mutex_exit();
if (!m_freed_ranges.empty()) if (m_freed_pages)
{ {
ut_ad(!m_freed_pages->empty());
fil_space_t *freed_space= m_user_space; fil_space_t *freed_space= m_user_space;
/* Get the freed tablespace in case of predefined tablespace */ /* Get the freed tablespace in case of predefined tablespace */
if (!freed_space) if (!freed_space)
...@@ -434,14 +431,15 @@ void mtr_t::commit() ...@@ -434,14 +431,15 @@ void mtr_t::commit()
/* Update the last freed lsn */ /* Update the last freed lsn */
freed_space->update_last_freed_lsn(m_commit_lsn); freed_space->update_last_freed_lsn(m_commit_lsn);
for (const auto &range : m_freed_ranges) if (!is_trim_pages())
freed_space->add_free_range(range); for (const auto &range : *m_freed_pages)
} freed_space->add_free_range(range);
else
if (is_trim_pages()) freed_space->clear_freed_ranges();
{ delete m_freed_pages;
ut_ad(m_user_space != nullptr); m_freed_pages= nullptr;
m_user_space->clear_freed_ranges(); /* Reset of m_trim_pages and m_freed_in_system_tablespace
happens in mtr_t::start() */
} }
m_memo.for_each_block_in_reverse(CIterate<const ReleaseBlocks> m_memo.for_each_block_in_reverse(CIterate<const ReleaseBlocks>
...@@ -472,7 +470,7 @@ void mtr_t::commit_files(lsn_t checkpoint_lsn) ...@@ -472,7 +470,7 @@ void mtr_t::commit_files(lsn_t checkpoint_lsn)
ut_ad(!m_made_dirty); ut_ad(!m_made_dirty);
ut_ad(m_memo.size() == 0); ut_ad(m_memo.size() == 0);
ut_ad(!srv_read_only_mode); ut_ad(!srv_read_only_mode);
ut_ad(m_freed_ranges.empty()); ut_ad(!m_freed_pages);
ut_ad(!m_freed_in_system_tablespace); ut_ad(!m_freed_in_system_tablespace);
if (checkpoint_lsn) { if (checkpoint_lsn) {
......
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