2014-02-26 19:11:54 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
|
2017-01-10 10:48:56 +05:30
|
|
|
Copyright (c) 1995, 2017, Oracle and/or its affiliates. All Rights Reserved.
|
2014-02-26 19:11:54 +01:00
|
|
|
Copyright (c) 2012, Facebook Inc.
|
2018-11-01 10:48:56 +02:00
|
|
|
Copyright (c) 2013, 2018, MariaDB Corporation.
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
Foundation; version 2 of the License.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
this program; if not, write to the Free Software Foundation, Inc.,
|
2019-05-11 18:08:32 +03:00
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/**************************************************//**
|
|
|
|
@file include/mtr0mtr.h
|
|
|
|
Mini-transaction buffer
|
|
|
|
|
|
|
|
Created 11/26/1995 Heikki Tuuri
|
|
|
|
*******************************************************/
|
|
|
|
|
|
|
|
#ifndef mtr0mtr_h
|
|
|
|
#define mtr0mtr_h
|
|
|
|
|
2018-03-28 09:29:14 +03:00
|
|
|
#include "fil0fil.h"
|
2016-08-12 11:17:45 +03:00
|
|
|
#include "dyn0buf.h"
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/** Start a mini-transaction. */
|
|
|
|
#define mtr_start(m) (m)->start()
|
|
|
|
|
|
|
|
/** Commit a mini-transaction. */
|
|
|
|
#define mtr_commit(m) (m)->commit()
|
|
|
|
|
|
|
|
/** Set and return a savepoint in mtr.
|
2014-02-26 19:11:54 +01:00
|
|
|
@return savepoint */
|
2016-08-12 11:17:45 +03:00
|
|
|
#define mtr_set_savepoint(m) (m)->get_savepoint()
|
|
|
|
|
|
|
|
/** Release the (index tree) s-latch stored in an mtr memo after a
|
2014-12-22 16:53:17 +02:00
|
|
|
savepoint. */
|
2016-08-12 11:17:45 +03:00
|
|
|
#define mtr_release_s_latch_at_savepoint(m, s, l) \
|
|
|
|
(m)->release_s_latch_at_savepoint((s), (l))
|
|
|
|
|
|
|
|
/** Get the logging mode of a mini-transaction.
|
2014-02-26 19:11:54 +01:00
|
|
|
@return logging mode: MTR_LOG_NONE, ... */
|
2016-08-12 11:17:45 +03:00
|
|
|
#define mtr_get_log_mode(m) (m)->get_log_mode()
|
|
|
|
|
|
|
|
/** Change the logging mode of a mini-transaction.
|
2014-02-26 19:11:54 +01:00
|
|
|
@return old mode */
|
2016-08-12 11:17:45 +03:00
|
|
|
#define mtr_set_log_mode(m, d) (m)->set_log_mode((d))
|
|
|
|
|
|
|
|
/** Read 1 - 4 bytes from a file page buffered in the buffer pool.
|
2014-02-26 19:11:54 +01:00
|
|
|
@return value read */
|
2016-08-12 11:17:45 +03:00
|
|
|
#define mtr_read_ulint(p, t, m) (m)->read_ulint((p), (t))
|
|
|
|
|
|
|
|
/** Release an object in the memo stack.
|
2014-02-26 19:11:54 +01:00
|
|
|
@return true if released */
|
2016-08-12 11:17:45 +03:00
|
|
|
#define mtr_memo_release(m, o, t) \
|
|
|
|
(m)->memo_release((o), (t))
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
#ifdef UNIV_DEBUG
|
2016-08-12 11:17:45 +03:00
|
|
|
/** Check if memo contains the given item.
|
2014-02-26 19:11:54 +01:00
|
|
|
@return TRUE if contains */
|
2016-08-12 11:17:45 +03:00
|
|
|
#define mtr_memo_contains(m, o, t) \
|
|
|
|
(m)->memo_contains((m)->get_memo(), (o), (t))
|
|
|
|
|
|
|
|
/** Check if memo contains the given page.
|
2014-02-26 19:11:54 +01:00
|
|
|
@return TRUE if contains */
|
2016-08-12 11:17:45 +03:00
|
|
|
#define mtr_memo_contains_page(m, p, t) \
|
2016-09-06 09:43:16 +03:00
|
|
|
(m)->memo_contains_page_flagged((p), (t))
|
2014-02-26 19:11:54 +01:00
|
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/** Print info of an mtr handle. */
|
|
|
|
#define mtr_print(m) (m)->print()
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/** Return the log object of a mini-transaction buffer.
|
2014-02-26 19:11:54 +01:00
|
|
|
@return log */
|
2016-08-12 11:17:45 +03:00
|
|
|
#define mtr_get_log(m) (m)->get_log()
|
|
|
|
|
|
|
|
/** Push an object to an mtr memo stack. */
|
|
|
|
#define mtr_memo_push(m, o, t) (m)->memo_push(o, t)
|
|
|
|
|
|
|
|
/** Lock an rw-lock in s-mode. */
|
|
|
|
#define mtr_s_lock(l, m) (m)->s_lock((l), __FILE__, __LINE__)
|
|
|
|
|
|
|
|
/** Lock an rw-lock in x-mode. */
|
|
|
|
#define mtr_x_lock(l, m) (m)->x_lock((l), __FILE__, __LINE__)
|
|
|
|
|
|
|
|
/** Lock a tablespace in x-mode. */
|
|
|
|
#define mtr_x_lock_space(s, m) (m)->x_lock_space((s), __FILE__, __LINE__)
|
|
|
|
|
|
|
|
/** Lock an rw-lock in sx-mode. */
|
|
|
|
#define mtr_sx_lock(l, m) (m)->sx_lock((l), __FILE__, __LINE__)
|
|
|
|
|
|
|
|
#define mtr_memo_contains_flagged(m, p, l) \
|
|
|
|
(m)->memo_contains_flagged((p), (l))
|
|
|
|
|
|
|
|
#define mtr_memo_contains_page_flagged(m, p, l) \
|
|
|
|
(m)->memo_contains_page_flagged((p), (l))
|
|
|
|
|
|
|
|
#define mtr_release_block_at_savepoint(m, s, b) \
|
|
|
|
(m)->release_block_at_savepoint((s), (b))
|
|
|
|
|
|
|
|
#define mtr_block_sx_latch_at_savepoint(m, s, b) \
|
|
|
|
(m)->sx_latch_at_savepoint((s), (b))
|
|
|
|
|
|
|
|
#define mtr_block_x_latch_at_savepoint(m, s, b) \
|
|
|
|
(m)->x_latch_at_savepoint((s), (b))
|
|
|
|
|
|
|
|
/** Check if a mini-transaction is dirtying a clean page.
|
|
|
|
@param b block being x-fixed
|
|
|
|
@return true if the mtr is dirtying a clean page. */
|
|
|
|
#define mtr_block_dirtied(b) mtr_t::is_block_dirtied((b))
|
|
|
|
|
|
|
|
/** Append records to the system-wide redo log buffer.
|
|
|
|
@param[in] log redo log records */
|
2014-02-26 19:11:54 +01:00
|
|
|
void
|
2016-08-12 11:17:45 +03:00
|
|
|
mtr_write_log(
|
|
|
|
const mtr_buf_t* log);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/** Mini-transaction memo stack slot. */
|
2016-08-12 11:17:45 +03:00
|
|
|
struct mtr_memo_slot_t {
|
|
|
|
/** pointer to the object */
|
|
|
|
void* object;
|
|
|
|
|
|
|
|
/** type of the stored object (MTR_MEMO_S_LOCK, ...) */
|
|
|
|
ulint type;
|
2014-02-26 19:11:54 +01:00
|
|
|
};
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/** 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;
|
2014-02-26 19:11:54 +01:00
|
|
|
#ifdef UNIV_DEBUG
|
2016-08-12 11:17:45 +03:00
|
|
|
/** 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;
|
|
|
|
|
|
|
|
/** State of the transaction */
|
|
|
|
mtr_state_t m_state;
|
|
|
|
|
|
|
|
/** Flush Observer */
|
|
|
|
FlushObserver* m_flush_observer;
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
#ifdef UNIV_DEBUG
|
2016-08-12 11:17:45 +03:00
|
|
|
/** For checking corruption. */
|
|
|
|
ulint m_magic_n;
|
2014-02-26 19:11:54 +01:00
|
|
|
#endif /* UNIV_DEBUG */
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** Owning mini-transaction */
|
|
|
|
mtr_t* m_mtr;
|
|
|
|
};
|
|
|
|
|
|
|
|
mtr_t()
|
|
|
|
{
|
|
|
|
m_impl.m_state = MTR_STATE_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
~mtr_t() { }
|
|
|
|
|
2018-11-01 10:48:56 +02:00
|
|
|
/** Start a mini-transaction. */
|
|
|
|
void start();
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** Commit the mini-transaction. */
|
|
|
|
void commit();
|
|
|
|
|
|
|
|
/** Commit a mini-transaction that did not modify any pages,
|
|
|
|
but generated some redo log on a higher level, such as
|
|
|
|
MLOG_FILE_NAME records and a MLOG_CHECKPOINT marker.
|
|
|
|
The caller must invoke log_mutex_enter() and log_mutex_exit().
|
|
|
|
This is to be used at log_checkpoint().
|
2017-01-10 10:48:56 +05:30
|
|
|
@param[in] checkpoint_lsn the LSN of the log checkpoint
|
|
|
|
@param[in] write_mlog_checkpoint Write MLOG_CHECKPOINT marker
|
|
|
|
if it is enabled. */
|
|
|
|
void commit_checkpoint(
|
|
|
|
lsn_t checkpoint_lsn,
|
|
|
|
bool write_mlog_checkpoint);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** Return current size of the buffer.
|
|
|
|
@return savepoint */
|
|
|
|
ulint get_savepoint() const
|
2016-09-06 09:43:16 +03:00
|
|
|
MY_ATTRIBUTE((warn_unused_result))
|
2016-08-12 11:17:45 +03:00
|
|
|
{
|
|
|
|
ut_ad(is_active());
|
|
|
|
ut_ad(m_impl.m_magic_n == MTR_MAGIC_N);
|
|
|
|
|
|
|
|
return(m_impl.m_memo.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Release the (index tree) s-latch stored in an mtr memo after a
|
|
|
|
savepoint.
|
|
|
|
@param savepoint value returned by @see set_savepoint.
|
|
|
|
@param lock latch to release */
|
|
|
|
inline void release_s_latch_at_savepoint(
|
|
|
|
ulint savepoint,
|
|
|
|
rw_lock_t* lock);
|
|
|
|
|
|
|
|
/** Release the block in an mtr memo after a savepoint. */
|
|
|
|
inline void release_block_at_savepoint(
|
|
|
|
ulint savepoint,
|
|
|
|
buf_block_t* block);
|
|
|
|
|
|
|
|
/** SX-latch a not yet latched block after a savepoint. */
|
|
|
|
inline void sx_latch_at_savepoint(ulint savepoint, buf_block_t* block);
|
|
|
|
|
|
|
|
/** X-latch a not yet latched block after a savepoint. */
|
|
|
|
inline void x_latch_at_savepoint(ulint savepoint, buf_block_t* block);
|
|
|
|
|
|
|
|
/** Get the logging mode.
|
|
|
|
@return logging mode */
|
|
|
|
inline mtr_log_t get_log_mode() const
|
2016-09-06 09:43:16 +03:00
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** Change the logging mode.
|
|
|
|
@param mode logging mode
|
|
|
|
@return old mode */
|
|
|
|
inline mtr_log_t set_log_mode(mtr_log_t mode);
|
|
|
|
|
|
|
|
/** Copy the tablespaces associated with the mini-transaction
|
|
|
|
(needed for generating MLOG_FILE_NAME records)
|
|
|
|
@param[in] mtr mini-transaction that may modify
|
|
|
|
the same set of tablespaces as this one */
|
|
|
|
void set_spaces(const mtr_t& mtr)
|
|
|
|
{
|
2018-02-06 14:50:50 +01:00
|
|
|
ut_ad(!m_impl.m_user_space_id);
|
2016-08-12 11:17:45 +03:00
|
|
|
ut_ad(!m_impl.m_user_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Set the tablespace associated with the mini-transaction
|
|
|
|
(needed for generating a MLOG_FILE_NAME record)
|
|
|
|
@param[in] space_id user or system tablespace ID
|
|
|
|
@return the tablespace */
|
MDEV-12266: Change dict_table_t::space to fil_space_t*
InnoDB always keeps all tablespaces in the fil_system cache.
The fil_system.LRU is only for closing file handles; the
fil_space_t and fil_node_t for all data files will remain
in main memory. Between startup to shutdown, they can only be
created and removed by DDL statements. Therefore, we can
let dict_table_t::space point directly to the fil_space_t.
dict_table_t::space_id: A numeric tablespace ID for the corner cases
where we do not have a tablespace. The most prominent examples are
ALTER TABLE...DISCARD TABLESPACE or a missing or corrupted file.
There are a few functional differences; most notably:
(1) DROP TABLE will delete matching .ibd and .cfg files,
even if they were not attached to the data dictionary.
(2) Some error messages will report file names instead of numeric IDs.
There still are many functions that use numeric tablespace IDs instead
of fil_space_t*, and many functions could be converted to fil_space_t
member functions. Also, Tablespace and Datafile should be merged with
fil_space_t and fil_node_t. page_id_t and buf_page_get_gen() could use
fil_space_t& instead of a numeric ID, and after moving to a single
buffer pool (MDEV-15058), buf_pool_t::page_hash could be moved to
fil_space_t::page_hash.
FilSpace: Remove. Only few calls to fil_space_acquire() will remain,
and gradually they should be removed.
mtr_t::set_named_space_id(ulint): Renamed from set_named_space(),
to prevent accidental calls to this slower function. Very few
callers remain.
fseg_create(), fsp_reserve_free_extents(): Take fil_space_t*
as a parameter instead of a space_id.
fil_space_t::rename(): Wrapper for fil_rename_tablespace_check(),
fil_name_write_rename(), fil_rename_tablespace(). Mariabackup
passes the parameter log=false; InnoDB passes log=true.
dict_mem_table_create(): Take fil_space_t* instead of space_id
as parameter.
dict_process_sys_tables_rec_and_mtr_commit(): Replace the parameter
'status' with 'bool cached'.
dict_get_and_save_data_dir_path(): Avoid copying the fil_node_t::name.
fil_ibd_open(): Return the tablespace.
fil_space_t::set_imported(): Replaces fil_space_set_imported().
truncate_t: Change many member function parameters to fil_space_t*,
and remove page_size parameters.
row_truncate_prepare(): Merge to its only caller.
row_drop_table_from_cache(): Assert that the table is persistent.
dict_create_sys_indexes_tuple(): Write SYS_INDEXES.SPACE=FIL_NULL
if the tablespace has been discarded.
row_import_update_discarded_flag(): Remove a constant parameter.
2018-03-27 16:31:10 +03:00
|
|
|
fil_space_t* set_named_space_id(ulint space_id)
|
2016-08-12 11:17:45 +03:00
|
|
|
{
|
2018-02-06 14:50:50 +01:00
|
|
|
ut_ad(!m_impl.m_user_space_id);
|
2016-08-12 11:17:45 +03:00
|
|
|
ut_d(m_impl.m_user_space_id = space_id);
|
2018-02-06 14:50:50 +01:00
|
|
|
if (!space_id) {
|
2018-03-28 09:29:14 +03:00
|
|
|
return fil_system.sys_space;
|
2016-08-12 11:17:45 +03:00
|
|
|
} else {
|
2018-03-28 09:29:14 +03:00
|
|
|
ut_ad(m_impl.m_user_space_id == space_id);
|
|
|
|
ut_ad(!m_impl.m_user_space);
|
|
|
|
m_impl.m_user_space = fil_space_get(space_id);
|
|
|
|
ut_ad(m_impl.m_user_space);
|
|
|
|
return m_impl.m_user_space;
|
2016-08-12 11:17:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Set the tablespace associated with the mini-transaction
|
|
|
|
(needed for generating a MLOG_FILE_NAME record)
|
|
|
|
@param[in] space user or system tablespace */
|
2018-03-28 09:29:14 +03:00
|
|
|
void set_named_space(fil_space_t* space)
|
|
|
|
{
|
2018-04-29 09:41:42 +03:00
|
|
|
ut_ad(!m_impl.m_user_space_id);
|
2018-03-28 09:29:14 +03:00
|
|
|
ut_d(m_impl.m_user_space_id = space->id);
|
2018-04-29 09:41:42 +03:00
|
|
|
if (space->id) {
|
2018-03-28 09:29:14 +03:00
|
|
|
m_impl.m_user_space = space;
|
|
|
|
}
|
|
|
|
}
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
#ifdef UNIV_DEBUG
|
2016-08-12 11:17:45 +03:00
|
|
|
/** Check the tablespace associated with the mini-transaction
|
|
|
|
(needed for generating a MLOG_FILE_NAME record)
|
|
|
|
@param[in] space tablespace
|
|
|
|
@return whether the mini-transaction is associated with the space */
|
|
|
|
bool is_named_space(ulint space) const;
|
MDEV-12266: Change dict_table_t::space to fil_space_t*
InnoDB always keeps all tablespaces in the fil_system cache.
The fil_system.LRU is only for closing file handles; the
fil_space_t and fil_node_t for all data files will remain
in main memory. Between startup to shutdown, they can only be
created and removed by DDL statements. Therefore, we can
let dict_table_t::space point directly to the fil_space_t.
dict_table_t::space_id: A numeric tablespace ID for the corner cases
where we do not have a tablespace. The most prominent examples are
ALTER TABLE...DISCARD TABLESPACE or a missing or corrupted file.
There are a few functional differences; most notably:
(1) DROP TABLE will delete matching .ibd and .cfg files,
even if they were not attached to the data dictionary.
(2) Some error messages will report file names instead of numeric IDs.
There still are many functions that use numeric tablespace IDs instead
of fil_space_t*, and many functions could be converted to fil_space_t
member functions. Also, Tablespace and Datafile should be merged with
fil_space_t and fil_node_t. page_id_t and buf_page_get_gen() could use
fil_space_t& instead of a numeric ID, and after moving to a single
buffer pool (MDEV-15058), buf_pool_t::page_hash could be moved to
fil_space_t::page_hash.
FilSpace: Remove. Only few calls to fil_space_acquire() will remain,
and gradually they should be removed.
mtr_t::set_named_space_id(ulint): Renamed from set_named_space(),
to prevent accidental calls to this slower function. Very few
callers remain.
fseg_create(), fsp_reserve_free_extents(): Take fil_space_t*
as a parameter instead of a space_id.
fil_space_t::rename(): Wrapper for fil_rename_tablespace_check(),
fil_name_write_rename(), fil_rename_tablespace(). Mariabackup
passes the parameter log=false; InnoDB passes log=true.
dict_mem_table_create(): Take fil_space_t* instead of space_id
as parameter.
dict_process_sys_tables_rec_and_mtr_commit(): Replace the parameter
'status' with 'bool cached'.
dict_get_and_save_data_dir_path(): Avoid copying the fil_node_t::name.
fil_ibd_open(): Return the tablespace.
fil_space_t::set_imported(): Replaces fil_space_set_imported().
truncate_t: Change many member function parameters to fil_space_t*,
and remove page_size parameters.
row_truncate_prepare(): Merge to its only caller.
row_drop_table_from_cache(): Assert that the table is persistent.
dict_create_sys_indexes_tuple(): Write SYS_INDEXES.SPACE=FIL_NULL
if the tablespace has been discarded.
row_import_update_discarded_flag(): Remove a constant parameter.
2018-03-27 16:31:10 +03:00
|
|
|
/** Check the tablespace associated with the mini-transaction
|
|
|
|
(needed for generating a MLOG_FILE_NAME record)
|
|
|
|
@param[in] space tablespace
|
|
|
|
@return whether the mini-transaction is associated with the space */
|
|
|
|
bool is_named_space(const fil_space_t* space) const;
|
2014-02-26 19:11:54 +01:00
|
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/** Read 1 - 4 bytes from a file page buffered in the buffer pool.
|
|
|
|
@param ptr pointer from where to read
|
|
|
|
@param type) MLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES
|
|
|
|
@return value read */
|
|
|
|
inline ulint read_ulint(const byte* ptr, mlog_id_t type) const
|
2016-09-06 09:43:16 +03:00
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** Locks a rw-latch in S mode.
|
|
|
|
NOTE: use mtr_s_lock().
|
|
|
|
@param lock rw-lock
|
|
|
|
@param file file name from where called
|
|
|
|
@param line line number in file */
|
2017-03-01 08:27:39 +02:00
|
|
|
inline void s_lock(rw_lock_t* lock, const char* file, unsigned line);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** Locks a rw-latch in X mode.
|
|
|
|
NOTE: use mtr_x_lock().
|
|
|
|
@param lock rw-lock
|
|
|
|
@param file file name from where called
|
|
|
|
@param line line number in file */
|
2017-03-01 08:27:39 +02:00
|
|
|
inline void x_lock(rw_lock_t* lock, const char* file, unsigned line);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** Locks a rw-latch in X mode.
|
|
|
|
NOTE: use mtr_sx_lock().
|
|
|
|
@param lock rw-lock
|
|
|
|
@param file file name from where called
|
|
|
|
@param line line number in file */
|
2017-03-01 08:27:39 +02:00
|
|
|
inline void sx_lock(rw_lock_t* lock, const char* file, unsigned line);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** Acquire a tablespace X-latch.
|
|
|
|
NOTE: use mtr_x_lock_space().
|
|
|
|
@param[in] space_id tablespace ID
|
|
|
|
@param[in] file file name from where called
|
|
|
|
@param[in] line line number in file
|
|
|
|
@return the tablespace object (never NULL) */
|
|
|
|
fil_space_t* x_lock_space(
|
|
|
|
ulint space_id,
|
|
|
|
const char* file,
|
2017-03-01 08:27:39 +02:00
|
|
|
unsigned line);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** Release an object in the memo stack.
|
|
|
|
@param object object
|
|
|
|
@param type object type: MTR_MEMO_S_LOCK, ...
|
|
|
|
@return bool if lock released */
|
|
|
|
bool memo_release(const void* object, ulint type);
|
2016-09-06 09:43:16 +03:00
|
|
|
/** Release a page latch.
|
|
|
|
@param[in] ptr pointer to within a page frame
|
|
|
|
@param[in] type object type: MTR_MEMO_PAGE_X_FIX, ... */
|
|
|
|
void release_page(const void* ptr, mtr_memo_type_t type);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** Note that the mini-transaction has modified data. */
|
|
|
|
void set_modified()
|
|
|
|
{
|
|
|
|
m_impl.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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get the LSN of commit().
|
|
|
|
@return the commit LSN
|
|
|
|
@retval 0 if the transaction only modified temporary tablespaces */
|
|
|
|
lsn_t commit_lsn() const
|
|
|
|
{
|
|
|
|
ut_ad(has_committed());
|
|
|
|
return(m_commit_lsn);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Note that we are inside the change buffer code. */
|
|
|
|
void enter_ibuf()
|
|
|
|
{
|
|
|
|
m_impl.m_inside_ibuf = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Note that we have exited from the change buffer code. */
|
|
|
|
void exit_ibuf()
|
|
|
|
{
|
|
|
|
m_impl.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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
@return true if the mini-transaction is active */
|
|
|
|
bool is_active() const
|
|
|
|
{
|
|
|
|
return(m_impl.m_state == MTR_STATE_ACTIVE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get flush observer
|
|
|
|
@return flush observer */
|
|
|
|
FlushObserver* get_flush_observer() const
|
|
|
|
{
|
|
|
|
return(m_impl.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;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef UNIV_DEBUG
|
|
|
|
/** Check if memo contains the given item.
|
|
|
|
@param memo memo stack
|
|
|
|
@param object, object to search
|
|
|
|
@param type type of object
|
|
|
|
@return true if contains */
|
|
|
|
static bool memo_contains(
|
MDEV-11831 Make InnoDB mini-transaction memo checks stricter
InnoDB keeps track of buffer-fixed buf_block_t or acquired rw_lock_t
within a mini-transaction. There are some memo_contains assertions
in the code that document when certain blocks or rw_locks must be held.
But, these assertions only check the mini-transaction memo, not the fact
whether the rw_lock_t are actually being held by the caller.
btr_pcur_store_position(): Remove #ifdef, and assert that the block
is always buffer-fixed.
rtr_pcur_getnext_from_path(), rtr_pcur_open_low(),
ibuf_rec_get_page_no_func(), ibuf_rec_get_space_func(),
ibuf_rec_get_info_func(), ibuf_rec_get_op_type_func(),
ibuf_build_entry_from_ibuf_rec_func(), ibuf_rec_get_volume_func(),
ibuf_get_merge_page_nos_func(), ibuf_get_volume_buffered_count_func()
ibuf_get_entry_counter_low_func(), page_set_ssn_id(),
row_vers_old_has_index_entry(), row_vers_build_for_consistent_read(),
row_vers_build_for_semi_consistent_read(),
trx_undo_prev_version_build():
Make use of mtr_memo_contains_page_flagged().
mtr_t::memo_contains(): Take a const memo. Assert rw_lock_own().
FindPage, FlaggedCheck: Assert rw_lock_own_flagged().
2017-01-18 12:53:35 +02:00
|
|
|
const mtr_buf_t* memo,
|
|
|
|
const void* object,
|
|
|
|
ulint type)
|
2016-09-06 09:43:16 +03:00
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** Check if memo contains the given item.
|
|
|
|
@param object object to search
|
|
|
|
@param flags specify types of object (can be ORred) of
|
|
|
|
MTR_MEMO_PAGE_S_FIX ... values
|
|
|
|
@return true if contains */
|
|
|
|
bool memo_contains_flagged(const void* ptr, ulint flags) const;
|
|
|
|
|
|
|
|
/** Check if memo contains the given page.
|
2016-09-06 09:43:16 +03:00
|
|
|
@param[in] ptr pointer to within buffer frame
|
|
|
|
@param[in] flags specify types of object with OR of
|
2016-08-12 11:17:45 +03:00
|
|
|
MTR_MEMO_PAGE_S_FIX... values
|
2016-09-06 09:43:16 +03:00
|
|
|
@return the block
|
|
|
|
@retval NULL if not found */
|
|
|
|
buf_block_t* memo_contains_page_flagged(
|
|
|
|
const byte* ptr,
|
|
|
|
ulint flags) const;
|
|
|
|
|
|
|
|
/** Mark the given latched page as modified.
|
|
|
|
@param[in] ptr pointer to within buffer frame */
|
|
|
|
void memo_modify_page(const byte* ptr);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** Print info of an mtr handle. */
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @return true if mini-transaction contains modifications. */
|
|
|
|
bool has_modifications() const
|
|
|
|
{
|
|
|
|
return(m_impl.m_modifications);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @return the memo stack */
|
|
|
|
const mtr_buf_t* get_memo() const
|
|
|
|
{
|
|
|
|
return(&m_impl.m_memo);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @return the memo stack */
|
|
|
|
mtr_buf_t* get_memo()
|
|
|
|
{
|
|
|
|
return(&m_impl.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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Note that a record has been added to the log */
|
|
|
|
void added_rec()
|
|
|
|
{
|
|
|
|
++m_impl.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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Push an object to an mtr memo stack.
|
|
|
|
@param object object
|
|
|
|
@param type object type: MTR_MEMO_S_LOCK, ... */
|
|
|
|
inline void memo_push(void* object, mtr_memo_type_t type);
|
|
|
|
|
|
|
|
/** Check if this mini-transaction is dirtying a clean page.
|
|
|
|
@param block block being x-fixed
|
|
|
|
@return true if the mtr is dirtying a clean page. */
|
2019-06-16 15:55:09 +03:00
|
|
|
static inline bool is_block_dirtied(const buf_block_t* block)
|
2016-09-06 09:43:16 +03:00
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
class Command;
|
|
|
|
|
|
|
|
friend class Command;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Impl m_impl;
|
|
|
|
|
|
|
|
/** LSN at commit time */
|
|
|
|
volatile lsn_t m_commit_lsn;
|
|
|
|
};
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
#include "mtr0mtr.ic"
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
#endif /* mtr0mtr_h */
|