Create an Account
username: password:
 
  MemeStreams Logo

Journal of toby (759) - InnoDB as a Queue for Worker Bees

search

Lost
Picture of Lost
My Blog
My Profile
My Audience
My Sources
Send Me a Message

sponsored links

Lost's topics
Arts
Business
Games
Health and Wellness
Home and Garden
Miscellaneous
Current Events
Recreation
Local Information
Science
Society
Sports
Technology

support us

Get MemeStreams Stuff!


 
Journal of toby (759) - InnoDB as a Queue for Worker Bees
Topic: Technology 12:08 pm EDT, Apr  6, 2008

You have multiple worker processes/threads pulling records, FIFO, from a table. If one worker 'dies' or fails processing, another worker should retry the same record.

Here are some ideas (partially tested).

-- find first record & select it, taking exclusive lock
SELECT * FROM q WHERE id = (SELECT @id := MIN(id) FROM q) FOR UPDATE;

-- now other threads need to see that it's deleted (new MIN())
-- This only works where reading session is in READ UNCOMMITTED mode!
DELETE FROM q WHERE id = @id;

-- ... do whatever processing is required...

-- then either COMMIT (if successful)
-- or ROLLBACK (if processing failed and another worker should attempt)

Journal of toby (759) - InnoDB as a Queue for Worker Bees



 
 
Powered By Industrial Memetics
RSS2.0