Commit 4997e9b2 authored by vasil's avatar vasil

Add the number of locks acquired by a transaction to its weight when

choosing the lightest transaction to kill when a deadlock occurs.
This fixes Bug#21293 partially.

Approved by:	Heikki
parent a3208f42
...@@ -371,6 +371,17 @@ trx_is_interrupted( ...@@ -371,6 +371,17 @@ trx_is_interrupted(
#define trx_is_interrupted(trx) FALSE #define trx_is_interrupted(trx) FALSE
#endif /* !UNIV_HOTBACKUP */ #endif /* !UNIV_HOTBACKUP */
/***********************************************************************
Compares the "weight" (or size) of two transactions. The weight of one
transaction is estimated as the number of altered rows + the number of
locked rows. */
int
trx_weight_cmp(
/*===========*/
/* out: <0, 0 or >0; similar to strcmp(3) */
trx_t* a, /* in: the first transaction to be compared */
trx_t* b); /* in: the second transaction to be compared */
/* Signal to a transaction */ /* Signal to a transaction */
struct trx_sig_struct{ struct trx_sig_struct{
......
...@@ -3357,8 +3357,8 @@ lock_deadlock_recursive( ...@@ -3357,8 +3357,8 @@ lock_deadlock_recursive(
return(LOCK_VICTIM_IS_START); return(LOCK_VICTIM_IS_START);
} }
if (ut_dulint_cmp(wait_lock->trx->undo_no, if (trx_weight_cmp(wait_lock->trx,
start->undo_no) >= 0) { start) >= 0) {
/* Our recursion starting point /* Our recursion starting point
transaction is 'smaller', let us transaction is 'smaller', let us
choose 'start' as the victim and roll choose 'start' as the victim and roll
......
...@@ -1773,6 +1773,24 @@ trx_print( ...@@ -1773,6 +1773,24 @@ trx_print(
} }
} }
/***********************************************************************
Compares the "weight" (or size) of two transactions. The weight of one
transaction is estimated as the number of altered rows + the number of
locked rows. */
int
trx_weight_cmp(
/*===========*/
/* out: <0, 0 or >0; similar to strcmp(3) */
trx_t* a, /* in: the first transaction to be compared */
trx_t* b) /* in: the second transaction to be compared */
{
#define TRX_WEIGHT(t) \
ut_dulint_add((t)->undo_no, UT_LIST_GET_LEN((t)->trx_locks))
return(ut_dulint_cmp(TRX_WEIGHT(a), TRX_WEIGHT(b)));
}
/******************************************************************** /********************************************************************
Prepares a transaction. */ Prepares a transaction. */
......
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