So imagine you have a table and for every row it contains an INT
that represents a user, a medium int that represents an activity
number, and a ENUM that represents state.
CREATE TABLE UserStack (
id int unsigned not null default 0,
activity medium int unsigned not null default 0,
state ENUM('ready','processing','processed', 'error'),
PRIMARY KEY(id),
INDEX (state, activity)
) ENGINE = INNODB;
Now you have an application that is spread across many servers
which pops a set of users off the stack and sets them to a
processing state.
START TRANSACTION
SELECT * FROM UserStack WHERE state='ready' ORDER BY activity DESC LIMIT 10 FOR UPDATE
foreach id
Mark them Processing
If multiple threads do this at the same time; the 1st thread will …