My question is similar to: Ignoring locked row in a MySQL query except that I have already implemented a logic close to what's suggested in the accepted answer. My question is how to set the process id initially. All servers run a query like (the code is in ruby on rails but the resulting mysql query is):
UPDATE (some_table) SET process_id=(some process_id) WHERE (some condition on row_1) AND process_id is null ORDER BY (row_1) LIMIT 100
Now what happens is all processes try to update the same rows, they get locked and they timeout waiting for the lock. I would like the servers to ignore the rows that are locked (because after the lock is released the process_id won't be null anymore so there is no point for locking here). I could try to randomize the batch of records to update but the problem is I want to prioritize the update based on row_1 as in the query above. So my question is, is there a way in mysql to check if a record is locked and ignore it if it is?