summaryrefslogtreecommitdiff
path: root/storage/innobase/include
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2017-03-09 23:20:51 +0200
committerMarko Mäkelä <marko.makela@mariadb.com>2017-03-13 18:57:17 +0200
commit13e5c9de800254dc80a4ba4cc98d788be899acb6 (patch)
tree992cc747be5a45c75902ff0c8c2b90f98dfdb2d5 /storage/innobase/include
parent056ec4ab2412ffbb2a54a274677a578e86433095 (diff)
downloadmariadb-git-13e5c9de800254dc80a4ba4cc98d788be899acb6.tar.gz
MDEV-12219 Discard temporary undo logs at transaction commit
Starting with MySQL 5.7, temporary tables in InnoDB are handled differently from persistent tables. Because temporary tables are private to a connection, concurrency control and multi-versioning (MVCC) are not applicable. For performance reasons, purge is disabled as well. Rollback is supported for temporary tables; that is why we have the temporary undo logs in the first place. Because MVCC and purge are disabled for temporary tables, we should discard all temporary undo logs already at transaction commit, just like we discard the persistent insert_undo logs. Before this change, update_undo logs were being preserved. trx_temp_undo_t: A wrapper for temporary undo logs, comprising a rollback segment and a single temporary undo log. trx_rsegs_t::m_noredo: Use trx_temp_undo_t. (Instead of insert_undo, update_undo, there will be a single undo.) trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove. trx_undo_add_page(): Remove the parameter undo_ptr. Acquire and release the rollback segment mutex inside the function. trx_undo_free_last_page(): Remove the parameter trx. trx_undo_truncate_end(): Remove the parameter trx, and add the parameter is_temp. Clean up the code a bit. trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo. trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup(). Replace the parameter undo_ptr with undo. This will discard the temporary undo or insert_undo log at commit/rollback. trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup(): Remove 3 parameters. Always operate on the persistent update_undo. trx_serialise(): Renamed from trx_serialisation_number_get(). trx_write_serialisation_history(): Simplify the code flow. If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO. trx_commit_in_memory(): Simplify the logic, and add assertions. trx_undo_page_report_modify(): Keep a direct reference to the persistent update_undo log. trx_undo_report_row_operation(): Simplify some code. Always assign TRX_UNDO_INSERT for temporary undo logs. trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs. trx_roll_try_truncate(): Remove the parameter undo_ptr. Try to truncate all 3 undo logs of the transaction. trx_roll_pop_top_rec_of_trx_low(): Remove. trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter trx->roll_limit. Clear roll_limit when exhausting the undo logs. Consider all 3 undo logs at once, prioritizing the persistent undo logs. row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx() reset the trx->roll_limit.
Diffstat (limited to 'storage/innobase/include')
-rw-r--r--storage/innobase/include/trx0purge.h5
-rw-r--r--storage/innobase/include/trx0roll.h35
-rw-r--r--storage/innobase/include/trx0trx.h15
-rw-r--r--storage/innobase/include/trx0trx.ic27
-rw-r--r--storage/innobase/include/trx0undo.h117
-rw-r--r--storage/innobase/include/trx0undo.ic6
6 files changed, 73 insertions, 132 deletions
diff --git a/storage/innobase/include/trx0purge.h b/storage/innobase/include/trx0purge.h
index ef4024d9908..a99f65a97f3 100644
--- a/storage/innobase/include/trx0purge.h
+++ b/storage/innobase/include/trx0purge.h
@@ -58,13 +58,8 @@ void
trx_purge_add_update_undo_to_history(
/*=================================*/
trx_t* trx, /*!< in: transaction */
- trx_undo_ptr_t* undo_ptr, /*!< in: update undo log. */
page_t* undo_page, /*!< in: update undo log header page,
x-latched */
- bool update_rseg_history_len,
- /*!< in: if true: update rseg history
- len else skip updating it. */
- ulint n_added_logs, /*!< in: number of logs added */
mtr_t* mtr); /*!< in: mtr */
/*******************************************************************//**
This function runs a purge batch.
diff --git a/storage/innobase/include/trx0roll.h b/storage/innobase/include/trx0roll.h
index ec4c7d57e5d..1f2e98b9708 100644
--- a/storage/innobase/include/trx0roll.h
+++ b/storage/innobase/include/trx0roll.h
@@ -1,6 +1,7 @@
/*****************************************************************************
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2015, 2017, 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
@@ -50,32 +51,16 @@ trx_savept_t
trx_savept_take(
/*============*/
trx_t* trx); /*!< in: transaction */
-/********************************************************************//**
-Pops the topmost record when the two undo logs of a transaction are seen
-as a single stack of records ordered by their undo numbers.
-@return undo log record copied to heap, NULL if none left, or if the
-undo number of the top record would be less than the limit */
-trx_undo_rec_t*
-trx_roll_pop_top_rec_of_trx_low(
-/*============================*/
- trx_t* trx, /*!< in/out: transaction */
- trx_undo_ptr_t* undo_ptr, /*!< in: rollback segment to look
- for next undo log record. */
- undo_no_t limit, /*!< in: least undo number we need */
- roll_ptr_t* roll_ptr, /*!< out: roll pointer to undo record */
- mem_heap_t* heap); /*!< in/out: memory heap where copied */
-
-/********************************************************************//**
-Get next undo log record from redo and noredo rollback segments.
-@return undo log record copied to heap, NULL if none left, or if the
-undo number of the top record would be less than the limit */
+
+/** Get the last undo log record of a transaction (for rollback).
+@param[in,out] trx transaction
+@param[out] roll_ptr DB_ROLL_PTR to the undo record
+@param[in,out] heap memory heap for allocation
+@return undo log record copied to heap
+@retval NULL if none left or the roll_limit (savepoint) was reached */
trx_undo_rec_t*
-trx_roll_pop_top_rec_of_trx(
-/*========================*/
- trx_t* trx, /*!< in: transaction */
- undo_no_t limit, /*!< in: least undo number we need */
- roll_ptr_t* roll_ptr, /*!< out: roll pointer to undo record */
- mem_heap_t* heap); /*!< in: memory heap where copied */
+trx_roll_pop_top_rec_of_trx(trx_t* trx, roll_ptr_t* roll_ptr, mem_heap_t* heap)
+ MY_ATTRIBUTE((nonnull, warn_unused_result));
/*******************************************************************//**
Rollback or clean up any incomplete transactions which were
diff --git a/storage/innobase/include/trx0trx.h b/storage/innobase/include/trx0trx.h
index c6011c13d12..55f80f584c5 100644
--- a/storage/innobase/include/trx0trx.h
+++ b/storage/innobase/include/trx0trx.h
@@ -856,6 +856,14 @@ struct trx_undo_ptr_t {
NULL if no update performed yet */
};
+/** An instance of temporary rollback segment. */
+struct trx_temp_undo_t {
+ /** temporary rollback segment, or NULL if not assigned yet */
+ trx_rseg_t* rseg;
+ /** pointer to the undo log, or NULL if nothing logged yet */
+ trx_undo_t* undo;
+};
+
/** Rollback segments assigned to a transaction for undo logging. */
struct trx_rsegs_t {
/** undo log ptr holding reference to a rollback segment that resides in
@@ -863,10 +871,9 @@ struct trx_rsegs_t {
to be recovered on crash. */
trx_undo_ptr_t m_redo;
- /** undo log ptr holding reference to a rollback segment that resides in
- temp tablespace used for undo logging of tables that doesn't need
- to be recovered on crash. */
- trx_undo_ptr_t m_noredo;
+ /** undo log for temporary tables; discarded immediately after
+ transaction commit/rollback */
+ trx_temp_undo_t m_noredo;
};
enum trx_rseg_type_t {
diff --git a/storage/innobase/include/trx0trx.ic b/storage/innobase/include/trx0trx.ic
index 14d519351e4..e5fdcec919a 100644
--- a/storage/innobase/include/trx0trx.ic
+++ b/storage/innobase/include/trx0trx.ic
@@ -226,18 +226,6 @@ trx_is_redo_rseg_updated(
}
/********************************************************************//**
-Check if noredo rseg is modified for insert/update. */
-UNIV_INLINE
-bool
-trx_is_noredo_rseg_updated(
-/*=======================*/
- const trx_t* trx) /*!< in: transaction */
-{
- return(trx->rsegs.m_noredo.insert_undo != 0
- || trx->rsegs.m_noredo.update_undo != 0);
-}
-
-/********************************************************************//**
Check if redo/noredo rseg is modified for insert/update. */
UNIV_INLINE
bool
@@ -245,20 +233,7 @@ trx_is_rseg_updated(
/*================*/
const trx_t* trx) /*!< in: transaction */
{
- return(trx_is_redo_rseg_updated(trx)
- || trx_is_noredo_rseg_updated(trx));
-}
-
-/********************************************************************//**
-Check if redo/nonredo rseg is valid. */
-UNIV_INLINE
-bool
-trx_is_rseg_assigned(
-/*=================*/
- const trx_t* trx) /*!< in: transaction */
-{
- return(trx->rsegs.m_redo.rseg != NULL
- || trx->rsegs.m_noredo.rseg != NULL);
+ return(trx_is_redo_rseg_updated(trx) || trx->rsegs.m_noredo.undo);
}
/**
diff --git a/storage/innobase/include/trx0undo.h b/storage/innobase/include/trx0undo.h
index 043d1dda22f..dcfbaaa02de 100644
--- a/storage/innobase/include/trx0undo.h
+++ b/storage/innobase/include/trx0undo.h
@@ -35,6 +35,15 @@ Created 3/26/1996 Heikki Tuuri
#include "page0types.h"
#include "trx0xa.h"
+/** The LSB of the "is insert" flag in DB_ROLL_PTR */
+#define ROLL_PTR_INSERT_FLAG_POS 55
+/** The LSB of the 7-bit trx_rseg_t::id in DB_ROLL_PTR */
+#define ROLL_PTR_RSEG_ID_POS 48
+/** The LSB of the 32-bit undo log page number in DB_ROLL_PTR */
+#define ROLL_PTR_PAGE_POS 16
+/** The LSB of the 16-bit byte offset within an undo log page in DB_ROLL_PTR */
+#define ROLL_PTR_BYTE_POS 0
+
/***********************************************************************//**
Builds a roll pointer.
@return roll pointer */
@@ -194,57 +203,31 @@ trx_undo_get_first_rec(
ulint mode,
mtr_t* mtr);
-/********************************************************************//**
-Tries to add a page to the undo log segment where the undo log is placed.
-@return X-latched block if success, else NULL */
+/** Allocate an undo log page.
+@param[in,out] trx transaction
+@param[in,out] undo undo log
+@param[in,out] mtr mini-transaction that does not hold any page latch
+@return X-latched block if success
+@retval NULL on failure */
buf_block_t*
-trx_undo_add_page(
-/*==============*/
- trx_t* trx, /*!< in: transaction */
- trx_undo_t* undo, /*!< in: undo log memory object */
- trx_undo_ptr_t* undo_ptr, /*!< in: assign undo log from
- referred rollback segment. */
- mtr_t* mtr) /*!< in: mtr which does not have
- a latch to any undo log page;
- the caller must have reserved
- the rollback segment mutex */
+trx_undo_add_page(trx_t* trx, trx_undo_t* undo, mtr_t* mtr)
MY_ATTRIBUTE((nonnull, warn_unused_result));
-/********************************************************************//**
-Frees the last undo log page.
-The caller must hold the rollback segment mutex. */
+
+/** Free the last undo log page. The caller must hold the rseg mutex.
+@param[in,out] undo undo log
+@param[in,out] mtr mini-transaction that does not hold any undo log page
+ or that has allocated the undo log page */
void
-trx_undo_free_last_page_func(
-/*==========================*/
-#ifdef UNIV_DEBUG
- const trx_t* trx, /*!< in: transaction */
-#endif /* UNIV_DEBUG */
- trx_undo_t* undo, /*!< in/out: undo log memory copy */
- mtr_t* mtr) /*!< in/out: mini-transaction which does not
- have a latch to any undo log page or which
- has allocated the undo log page */
+trx_undo_free_last_page(trx_undo_t* undo, mtr_t* mtr)
MY_ATTRIBUTE((nonnull));
-#ifdef UNIV_DEBUG
-# define trx_undo_free_last_page(trx,undo,mtr) \
- trx_undo_free_last_page_func(trx,undo,mtr)
-#else /* UNIV_DEBUG */
-# define trx_undo_free_last_page(trx,undo,mtr) \
- trx_undo_free_last_page_func(undo,mtr)
-#endif /* UNIV_DEBUG */
-/***********************************************************************//**
-Truncates an undo log from the end. This function is used during a rollback
-to free space from an undo log. */
+/** Truncate the tail of an undo log during rollback.
+@param[in,out] undo undo log
+@param[in] limit all undo logs after this limit will be discarded
+@param[in] is_temp whether this is temporary undo log */
void
-trx_undo_truncate_end_func(
-/*=======================*/
- trx_t* trx, /*!< in: transaction whose undo log it is */
- trx_undo_t* undo, /*!< in/out: undo log */
- undo_no_t limit) /*!< in: all undo records with undo number
- >= this value should be truncated */
- MY_ATTRIBUTE((nonnull(1,2)));
-
-#define trx_undo_truncate_end(trx, undo, limit) \
- trx_undo_truncate_end_func(trx, undo, limit)
+trx_undo_truncate_end(trx_undo_t* undo, undo_no_t limit, bool is_temp)
+ MY_ATTRIBUTE((nonnull));
/** Truncate the head of an undo log.
NOTE that only whole pages are freed; the header page is not
@@ -269,20 +252,23 @@ ulint
trx_undo_lists_init(
/*================*/
trx_rseg_t* rseg); /*!< in: rollback segment memory object */
-/**********************************************************************//**
-Assigns an undo log for a transaction. A new undo log is created or a cached
-undo log reused.
-@return DB_SUCCESS if undo log assign successful, possible error codes
-are: DB_TOO_MANY_CONCURRENT_TRXS DB_OUT_OF_FILE_SPACE DB_READ_ONLY
-DB_OUT_OF_MEMORY */
+/** Assign an undo log for a transaction.
+A new undo log is created or a cached undo log reused.
+@param[in,out] trx transaction
+@param[in] rseg rollback segment
+@param[out] undo the undo log
+@param[in] type TRX_UNDO_INSERT or TRX_UNDO_UPDATE
+@retval DB_SUCCESS on success
+@retval DB_TOO_MANY_CONCURRENT_TRXS
+@retval DB_OUT_OF_FILE_SPACE
+@retval DB_READ_ONLY
+@retval DB_OUT_OF_MEMORY */
dberr_t
trx_undo_assign_undo(
-/*=================*/
- trx_t* trx, /*!< in: transaction */
- trx_undo_ptr_t* undo_ptr, /*!< in: assign undo log from
- referred rollback segment. */
- ulint type) /*!< in: TRX_UNDO_INSERT or
- TRX_UNDO_UPDATE */
+ trx_t* trx,
+ trx_rseg_t* rseg,
+ trx_undo_t** undo,
+ ulint type)
MY_ATTRIBUTE((nonnull, warn_unused_result));
/******************************************************************//**
Sets the state of the undo log segment at a transaction finish.
@@ -315,24 +301,17 @@ trx_undo_update_cleanup(
/*====================*/
trx_t* trx, /*!< in: trx owning the update
undo log */
- trx_undo_ptr_t* undo_ptr, /*!< in: update undo log. */
page_t* undo_page, /*!< in: update undo log header page,
x-latched */
- bool update_rseg_history_len,
- /*!< in: if true: update rseg history
- len else skip updating it. */
- ulint n_added_logs, /*!< in: number of logs added */
mtr_t* mtr); /*!< in: mtr */
-/** Frees an insert undo log after a transaction commit or rollback.
-Knowledge of inserts is not needed after a commit or rollback, therefore
+/** Free an insert or temporary undo log after commit or rollback.
+The information is not needed after a commit or rollback, therefore
the data can be discarded.
-@param[in,out] undo_ptr undo log to clean up
-@param[in] noredo whether the undo tablespace is redo logged */
+@param[in,out] undo undo log
+@param[in] is_temp whether this is temporary undo log */
void
-trx_undo_insert_cleanup(
- trx_undo_ptr_t* undo_ptr,
- bool noredo);
+trx_undo_commit_cleanup(trx_undo_t* undo, bool is_temp);
/********************************************************************//**
At shutdown, frees the undo logs of a PREPARED transaction. */
diff --git a/storage/innobase/include/trx0undo.ic b/storage/innobase/include/trx0undo.ic
index a0790022d7f..0285c212bdd 100644
--- a/storage/innobase/include/trx0undo.ic
+++ b/storage/innobase/include/trx0undo.ic
@@ -47,9 +47,9 @@ trx_undo_build_roll_ptr(
ut_ad(rseg_id < TRX_SYS_N_RSEGS);
ut_ad(offset < 65536);
- roll_ptr = (roll_ptr_t) is_insert << 55
- | (roll_ptr_t) rseg_id << 48
- | (roll_ptr_t) page_no << 16
+ roll_ptr = (roll_ptr_t) is_insert << ROLL_PTR_INSERT_FLAG_POS
+ | (roll_ptr_t) rseg_id << ROLL_PTR_RSEG_ID_POS
+ | (roll_ptr_t) page_no << ROLL_PTR_PAGE_POS
| offset;
return(roll_ptr);
}