MySQL可以由于连续的共享锁而锁定锁定吗?
我有2个不同的交易,其中一个正在使用读取锁(共享 )的选择
语句,而另一种用途写锁( for Update )。
假设他们正在尝试在同一行上获取锁。这是我试图理解正在发生的事情的情况。
假设我使用读取锁有连续的请求流,偶尔需要获取写锁。
这些锁是否使用FIFO策略来避免饥饿或其他一些策略(例如阅读锁),只要它可以获取锁定和写锁定锁会等待所有读数(即使在这种情况下是新的)。
我怀疑第二次可能发生,但我不确定。
我正在调查一个问题,但找不到有关此问题的好文件。
I have 2 different transactions where one is using read locks (FOR SHARE
) for SELECT
statements and the other uses write locks (FOR UPDATE
).
Let's say they are trying to acquire the lock on the same row. Here's the scenario I'm trying to understand what's happening.
Let's say I have continuous stream of requests using the read locks and occasionally I need to acquire the write lock.
Are these locks using FIFO strategy to avoid starvation or some other strategy such as read locks would be acquired as long as it can acquire the lock and write lock would wait all the reads to drain (even the new ones in this case).
I'm suspecting 2nd might be happening but I'm not 100% sure.
I'm investigating an issue and couldn't find a good documentation about this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您缺乏文档,则可以尝试一个实验:
窗口1:
窗口2:
窗口3:
这表明X-Lock请求阻止了后续的S锁请求。
50秒通过,然后是:
窗口2:
然后立即:
窗口3:
窗口3中的选择在等待窗口2中的更新时被阻止。当更新时间时,窗口3中的选择可以继续进行。
If you lack documentation, you can try an experiment:
Window 1:
Window 2:
Window 3:
This indicates that the X-lock request is blocking subsequent S-lock requests.
50 seconds passes, and then:
Window 2:
And then immediately:
Window 3:
The select in window 3 was blocked while waiting for the update in window 2. When the update timed out, then the select in window 3 was able to proceed.