MySQL: GET_LOCK limits and issues

雨燕双飞 提交于 2019-12-11 02:31:01

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!