Commit 765be34d 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 198d55d6
......@@ -371,6 +371,17 @@ trx_is_interrupted(
#define trx_is_interrupted(trx) FALSE
#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 */
struct trx_sig_struct{
......
......@@ -3357,8 +3357,8 @@ lock_deadlock_recursive(
return(LOCK_VICTIM_IS_START);
}
if (ut_dulint_cmp(wait_lock->trx->undo_no,
start->undo_no) >= 0) {
if (trx_weight_cmp(wait_lock->trx,
start) >= 0) {
/* Our recursion starting point
transaction is 'smaller', let us
choose 'start' as the victim and roll
......
......@@ -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. */
......
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