List:General Discussion« Previous MessageNext Message »
From:Paul McCullagh Date:March 9 2009 10:33pm
Subject:Re: InnoDB deadlocks
View as plain text  
Hi Mattia,

On Mar 9, 2009, at 6:21 PM, Mattia Merzi wrote:

> Hi everyone,
>
> I've got some problems with deadlocks on InnoDB tables.
> On paragraph 13.6.8.10. "How to Cope with Deadlocks"
> of the mysql 5.1 version, the last sentence states:
> --------------
> Another way to serialize transactions is to create an auxiliary
> “semaphore” table that contains just a single row.
> Have each transaction update that row before accessing other tables.
> In that way, all transactions happen in a serial fashion.
> Note that the InnoDB instant deadlock detection algorithm also works
> in this case, because the serializing lock is a row-level lock.
> With MySQL table-level locks, the timeout method must be used to
> resolve deadlocks.
> --------------
>
> Just two very simple questions:
> - using this method, transactions will be serialized so the deadlock
> problem will never come up again?

Yes.

But transactions will also no longer run in parallel which will reduce  
the throughput of the server if it is accessed by multiple clients.

>
>  This seems clear reading that sentence, the only thing that makes me
> humble is the statement:
>  "Note that the InnoDB instant deadlock detection algorithm also
> works in this case" ... can someone
>  briefly explain me this concept?
> - if I create a "semaphore" table and I start any deadlock-prone
> transaction issuing a "lock table .... write"
>  on that table and an unlock tables immediately after the commit,
> will the effect be the same?

Yes, this will work the same.

>  'Cause the last sentence of the manual says:
>  "With MySQL table-level locks, the timeout method must be used to
> resolve deadlocks"

This is true, but is only a problem if deadlocks are possible.  
However, deadlocks are not possible if you start every transaction  
with a "lock table .... write".
>
>  will this mean that if I use this LOCK TABLE method I can get
> timeouts instead of deadlocks
>  on the very same transactions?

Yes, this can happen. But, only if a deadlock is possible. By  
exclusive locking a single resource (a row or a table), at the start  
of each transaction, you explicitly make deadlocks impossible.

However, it is recommended to UPDATE a single row in the new table,  
instead of using "lock table .... write".

This has the same affect, but with the benefit that deadlock detection  
will still work in the case that you do not modify all transactions as  
suggested.

This might happen because:

- your code is vast, and you miss one, or
- you add a new transaction and forget to add the exclusive locking  
UPDATE, or
- you leave out certain transaction on purpose because you have never  
had deadlocking problems with them before.

All "good" reasons not to serialize all transactions, and therefore a  
good reason to use the method that continues to support deadlock  
detection.

Best regards,

Paul


--
Paul McCullagh
PrimeBase Technologies
www.primebase.org
www.blobstreaming.org
pbxt.blogspot.com


Thread
InnoDB deadlocksMattia Merzi9 Mar
  • Re: InnoDB deadlocksPaul McCullagh9 Mar
    • RE: InnoDB deadlocksJerry Schwartz10 Mar
      • Re: InnoDB deadlocksMattia Merzi10 Mar