Commit 7fa5cce3 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-30289: Remove the pointer indirection for mtr_t::m_memo

parent a01abad6
......@@ -77,6 +77,9 @@ struct mtr_memo_slot_t
/** Mini-transaction handle and buffer */
struct mtr_t {
mtr_t();
~mtr_t();
/** Start a mini-transaction. */
void start();
......@@ -91,11 +94,11 @@ struct mtr_t {
/** Release latches of unmodified buffer pages.
@param begin first slot to release */
void rollback_to_savepoint(ulint begin)
{ rollback_to_savepoint(begin, m_memo->size()); }
{ rollback_to_savepoint(begin, m_memo.size()); }
/** Release the last acquired buffer page latch. */
void release_last_page()
{ auto s= m_memo->size(); rollback_to_savepoint(s - 1, s); }
{ auto s= m_memo.size(); rollback_to_savepoint(s - 1, s); }
/** Commit a mini-transaction that is shrinking a tablespace.
@param space tablespace that is being shrunk */
......@@ -119,7 +122,7 @@ struct mtr_t {
ulint get_savepoint() const
{
ut_ad(is_active());
return m_memo ? m_memo->size() : 0;
return m_memo.size();
}
/** Release the (index tree) s-latch stored in an mtr memo after a savepoint.
......@@ -128,7 +131,7 @@ struct mtr_t {
void release_s_latch_at_savepoint(ulint savepoint, index_lock *lock)
{
ut_ad(is_active());
mtr_memo_slot_t &slot= m_memo->at(savepoint);
mtr_memo_slot_t &slot= m_memo[savepoint];
ut_ad(slot.object == lock);
ut_ad(slot.type == MTR_MEMO_S_LOCK);
slot.object= nullptr;
......@@ -138,7 +141,7 @@ struct mtr_t {
void release_block_at_savepoint(ulint savepoint, buf_block_t *block)
{
ut_ad(is_active());
mtr_memo_slot_t &slot= m_memo->at(savepoint);
mtr_memo_slot_t &slot= m_memo[savepoint];
ut_ad(slot.object == block);
ut_ad(!(slot.type & MTR_MEMO_MODIFY));
slot.object= nullptr;
......@@ -172,7 +175,7 @@ struct mtr_t {
ut_ad(is_active());
ut_ad(!memo_contains_flagged(block, MTR_MEMO_PAGE_S_FIX |
MTR_MEMO_PAGE_X_FIX | MTR_MEMO_PAGE_SX_FIX));
mtr_memo_slot_t &slot= m_memo->at(savepoint);
mtr_memo_slot_t &slot= m_memo[savepoint];
ut_ad(slot.object == block);
ut_ad(slot.type == MTR_MEMO_BUF_FIX);
slot.type= MTR_MEMO_PAGE_X_FIX;
......@@ -189,7 +192,7 @@ struct mtr_t {
ut_ad(is_active());
ut_ad(!memo_contains_flagged(block, MTR_MEMO_PAGE_S_FIX |
MTR_MEMO_PAGE_X_FIX | MTR_MEMO_PAGE_SX_FIX));
mtr_memo_slot_t &slot= m_memo->at(savepoint);
mtr_memo_slot_t &slot= m_memo[savepoint];
ut_ad(slot.object == block);
ut_ad(slot.type == MTR_MEMO_BUF_FIX);
slot.type= MTR_MEMO_PAGE_SX_FIX;
......@@ -409,7 +412,7 @@ struct mtr_t {
@param latch latch type */
void u_lock_register(ulint savepoint)
{
mtr_memo_slot_t &slot= m_memo->at(savepoint);
mtr_memo_slot_t &slot= m_memo[savepoint];
ut_ad(slot.type == MTR_MEMO_BUF_FIX);
slot.type= MTR_MEMO_PAGE_SX_FIX;
}
......@@ -418,7 +421,7 @@ struct mtr_t {
@param latch latch type */
void s_lock_register(ulint savepoint)
{
mtr_memo_slot_t &slot= m_memo->at(savepoint);
mtr_memo_slot_t &slot= m_memo[savepoint];
ut_ad(slot.type == MTR_MEMO_BUF_FIX);
slot.type= MTR_MEMO_PAGE_S_FIX;
}
......@@ -477,10 +480,7 @@ struct mtr_t {
m_made_dirty=
is_block_dirtied(*static_cast<const buf_page_t*>(object));
if (!m_memo)
m_memo= new std::vector<mtr_memo_slot_t>(1, {object, type});
else
m_memo->emplace_back(mtr_memo_slot_t{object, type});
m_memo.emplace_back(mtr_memo_slot_t{object, type});
}
/** @return the size of the log is empty */
......@@ -790,7 +790,7 @@ struct mtr_t {
#endif /* UNIV_DEBUG */
/** acquired dict_index_t::lock, fil_space_t::latch, buf_block_t */
std::vector<mtr_memo_slot_t> *m_memo= nullptr;
std::vector<mtr_memo_slot_t> m_memo;
/** mini-transaction log */
mtr_buf_t m_log;
......
......@@ -76,10 +76,13 @@ void mtr_memo_slot_t::release() const
}
}
mtr_t::mtr_t()= default;
mtr_t::~mtr_t()= default;
/** Start a mini-transaction. */
void mtr_t::start()
{
ut_ad(!m_memo);
ut_ad(m_memo.empty());
ut_ad(!m_freed_pages);
ut_ad(!m_freed_space);
MEM_UNDEFINED(this, sizeof *this);
......@@ -110,24 +113,20 @@ void mtr_t::start()
inline void mtr_t::release_resources()
{
ut_ad(is_active());
ut_ad(!m_memo);
ut_ad(m_memo.empty());
m_log.erase();
ut_d(m_commit= true);
}
void mtr_t::release()
{
if (m_memo)
for (auto it= m_memo.rbegin(); it != m_memo.rend(); it++)
{
for (auto it= m_memo->rbegin(); it != m_memo->rend(); it++)
{
mtr_memo_slot_t &slot= *it;
if (slot.object)
slot.release();
}
delete m_memo;
m_memo= nullptr;
mtr_memo_slot_t &slot= *it;
if (slot.object)
slot.release();
}
m_memo.clear();
}
/** Commit a mini-transaction. */
......@@ -190,17 +189,14 @@ void mtr_t::commit()
else
ut_ad(!m_freed_space);
if (m_memo)
for (const mtr_memo_slot_t &slot : m_memo)
{
for (const mtr_memo_slot_t &slot : *m_memo)
if (slot.object && slot.type & MTR_MEMO_MODIFY)
{
if (slot.object && slot.type & MTR_MEMO_MODIFY)
{
ut_ad(slot.type == MTR_MEMO_PAGE_X_MODIFY ||
slot.type == MTR_MEMO_PAGE_SX_MODIFY);
buf_flush_note_modification(static_cast<buf_block_t*>(slot.object),
lsns.first, m_commit_lsn);
}
ut_ad(slot.type == MTR_MEMO_PAGE_X_MODIFY ||
slot.type == MTR_MEMO_PAGE_SX_MODIFY);
buf_flush_note_modification(static_cast<buf_block_t*>(slot.object),
lsns.first, m_commit_lsn);
}
}
......@@ -223,14 +219,13 @@ void mtr_t::commit()
void mtr_t::rollback_to_savepoint(ulint begin, ulint end)
{
ut_ad(m_memo);
ut_ad(end <= m_memo->size());
ut_ad(end <= m_memo.size());
ut_ad(begin <= end);
ulint s= end;
while (s-- > begin)
{
const mtr_memo_slot_t &slot= (*m_memo)[s];
const mtr_memo_slot_t &slot= m_memo[s];
if (!slot.object)
continue;
/* This is intended for releasing latches on indexes or unmodified
......@@ -240,7 +235,7 @@ void mtr_t::rollback_to_savepoint(ulint begin, ulint end)
slot.release();
}
m_memo->erase(m_memo->begin() + begin, m_memo->begin() + end);
m_memo.erase(m_memo.begin() + begin, m_memo.begin() + end);
}
/** Commit a mini-transaction that is shrinking a tablespace.
......@@ -252,7 +247,7 @@ void mtr_t::commit_shrink(fil_space_t &space)
ut_ad(!high_level_read_only);
ut_ad(m_modifications);
ut_ad(m_made_dirty);
ut_ad(m_memo);
ut_ad(!m_memo.empty());
ut_ad(!recv_recovery_is_on());
ut_ad(m_log_mode == MTR_LOG_ALL);
ut_ad(UT_LIST_GET_LEN(space.chain) == 1);
......@@ -292,7 +287,7 @@ void mtr_t::commit_shrink(fil_space_t &space)
const page_id_t high{space.id, space.size};
for (mtr_memo_slot_t &slot : *m_memo)
for (mtr_memo_slot_t &slot : m_memo)
{
if (!slot.object)
continue;
......@@ -539,19 +534,18 @@ void mtr_t::x_lock_space(fil_space_t *space)
void mtr_t::release(const void *object)
{
ut_ad(is_active());
ut_ad(m_memo);
auto it=
std::find_if(m_memo->begin(), m_memo->end(),
std::find_if(m_memo.begin(), m_memo.end(),
[object](const mtr_memo_slot_t& slot)
{ return slot.object == object; });
ut_ad(it != m_memo->end());
ut_ad(it != m_memo.end());
ut_ad(!(it->type & MTR_MEMO_MODIFY));
it->release();
m_memo->erase(it);
ut_ad(std::find_if(m_memo->begin(), m_memo->end(),
m_memo.erase(it);
ut_ad(std::find_if(m_memo.begin(), m_memo.end(),
[object](const mtr_memo_slot_t& slot)
{ return slot.object == &object; }) == m_memo->end());
{ return slot.object == &object; }) == m_memo.end());
}
static bool log_margin_warned;
......@@ -810,11 +804,11 @@ std::pair<lsn_t,mtr_t::page_flush_ahead> mtr_t::do_write()
#ifndef DBUG_OFF
do
{
if (!m_memo || m_log_mode != MTR_LOG_ALL)
if (m_log_mode != MTR_LOG_ALL)
continue;
DBUG_EXECUTE_IF("skip_page_checksum", continue;);
for (const mtr_memo_slot_t& slot : *m_memo)
for (const mtr_memo_slot_t& slot : m_memo)
if (slot.type & MTR_MEMO_MODIFY)
{
const buf_page_t &b= *static_cast<const buf_page_t*>(slot.object);
......@@ -891,12 +885,9 @@ inline std::pair<lsn_t,mtr_t::page_flush_ahead> mtr_t::finish_write(ulint len)
bool mtr_t::have_x_latch(const buf_block_t &block) const
{
if (!m_memo)
return false;
ut_d(const mtr_memo_slot_t *found= nullptr);
for (const mtr_memo_slot_t &slot : *m_memo)
for (const mtr_memo_slot_t &slot : m_memo)
{
if (slot.object != &block)
continue;
......@@ -916,16 +907,13 @@ bool mtr_t::have_x_latch(const buf_block_t &block) const
bool mtr_t::have_u_or_x_latch(const buf_block_t &block) const
{
if (m_memo)
for (const mtr_memo_slot_t &slot : m_memo)
{
for (const mtr_memo_slot_t &slot : *m_memo)
if (slot.object == &block &&
slot.type & (MTR_MEMO_PAGE_X_FIX | MTR_MEMO_PAGE_SX_FIX))
{
if (slot.object == &block &&
slot.type & (MTR_MEMO_PAGE_X_FIX | MTR_MEMO_PAGE_SX_FIX))
{
ut_ad(block.page.lock.have_u_or_x());
return true;
}
ut_ad(block.page.lock.have_u_or_x());
return true;
}
}
return false;
......@@ -937,18 +925,15 @@ bool mtr_t::have_u_or_x_latch(const buf_block_t &block) const
@return whether space.latch is being held */
bool mtr_t::memo_contains(const fil_space_t& space, bool shared) const
{
if (m_memo)
{
const mtr_memo_type_t type= shared
? MTR_MEMO_SPACE_S_LOCK : MTR_MEMO_SPACE_X_LOCK;
const mtr_memo_type_t type= shared
? MTR_MEMO_SPACE_S_LOCK : MTR_MEMO_SPACE_X_LOCK;
for (const mtr_memo_slot_t &slot : *m_memo)
for (const mtr_memo_slot_t &slot : m_memo)
{
if (slot.object == &space && slot.type == type)
{
if (slot.object == &space && slot.type == type)
{
ut_ad(shared || space.is_owner());
return true;
}
ut_ad(shared || space.is_owner());
return true;
}
}
......@@ -958,9 +943,8 @@ bool mtr_t::memo_contains(const fil_space_t& space, bool shared) const
void mtr_t::page_lock_upgrade(const buf_block_t &block)
{
ut_ad(block.page.lock.have_x());
ut_ad(m_memo);
for (mtr_memo_slot_t &slot : *m_memo)
for (mtr_memo_slot_t &slot : m_memo)
if (slot.object == &block && slot.type & MTR_MEMO_PAGE_SX_FIX)
slot.type= mtr_memo_type_t(slot.type ^
(MTR_MEMO_PAGE_SX_FIX | MTR_MEMO_PAGE_X_FIX));
......@@ -973,9 +957,8 @@ void mtr_t::page_lock_upgrade(const buf_block_t &block)
void mtr_t::lock_upgrade(const index_lock &lock)
{
ut_ad(lock.have_x());
ut_ad(m_memo);
for (mtr_memo_slot_t &slot : *m_memo)
for (mtr_memo_slot_t &slot : m_memo)
if (slot.object == &lock && slot.type == MTR_MEMO_SX_LOCK)
slot.type= MTR_MEMO_X_LOCK;
}
......@@ -1028,10 +1011,9 @@ void mtr_t::page_lock(buf_block_t *block, ulint rw_latch)
void mtr_t::upgrade_buffer_fix(ulint savepoint, rw_lock_type_t rw_latch)
{
ut_ad(is_active());
ut_ad(m_memo);
ut_ad(savepoint < m_memo->size());
ut_ad(savepoint < m_memo.size());
mtr_memo_slot_t &slot= (*m_memo)[savepoint];
mtr_memo_slot_t &slot= m_memo[savepoint];
ut_ad(slot.type == MTR_MEMO_BUF_FIX);
buf_block_t *block= static_cast<buf_block_t*>(slot.object);
ut_d(const auto state= block->page.state());
......@@ -1070,27 +1052,24 @@ bool mtr_t::memo_contains(const index_lock &lock, mtr_memo_type_t type) const
ut_ad(type == MTR_MEMO_X_LOCK || type == MTR_MEMO_S_LOCK ||
type == MTR_MEMO_SX_LOCK);
if (m_memo)
for (const mtr_memo_slot_t &slot : m_memo)
{
for (const mtr_memo_slot_t &slot : *m_memo)
if (slot.object == &lock && slot.type == type)
{
if (slot.object == &lock && slot.type == type)
{
switch (type) {
case MTR_MEMO_X_LOCK:
ut_ad(lock.have_x());
break;
case MTR_MEMO_SX_LOCK:
ut_ad(lock.have_u_or_x());
break;
case MTR_MEMO_S_LOCK:
ut_ad(lock.have_s());
break;
default:
break;
}
return true;
switch (type) {
case MTR_MEMO_X_LOCK:
ut_ad(lock.have_x());
break;
case MTR_MEMO_SX_LOCK:
ut_ad(lock.have_u_or_x());
break;
case MTR_MEMO_S_LOCK:
ut_ad(lock.have_s());
break;
default:
break;
}
return true;
}
}
......@@ -1118,7 +1097,7 @@ bool mtr_t::memo_contains_flagged(const void *object, ulint flags) const
MTR_MEMO_MODIFY)) ==
!!(flags & (MTR_MEMO_X_LOCK | MTR_MEMO_SX_LOCK | MTR_MEMO_S_LOCK)));
for (const mtr_memo_slot_t &slot : *m_memo)
for (const mtr_memo_slot_t &slot : m_memo)
{
if (object != slot.object)
continue;
......@@ -1153,7 +1132,7 @@ buf_block_t* mtr_t::memo_contains_page_flagged(const byte *ptr, ulint flags)
{
ptr= page_align(ptr);
for (const mtr_memo_slot_t &slot : *m_memo)
for (const mtr_memo_slot_t &slot : m_memo)
{
if (!slot.object || !(flags & slot.type))
continue;
......@@ -1178,16 +1157,9 @@ buf_block_t* mtr_t::memo_contains_page_flagged(const byte *ptr, ulint flags)
@param block page that will be modified */
void mtr_t::modify(const buf_block_t &block)
{
if (UNIV_UNLIKELY(!m_memo))
{
/* This must be PageConverter::update_page() in IMPORT TABLESPACE. */
ut_ad(!block.page.in_LRU_list);
return;
}
mtr_memo_slot_t *found= nullptr;
for (mtr_memo_slot_t &slot : *m_memo)
for (mtr_memo_slot_t &slot : m_memo)
{
if (slot.object == &block &&
slot.type & (MTR_MEMO_PAGE_X_FIX | MTR_MEMO_PAGE_SX_FIX))
......@@ -1199,7 +1171,9 @@ void mtr_t::modify(const buf_block_t &block)
if (UNIV_UNLIKELY(!found))
{
ut_ad("modifying an unlatched page" == 0);
/* This must be PageConverter::update_page() in IMPORT TABLESPACE. */
ut_ad(m_memo.empty());
ut_ad(!block.page.in_LRU_list);
return;
}
found->type= static_cast<mtr_memo_type_t>(found->type | MTR_MEMO_MODIFY);
......@@ -1217,11 +1191,10 @@ void mtr_t::free(const fil_space_t &space, uint32_t offset)
if (is_logged())
{
ut_ad(m_memo);
buf_block_t *freed= nullptr;
const page_id_t id{space.id, offset};
for (auto it= m_memo->rbegin(); it != m_memo->rend(); it++)
for (auto it= m_memo.rbegin(); it != m_memo.rend(); it++)
{
mtr_memo_slot_t &slot= *it;
buf_block_t *block= static_cast<buf_block_t*>(slot.object);
......
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