Create an Account
username: password:
 
  MemeStreams Logo

MemeStreams Discussion

search


This page contains all of the posts and discussion on MemeStreams referencing the following web page: Journal of toby (759) - InnoDB as a Queue for Worker Bees. You can find discussions on MemeStreams as you surf the web, even if you aren't a MemeStreams member, using the Threads Bookmarklet.

Journal of toby (759) - InnoDB as a Queue for Worker Bees
by Lost at 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)


 
 
Powered By Industrial Memetics