The memcache protocol has an INCR command, which atomically
increments a stored value. MySQL Cluster is able to take simple
operations (like incrementing a counter) and “push them down” to
run on a data node with a lock held. Acquire the lock, increment
the value, read it, and release the lock.
Originally in memcached, the incrementing sequence number was
local to one memcache server, and was also volatile. Whenever the
memcached server restarted, the sequence would be reset. Today,
though, we can put cluster and memcached together, and instead of
a volatile local sequence number, we get a durable and shared
one.
This is a very simple application, and I’m going to walk through
the whole thing. Keep reading to see the whole thing, start to
finish. In my example I’ll use MySQL Cluster 7.2.4 and the
memcached ASCII protocol. There is a minor (but annoying) bug,
already fixed in 7.2.6, that prevented this from working with the …
[Read more]