I have an InnoDB table with a lock timeout column. If this column is null there is no lock, otherwise there is a lock that times out according to the timestamp in that column.
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
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.