You can use MySQL's built in locking, or you can do this:
Find a job that is waiting
Run an update like this:
UPDATE table SET status = 'processing'
WHERE jobid = found_job AND status = 'waiting'
If you get back a 1 from that query, it made one change, and you're good. If
you get back 0 (no rows updated) someone beat you to it.
j----- k-----
On Wednesday 03 March 2004 05:14 pm, tofu optimist wrote:
> Hi. I am new to my my sql and have a basic question about locking.
> I am running Ver 11.18 Distrib 3.23.54, for Win95/Win98.
>
> I have a table that holds work on jobs needing processing
>
> Field Type Null Key Default Extra
> ------- ------------- ------ ------- --------------
> jobid int(11) PRI (NULL) auto_increment
> status enum('waiting','processing','done','failed') YES waiting
> created timestamp(14) YES (NULL)
> details varchar(255) YES (NULL)
>
> Right now, a single process checks this table occasionally.
> If it finds rows in 'waiting' status, it grabs the info,
> sets the row to 'processing', and does the computation.
> Upon completion, the process stores the results elsewhere,
> sets the row to 'done' (or failed, if it failed), looks for
> more work to do, and sleeps a bit if there is no futher processing
> to be done now.
>
> For speed, I'd now like several processes to grab work from the table.
>
> I am not sure how mysql handles locking.
>
> While a process is seizing a row (changing row status from
> 'waiting' to 'processing'), how do I prevent another process
> from grabbing the same row?
>
> Thanks for any help or advice
>
> -TO
--
Joshua J. Kugler
Fairbanks, Alaska
Computer Consultant--Systems Designer
.--- --- ... .... ..- .- -.- ..- --. .-.. . .-.
[EMAIL PROTECTED]
ICQ#:13706295
Every knee shall bow, and every tongue confess, in heaven, on earth, and under
the earth, that Jesus Christ is LORD -- Count on it!
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]