mysql:像SQS一样独占选择?
有没有办法在mysql上模拟Amazon SQS消息选择机制(独占选择)?我需要这个来将一个 mysql 表用于多个 ec2 实例,这些实例将处理并删除其中的行。
select ... for update
并不完全是我想要的,因为它锁定了 select 上的线程,并且不返回未锁定的实例。
Is there any way to simulate Amazon SQS message selection mechanism on mysql (exclusive selects)? I need this to use one mysql table for multiple ec2 instances that will process and delete rows from it.
select ... for update
doesn't quite what I want because it locks a thread on select, and not returns not locked instances.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最终我想到了这个想法(现在没有实现):
更改目标表,添加列lock_name,lock_time
在每次迭代中:
2.1。更新 target_table set lock_time = now(), lock_name = 'controller_instance_name' 其中 lock_time < now() - 可见性超时
2.2。 select * from target_table where lock_name = 'controller_instance_name' and lock_time > now() -
select 中每个项目的visibilityTimeout 2.3
2.3.1 处理它
2.3.2 将其从表中删除:从 target_table 中删除,其中 id = ?
每个控制器实例将能够在锁定超过visibilityTimeout 值后选择行。
Eventually I came to this idea (don't implemented now):
alter target table, add columns lock_name, lock_time
on each iteration:
2.1. update target_table set lock_time = now(), lock_name = 'controller_instance_name' where lock_time < now() - visibilityTimeout
2.2. select * from target_table where lock_name = 'controller_instance_name' and lock_time > now() - visibilityTimeout
2.3 for each item in select
2.3.1 handle it
2.3.2 remove it from table: delete from target_table where id = ?
Each controller instance will be able to select row after it was locked more than on visibilityTimeout value.