简体   繁体   English

InnoDB:更新表上的锁定超时并有效地选择结果

[英]InnoDB: Update a lock timeout on table and select the result efficiently

I have an InnoDB table with a lock timeout column. 我有一个带有锁定超时列的InnoDB表。 If this column is null there is no lock, otherwise there is a lock that times out according to the timestamp in that column. 如果此列为null,则没有锁,否则,该锁将根据该列中的时间戳而超时。

The problem I am having is that there is alot of rows in this table, and many rows in this table are getting processed each minute, but the processing is currently following this model: 我遇到的问题是此表中有很多行,并且每分钟都在处理该表中的许多行,但是当前正在按照该模型进行处理:

1. select rows to be processed
2. iterate over rows to be processed in Java
     a. Try to acquire a lock on row
     b. if lock acquired, process row and continue; else continue

This gets inefficient really fast, so it would be great if I could instead just try to acquire a lock on all the rows to be processed, and then return the result set of rows for which the lock was acquired all in one transaction or a few more efficient transactions. 这会很快变得效率低下,所以如果我可以尝试在所有要处理的行上获取一个锁,然后返回一次或几笔事务都获取了该锁的行的结果集,那将是很好的选择更有效的交易。

What would you recommend? 你会推荐什么?

select only the rows which a lock can be acquired, using a where clause in your sql like 使用sql中的where子句,仅选择可以获取锁的行

where lock_timeout is null

Also, I hope if this has multiple threads, that you put a mutex or something on this whole section of code. 另外,我希望它有多个线程,您可以在整个代码段中放置一个互斥体或其他东西。 Everything from selecting the rows, until the locks are made. 从选择行,直到形成锁,所有的一切。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM