summaryrefslogtreecommitdiff
path: root/storage/xtradb/trx/trx0trx.cc
diff options
context:
space:
mode:
Diffstat (limited to 'storage/xtradb/trx/trx0trx.cc')
-rw-r--r--storage/xtradb/trx/trx0trx.cc71
1 files changed, 49 insertions, 22 deletions
diff --git a/storage/xtradb/trx/trx0trx.cc b/storage/xtradb/trx/trx0trx.cc
index 30d4b7f6546..12f680bd7e2 100644
--- a/storage/xtradb/trx/trx0trx.cc
+++ b/storage/xtradb/trx/trx0trx.cc
@@ -53,6 +53,9 @@ Created 3/26/1996 Heikki Tuuri
#include<set>
+extern "C"
+int thd_deadlock_victim_preference(const MYSQL_THD thd1, const MYSQL_THD thd2);
+
/** Set of table_id */
typedef std::set<table_id_t> table_id_set;
@@ -1725,6 +1728,38 @@ trx_assign_read_view(
return(trx->read_view);
}
+/********************************************************************//**
+Clones the read view from another transaction. All consistent reads within
+the receiver transaction will get the same read view as the donor transaction
+@return read view clone */
+UNIV_INTERN
+read_view_t*
+trx_clone_read_view(
+/*================*/
+ trx_t* trx, /*!< in: receiver transaction */
+ trx_t* from_trx) /*!< in: donor transaction */
+{
+ ut_ad(lock_mutex_own());
+ ut_ad(mutex_own(&trx_sys->mutex));
+ ut_ad(trx_mutex_own(from_trx));
+ ut_ad(trx->read_view == NULL);
+
+ if (from_trx->state != TRX_STATE_ACTIVE ||
+ from_trx->read_view == NULL) {
+
+ return(NULL);
+ }
+
+ trx->read_view = read_view_clone(from_trx->read_view,
+ trx->prebuilt_view);
+
+ read_view_add(trx->read_view);
+
+ trx->global_read_view = trx->read_view;
+
+ return(trx->read_view);
+}
+
/****************************************************************//**
Prepares a transaction for commit/rollback. */
UNIV_INTERN
@@ -2071,7 +2106,7 @@ state_ok:
if (trx->undo_no != 0) {
newline = TRUE;
- fprintf(f, ", undo log entries "TRX_ID_FMT, trx->undo_no);
+ fprintf(f, ", undo log entries " TRX_ID_FMT, trx->undo_no);
}
if (newline) {
@@ -2174,9 +2209,8 @@ trx_assert_started(
#endif /* UNIV_DEBUG */
/*******************************************************************//**
-Compares the "weight" (or size) of two transactions. Transactions that
-have edited non-transactional tables are considered heavier than ones
-that have not.
+Compares the "weight" (or size) of two transactions. The heavier the weight,
+the more reluctant we will be to choose the transaction as a deadlock victim.
@return TRUE if weight(a) >= weight(b) */
UNIV_INTERN
ibool
@@ -2185,26 +2219,19 @@ trx_weight_ge(
const trx_t* a, /*!< in: the first transaction to be compared */
const trx_t* b) /*!< in: the second transaction to be compared */
{
- ibool a_notrans_edit;
- ibool b_notrans_edit;
-
- /* If mysql_thd is NULL for a transaction we assume that it has
- not edited non-transactional tables. */
-
- a_notrans_edit = a->mysql_thd != NULL
- && thd_has_edited_nontrans_tables(a->mysql_thd);
-
- b_notrans_edit = b->mysql_thd != NULL
- && thd_has_edited_nontrans_tables(b->mysql_thd);
-
- if (a_notrans_edit != b_notrans_edit) {
+ int pref;
- return(a_notrans_edit);
+ /* First ask the upper server layer if it has any preference for which
+ to prefer as a deadlock victim. */
+ pref= thd_deadlock_victim_preference(a->mysql_thd, b->mysql_thd);
+ if (pref < 0) {
+ return FALSE;
+ } else if (pref > 0) {
+ return TRUE;
}
- /* Either both had edited non-transactional tables or both had
- not, we fall back to comparing the number of altered/locked
- rows. */
+ /* Upper server layer had no preference, we fall back to comparing the
+ number of altered/locked rows. */
#if 0
fprintf(stderr,
@@ -2371,7 +2398,7 @@ trx_recover_for_mysql(
ut_print_timestamp(stderr);
fprintf(stderr,
" InnoDB: Transaction contains changes"
- " to "TRX_ID_FMT" rows\n",
+ " to " TRX_ID_FMT " rows\n",
trx->undo_no);
count++;