可以使用MySQL内置函数get_lock吗?

huangapple go评论55阅读模式
英文:

Can I use mysql's built-in function get_lock?

问题

只有翻译的部分:

有一个批处理作业在外部运行。有多台服务器可以处理这个作业。
我希望在特定时间只有一台服务器从众多服务器中获取并处理这个作业。

为了达到这个目的,在研究全局锁定机制时,我发现了MySQL的get_lock函数。

而且,由于已经存在对MySQL的依赖,我认为可以使用这个函数。

然而,令人怀疑的是,在寻找全局锁定机制时,大多数情况下使用的是Redis等,很难找到使用get_lock的案例。

所以我怀疑MySQL的get_lock是否存在任何缺点。

我目前的情况是MySQL已经在使用,但Redis没有在使用。

那么,我可以使用MySQL的get_lock进行全局锁定吗?
或者MySQL的get_lock是否存在任何缺点?

英文:

There is a batch job outside. And there are multiple servers which can process the job.
I want only one server among many servers to fetch and process the job at specific times.

For this purpose, while investigating the global locking mechanism, I found mysql's get_lock function.

Also, since there is already a dependency on mysql, I think I can use this function.

However, what is suspicious is that, when looking for the global locking mechanism, most of them use redis, etc., and it was difficult to find cases that use get_lock.

So I doubt there is any downside to mysql's get_lock.

My current situation is that mysql is already being used, but rather redis is not being used.

Then, can I use mysql's get_lock for global locking?
Or maybe is there a downside to mysql's get_lock?

答案1

得分: 1

已经投票关闭了这个问题,但是可能有一些指导意见会有所帮助。

据我理解,您有几台机器在处理相同的数据集 - 您想确保数据项的独占性。您似乎正在考虑一种咨询式的锁定机制,即数据使用者需要寻找锁定,然后在使用数据之前创建它们。咨询式锁定应仅在最后一种情况下使用:

  • 数据客户端需要明确选择锁定机制 - 随着系统变得更加复杂,有人可能会编写未能像其他所有内容一样使用锁定机制的代码。然后,问题就会出现。
  • 咨询式锁定会导致状态分散 - 锁定状态保存在与需要锁定的操作不同的位置。您现在处于CAP定理的领域。

请尝试重新发布有关数据汇和数据源以及可用资源的详细信息,而不是询问解决方案是否适用于未定义的问题。

英文:

Already voted to close this, but a few pointers might be helpful.

As I understand it, you have several machines processing the same dataset - you want to ensure exclusivity on data items. You seem to be considering an advisory locking mechanism, i.e. one in which data consumers need to go looking for locks then create them before using data. Advisory locking should only be used as a last resort:

  • data clients need to explicitly opt-in to the locking mechanism - as systems become more complex it becomes increasing likely that someone will write some code which fails to use the locking mechanism in the same way as everything else. Then stuff breaks
  • advisory locking leads to displaced state - the lock state is held in a different place from the action requiring the lock. You're now in land of CAP theorem

Try re-posting with details of the data sinks and sources and the resources available rather than asking if a solution is appropriate to an undefined problem.

huangapple
  • 本文由 发表于 2023年6月1日 18:05:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76380798.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定