ResonantEcho
Programmer
I posted this earlier but not sure where it went. So... here I go again.
We have an application that runs every x minutes and looks for a row that is in a 'READY' status. A row represents a batch to be processed. We used to run one instance of the application. However, our volume has increased tremendously which requires us to run multiple instances to keep up. We noticed early on at times the same row (batch) would be grabbed by more than one instance causing the processed data to be duplicated.
Our current solution is to have each instance grab a different status (READY1, READY2, READY3, etc.). This is not ideal because we manually have to move them to these additional statuses.
The two queries within the application are as follows. The first query does a SELECT to see if there is a row in 'READY' status. If it finds one it immediatly does an UPDATE on that row and sets it to an 'ACTIV' status:
What is the proper way to prevent multiple instances of an application from selecting the same row?
We have an application that runs every x minutes and looks for a row that is in a 'READY' status. A row represents a batch to be processed. We used to run one instance of the application. However, our volume has increased tremendously which requires us to run multiple instances to keep up. We noticed early on at times the same row (batch) would be grabbed by more than one instance causing the processed data to be duplicated.
Our current solution is to have each instance grab a different status (READY1, READY2, READY3, etc.). This is not ideal because we manually have to move them to these additional statuses.
The two queries within the application are as follows. The first query does a SELECT to see if there is a row in 'READY' status. If it finds one it immediatly does an UPDATE on that row and sets it to an 'ACTIV' status:
Code:
SELECT TOP 1 columnid, column1, column2
FROM table
WHERE status = 'READY'
Code:
UPDATE table
SET status = 'ACTIV'
WHERE columnid = <columnid>
What is the proper way to prevent multiple instances of an application from selecting the same row?