Page 1 of 1

MySQL and locking mechanism

Posted: Fri 22 Jun 2007 14:58
by GuzunNicolae
Hello

I have a serious problem.

I have an application for Data entry. It takes a field one by one and presents the user to enter data.
I have a manual locking mechanism. The table with data has a boolean field, so when smb wants to edit the record it is set to True thus preventing other users to take it.

The procedure is as follows:
- Start transaction
- Get first matching record
- Set lock field to true
- Commit transaction

If two concurent users try to Get the same first matching record one of them waits until the other one commits transaction so it sees that it is manually locked and skips it.
Everything works fine until some point where application freezes.

Can you tell me where the problem can be? I think this is due to a deadlock somewhere. How MyDAC copes with deadlocks? Is there a mechanism to know that a dead lock appears?

Thanks. Bye

Posted: Sat 23 Jun 2007 13:41
by Antaeus
MyDAC has no mechanisms to recognize deadlocks, and cope with them. Setting the CommandTimeout option may be useful for you to prevent applications from freezing.

Posted: Sat 23 Jun 2007 13:42
by Antaeus
Probably this topic of MySQL Reference Manual will help you to solve the problem.

Posted: Mon 25 Jun 2007 08:06
by GuzunNicolae
I set CommandTimeout to 100 and it still freezez application.
Is this possible?

I thought it will raise an exception.

Posted: Tue 26 Jun 2007 15:12
by Antaeus
The commend timeout property is measured in seconds. Does it mean that your application does not raise an exception after 2 minutes?

Posted: Wed 27 Jun 2007 13:55
by GuzunNicolae
I thought it was measured in milliseconds.
Anyway I put it to 2 and I do not get the exception.

Well I get it when the query really exceeds this time, but I do not get it when my application waits for the lock.

Posted: Wed 27 Jun 2007 17:03
by Antaeus
Thank you for information. We have reproduced this problem and fixed it. This fix will be included in the next MyDAC build.
Please send me at evgeniyd*crlab*com a small test sample to make sure that this fix also solves the problem you have encountered.

Posted: Thu 28 Jun 2007 06:38
by GuzunNicolae
Very good. Thanks

But I want to know, what exactly have you fixed?
The application freezing or the Query to raise exception?

If the first can you please tell me what was the problem?

And when will be the next release of MyDAC? I need to solve this problem as fast as possible. The project already started.

Posted: Tue 03 Jul 2007 13:49
by Antaeus
We performed some additional investigation of this problem. It looks like the best way to solve this problem is to change the value of the innodb_lock_wait_timeout server variable.
Managing lock timeout by MyDAC causes some additional difficulties. There is no simple way to avoid them.

Posted: Tue 03 Jul 2007 14:00
by Antaeus
If this is not an appropriate solution for you, please send me at evgeniyd*crlab*com a complete small application that demonstrated this issue.