问题
I a need a database level synchronization. For this I'm using GET_LOCK('prefix.some_id', 0). At some moment GET_LOCK returns 1 for same key in different scripts on different hosts. What could be the problem? I need lots of those locks, 5-7k approximately.
Any ideas?
回答1:
MySQL 5.7.5 and MariaDB 10.0.2 both support your use case now.
For MySQL see: http://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_get-lock
For MariaDB see: https://mariadb.com/kb/en/mariadb/documentation/functions-and-operators/miscellaneous-functions/get_lock/
回答2:
According to the documentation, you cannot hold more than one lock per connection via GET_LOCK()
(emphasis added):
If you have a lock obtained with GET_LOCK(), it is released when you execute RELEASE_LOCK(), execute a new GET_LOCK(), or your connection terminates (either normally or abnormally)
As Daniel posted, there is a feature request for this functionality, but it was filed in 2003 with no activity.
Depending on your use-case, you may be able to use MySQL's table or row-level locking to achieve what you want.
回答3:
Bug #1118 Allow multiple concurrent locks with GET_LOCK()
来源:https://stackoverflow.com/questions/7455784/mysql-get-lock-limits-and-issues