Commit 2570cb8b authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-12353 preparation: Clean up mtr_t

mtr_t::Impl, mtr_t::Command: Merge to mtr_t.

MTR_MAGIC_N: Remove.

MTR_STATE_COMMITTING: Remove. This state was only being set
internally during mtr_t::commit().

mtr_t::Command::m_locks_released: Remove (set-and-never-read member).

mtr_t::Command::m_start_lsn: Replaced with the return value of
finish_write() and a parameter to release_blocks().

mtr_t::Command::m_end_lsn: Removed as a duplicate of mtr_t::m_commit_lsn.

mtr_t::Command::prepare_write(): Replace a switch () with a
comparison against 0. Only 2 m_log_mode are allowed.
parent dc8380b6
......@@ -2,7 +2,7 @@
Copyright (c) 1995, 2017, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2012, Facebook Inc.
Copyright (c) 2013, 2018, MariaDB Corporation.
Copyright (c) 2013, 2019, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
......@@ -146,68 +146,7 @@ struct mtr_memo_slot_t {
/** Mini-transaction handle and buffer */
struct mtr_t {
/** State variables of the mtr */
struct Impl {
/** memo stack for locks etc. */
mtr_buf_t m_memo;
/** mini-transaction log */
mtr_buf_t m_log;
/** true if mtr has made at least one buffer pool page dirty */
bool m_made_dirty;
/** true if inside ibuf changes */
bool m_inside_ibuf;
/** true if the mini-transaction modified buffer pool pages */
bool m_modifications;
/** Count of how many page initial log records have been
written to the mtr log */
ib_uint32_t m_n_log_recs;
/** specifies which operations should be logged; default
value MTR_LOG_ALL */
mtr_log_t m_log_mode;
#ifdef UNIV_DEBUG
/** Persistent user tablespace associated with the
mini-transaction, or 0 (TRX_SYS_SPACE) if none yet */
ulint m_user_space_id;
#endif /* UNIV_DEBUG */
/** User tablespace that is being modified by the
mini-transaction */
fil_space_t* m_user_space;
/** Undo tablespace that is being modified by the
mini-transaction */
fil_space_t* m_undo_space;
/** System tablespace if it is being modified by the
mini-transaction */
fil_space_t* m_sys_space;
/** State of the transaction */
mtr_state_t m_state;
/** Flush Observer */
FlushObserver* m_flush_observer;
#ifdef UNIV_DEBUG
/** For checking corruption. */
ulint m_magic_n;
#endif /* UNIV_DEBUG */
/** Owning mini-transaction */
mtr_t* m_mtr;
};
mtr_t()
{
m_impl.m_state = MTR_STATE_INIT;
}
~mtr_t() { }
mtr_t() : m_state(MTR_STATE_INIT) {}
/** Release the free extents that was reserved using
fsp_reserve_free_extents(). This is equivalent to calling
......@@ -236,14 +175,7 @@ struct mtr_t {
/** Return current size of the buffer.
@return savepoint */
ulint get_savepoint() const
MY_ATTRIBUTE((warn_unused_result))
{
ut_ad(is_active());
ut_ad(m_impl.m_magic_n == MTR_MAGIC_N);
return(m_impl.m_memo.size());
}
ulint get_savepoint() const {ut_ad(is_active()); return m_memo.size();}
/** Release the (index tree) s-latch stored in an mtr memo after a
savepoint.
......@@ -279,10 +211,10 @@ struct mtr_t {
@return the system tablespace */
fil_space_t* set_sys_modified()
{
if (!m_impl.m_sys_space) {
if (!m_sys_space) {
lookup_sys_space();
}
return(m_impl.m_sys_space);
return m_sys_space;
}
/** Copy the tablespaces associated with the mini-transaction
......@@ -291,15 +223,15 @@ struct mtr_t {
the same set of tablespaces as this one */
void set_spaces(const mtr_t& mtr)
{
ut_ad(!m_impl.m_user_space_id);
ut_ad(!m_impl.m_user_space);
ut_ad(!m_impl.m_undo_space);
ut_ad(!m_impl.m_sys_space);
ut_d(m_impl.m_user_space_id = mtr.m_impl.m_user_space_id);
m_impl.m_user_space = mtr.m_impl.m_user_space;
m_impl.m_undo_space = mtr.m_impl.m_undo_space;
m_impl.m_sys_space = mtr.m_impl.m_sys_space;
ut_ad(!m_user_space_id);
ut_ad(!m_user_space);
ut_ad(!m_undo_space);
ut_ad(!m_sys_space);
ut_d(m_user_space_id = mtr.m_user_space_id);
m_user_space = mtr.m_user_space;
m_undo_space = mtr.m_undo_space;
m_sys_space = mtr.m_sys_space;
}
/** Set the tablespace associated with the mini-transaction
......@@ -308,13 +240,13 @@ struct mtr_t {
@return the tablespace */
fil_space_t* set_named_space(ulint space_id)
{
ut_ad(!m_impl.m_user_space_id);
ut_d(m_impl.m_user_space_id = space_id);
ut_ad(!m_user_space_id);
ut_d(m_user_space_id = space_id);
if (!space_id) {
return(set_sys_modified());
} else {
lookup_user_space(space_id);
return(m_impl.m_user_space);
return m_user_space;
}
}
......@@ -381,18 +313,12 @@ struct mtr_t {
void release_page(const void* ptr, mtr_memo_type_t type);
/** Note that the mini-transaction has modified data. */
void set_modified()
{
m_impl.m_modifications = true;
}
void set_modified() { m_modifications = true; }
/** Set the state to not-modified. This will not log the
changes. This is only used during redo log apply, to avoid
logging the changes. */
void discard_modifications()
{
m_impl.m_modifications = false;
}
void discard_modifications() { m_modifications = false; }
/** Get the LSN of commit().
@return the commit LSN
......@@ -404,45 +330,28 @@ struct mtr_t {
}
/** Note that we are inside the change buffer code. */
void enter_ibuf()
{
m_impl.m_inside_ibuf = true;
}
void enter_ibuf() { m_inside_ibuf = true; }
/** Note that we have exited from the change buffer code. */
void exit_ibuf()
{
m_impl.m_inside_ibuf = false;
}
void exit_ibuf() { m_inside_ibuf = false; }
/** @return true if we are inside the change buffer code */
bool is_inside_ibuf() const
{
return(m_impl.m_inside_ibuf);
}
bool is_inside_ibuf() const { return m_inside_ibuf; }
/*
@return true if the mini-transaction is active */
bool is_active() const
{
return(m_impl.m_state == MTR_STATE_ACTIVE);
}
bool is_active() const { return m_state == MTR_STATE_ACTIVE; }
/** Get flush observer
@return flush observer */
FlushObserver* get_flush_observer() const
{
return(m_impl.m_flush_observer);
}
FlushObserver* get_flush_observer() const { return m_flush_observer; }
/** Set flush observer
@param[in] observer flush observer */
void set_flush_observer(FlushObserver* observer)
{
ut_ad(observer == NULL
|| m_impl.m_log_mode == MTR_LOG_NO_REDO);
m_impl.m_flush_observer = observer;
ut_ad(observer == NULL || m_log_mode == MTR_LOG_NO_REDO);
m_flush_observer = observer;
}
#ifdef UNIV_DEBUG
......@@ -482,65 +391,31 @@ struct mtr_t {
void print() const;
/** @return true if the mini-transaction has committed */
bool has_committed() const
{
return(m_impl.m_state == MTR_STATE_COMMITTED);
}
/** @return true if the mini-transaction is committing */
bool is_committing() const
{
return(m_impl.m_state == MTR_STATE_COMMITTING);
}
bool has_committed() const { return m_state == MTR_STATE_COMMITTED; }
/** @return true if mini-transaction contains modifications. */
bool has_modifications() const
{
return(m_impl.m_modifications);
}
bool has_modifications() const { return m_modifications; }
/** @return the memo stack */
const mtr_buf_t* get_memo() const
{
return(&m_impl.m_memo);
}
const mtr_buf_t* get_memo() const { return &m_memo; }
/** @return the memo stack */
mtr_buf_t* get_memo()
{
return(&m_impl.m_memo);
}
mtr_buf_t* get_memo() { return &m_memo; }
#endif /* UNIV_DEBUG */
/** @return true if a record was added to the mini-transaction */
bool is_dirty() const
{
return(m_impl.m_made_dirty);
}
bool is_dirty() const { return m_made_dirty; }
/** Note that a record has been added to the log */
void added_rec()
{
++m_impl.m_n_log_recs;
}
void added_rec() { ++m_n_log_recs; }
/** Get the buffered redo log of this mini-transaction.
@return redo log */
const mtr_buf_t* get_log() const
{
ut_ad(m_impl.m_magic_n == MTR_MAGIC_N);
return(&m_impl.m_log);
}
const mtr_buf_t* get_log() const { return &m_log; }
/** Get the buffered redo log of this mini-transaction.
@return redo log */
mtr_buf_t* get_log()
{
ut_ad(m_impl.m_magic_n == MTR_MAGIC_N);
return(&m_impl.m_log);
}
mtr_buf_t* get_log() { return &m_log; }
/** Push an object to an mtr memo stack.
@param object object
......@@ -560,15 +435,60 @@ struct mtr_t {
@param[in] space_id tablespace ID */
void lookup_user_space(ulint space_id);
class Command;
/** Prepare to write the mini-transaction log to the redo log buffer.
@return number of bytes to write in finish_write() */
inline ulint prepare_write();
friend class Command;
/** Append the redo log records to the redo log buffer.
@param[in] len number of bytes to write
@return start_lsn */
inline lsn_t finish_write(ulint len);
private:
Impl m_impl;
/** Release the resources */
inline void release_resources();
/** memo stack for locks etc. */
mtr_buf_t m_memo;
/** mini-transaction log */
mtr_buf_t m_log;
/** true if mtr has made at least one buffer pool page dirty */
bool m_made_dirty;
/** true if inside ibuf changes */
bool m_inside_ibuf;
/** true if the mini-transaction modified buffer pool pages */
bool m_modifications;
/** Count of how many page initial log records have been
written to the mtr log */
ib_uint32_t m_n_log_recs;
/** specifies which operations should be logged; default
value MTR_LOG_ALL */
mtr_log_t m_log_mode;
#ifdef UNIV_DEBUG
/** Persistent user tablespace associated with the
mini-transaction, or 0 (TRX_SYS_SPACE) if none yet */
ulint m_user_space_id;
#endif /* UNIV_DEBUG */
/** User tablespace that is being modified by the mini-transaction */
fil_space_t* m_user_space;
/** Undo tablespace that is being modified by the mini-transaction */
fil_space_t* m_undo_space;
/** System tablespace if being modified by the mini-transaction */
fil_space_t* m_sys_space;
/** State of the transaction */
mtr_state_t m_state;
/** Flush Observer */
FlushObserver* m_flush_observer;
/** LSN at commit time */
volatile lsn_t m_commit_lsn;
lsn_t m_commit_lsn;
};
#include "mtr0mtr.ic"
......
......@@ -49,7 +49,6 @@ mtr_t::memo_push(void* object, mtr_memo_type_t type)
ut_ad(object != NULL);
ut_ad(type >= MTR_MEMO_PAGE_S_FIX);
ut_ad(type <= MTR_MEMO_SX_LOCK);
ut_ad(m_impl.m_magic_n == MTR_MAGIC_N);
ut_ad(ut_is_2pow(type));
/* If this mtr has x-fixed a clean page then we set
......@@ -58,15 +57,13 @@ mtr_t::memo_push(void* object, mtr_memo_type_t type)
can insert the dirtied page to the flush list. */
if ((type == MTR_MEMO_PAGE_X_FIX || type == MTR_MEMO_PAGE_SX_FIX)
&& !m_impl.m_made_dirty) {
&& !m_made_dirty) {
m_impl.m_made_dirty = is_block_dirtied(
m_made_dirty = is_block_dirtied(
reinterpret_cast<const buf_block_t*>(object));
}
mtr_memo_slot_t* slot;
slot = m_impl.m_memo.push<mtr_memo_slot_t*>(sizeof(*slot));
mtr_memo_slot_t* slot = m_memo.push<mtr_memo_slot_t*>(sizeof(*slot));
slot->type = type;
slot->object = object;
......@@ -81,11 +78,9 @@ mtr_t::release_s_latch_at_savepoint(
rw_lock_t* lock)
{
ut_ad(is_active());
ut_ad(m_impl.m_magic_n == MTR_MAGIC_N);
ut_ad(m_impl.m_memo.size() > savepoint);
ut_ad(m_memo.size() > savepoint);
mtr_memo_slot_t* slot = m_impl.m_memo.at<mtr_memo_slot_t*>(savepoint);
mtr_memo_slot_t* slot = m_memo.at<mtr_memo_slot_t*>(savepoint);
ut_ad(slot->object == lock);
ut_ad(slot->type == MTR_MEMO_S_LOCK);
......@@ -104,8 +99,7 @@ mtr_t::sx_latch_at_savepoint(
buf_block_t* block)
{
ut_ad(is_active());
ut_ad(m_impl.m_magic_n == MTR_MAGIC_N);
ut_ad(m_impl.m_memo.size() > savepoint);
ut_ad(m_memo.size() > savepoint);
ut_ad(!memo_contains_flagged(
block,
......@@ -113,9 +107,7 @@ mtr_t::sx_latch_at_savepoint(
| MTR_MEMO_PAGE_X_FIX
| MTR_MEMO_PAGE_SX_FIX));
mtr_memo_slot_t* slot;
slot = m_impl.m_memo.at<mtr_memo_slot_t*>(savepoint);
mtr_memo_slot_t* slot = m_memo.at<mtr_memo_slot_t*>(savepoint);
ut_ad(slot->object == block);
......@@ -124,8 +116,8 @@ mtr_t::sx_latch_at_savepoint(
rw_lock_sx_lock(&block->lock);
if (!m_impl.m_made_dirty) {
m_impl.m_made_dirty = is_block_dirtied(block);
if (!m_made_dirty) {
m_made_dirty = is_block_dirtied(block);
}
slot->type = MTR_MEMO_PAGE_SX_FIX;
......@@ -140,8 +132,7 @@ mtr_t::x_latch_at_savepoint(
buf_block_t* block)
{
ut_ad(is_active());
ut_ad(m_impl.m_magic_n == MTR_MAGIC_N);
ut_ad(m_impl.m_memo.size() > savepoint);
ut_ad(m_memo.size() > savepoint);
ut_ad(!memo_contains_flagged(
block,
......@@ -149,9 +140,7 @@ mtr_t::x_latch_at_savepoint(
| MTR_MEMO_PAGE_X_FIX
| MTR_MEMO_PAGE_SX_FIX));
mtr_memo_slot_t* slot;
slot = m_impl.m_memo.at<mtr_memo_slot_t*>(savepoint);
mtr_memo_slot_t* slot = m_memo.at<mtr_memo_slot_t*>(savepoint);
ut_ad(slot->object == block);
......@@ -160,8 +149,8 @@ mtr_t::x_latch_at_savepoint(
rw_lock_x_lock(&block->lock);
if (!m_impl.m_made_dirty) {
m_impl.m_made_dirty = is_block_dirtied(block);
if (!m_made_dirty) {
m_made_dirty = is_block_dirtied(block);
}
slot->type = MTR_MEMO_PAGE_X_FIX;
......@@ -176,11 +165,8 @@ mtr_t::release_block_at_savepoint(
buf_block_t* block)
{
ut_ad(is_active());
ut_ad(m_impl.m_magic_n == MTR_MAGIC_N);
mtr_memo_slot_t* slot;
slot = m_impl.m_memo.at<mtr_memo_slot_t*>(savepoint);
mtr_memo_slot_t* slot = m_memo.at<mtr_memo_slot_t*>(savepoint);
ut_a(slot->object == block);
......@@ -198,10 +184,10 @@ Gets the logging mode of a mini-transaction.
mtr_log_t
mtr_t::get_log_mode() const
{
ut_ad(m_impl.m_log_mode >= MTR_LOG_ALL);
ut_ad(m_impl.m_log_mode <= MTR_LOG_SHORT_INSERTS);
ut_ad(m_log_mode >= MTR_LOG_ALL);
ut_ad(m_log_mode <= MTR_LOG_SHORT_INSERTS);
return(m_impl.m_log_mode);
return m_log_mode;
}
/**
......@@ -214,7 +200,7 @@ mtr_t::set_log_mode(mtr_log_t mode)
ut_ad(mode >= MTR_LOG_ALL);
ut_ad(mode <= MTR_LOG_SHORT_INSERTS);
const mtr_log_t old_mode = m_impl.m_log_mode;
const mtr_log_t old_mode = m_log_mode;
switch (old_mode) {
case MTR_LOG_NO_REDO:
......@@ -233,9 +219,8 @@ mtr_t::set_log_mode(mtr_log_t mode)
case MTR_LOG_ALL:
/* MTR_LOG_NO_REDO can only be set before generating
any redo log records. */
ut_ad(mode != MTR_LOG_NO_REDO
|| m_impl.m_n_log_recs == 0);
m_impl.m_log_mode = mode;
ut_ad(mode != MTR_LOG_NO_REDO || m_n_log_recs == 0);
m_log_mode = mode;
return(old_mode);
}
......
/*****************************************************************************
Copyright (c) 1995, 2015, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, MariaDB Corporation.
Copyright (c) 2017, 2019, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
......@@ -36,18 +36,18 @@ struct mtr_t;
/** Logging modes for a mini-transaction */
enum mtr_log_t {
/** Default mode: log all operations modifying disk-based data */
MTR_LOG_ALL = 21,
MTR_LOG_ALL = 0,
/** Log no operations and dirty pages are not added to the flush list.
Set when applying log in crash recovery or when a modification of a
ROW_FORMAT=COMPRESSED page is attempted. */
MTR_LOG_NONE = 22,
MTR_LOG_NONE,
/** Don't generate REDO log but add dirty pages to flush list */
MTR_LOG_NO_REDO = 23,
MTR_LOG_NO_REDO,
/** Inserts are logged in a shorter form */
MTR_LOG_SHORT_INSERTS = 24
MTR_LOG_SHORT_INSERTS
};
/** @name Log item types
......@@ -267,15 +267,10 @@ enum mtr_memo_type_t {
};
#endif /* !UNIV_CHECKSUM */
#ifdef UNIV_DEBUG
# define MTR_MAGIC_N 54551
#endif /* UNIV_DEBUG */
enum mtr_state_t {
MTR_STATE_INIT = 0,
MTR_STATE_ACTIVE = 12231,
MTR_STATE_COMMITTING = 56456,
MTR_STATE_COMMITTED = 34676
MTR_STATE_ACTIVE,
MTR_STATE_COMMITTED
};
#endif /* mtr0types_h */
This diff is collapsed.
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