Hi JB, Just a couple of quick thoughts, and others will likely jump in as well.
juanbackson wrote:
Hi, I have two distributed clients that need to write stuff to memcached, but each write will involve two records. These two records must be sync. So, they must be changed together.
You may be stretching the limits of what memcached is designed for here. By being simple, memcached is very, very fast and quite scalable, but doesn't provide features like distributed locks.
Is there anyway that I can lock on those two records and write them, so there won't be issue with two clients writing at the same time?
There are no locks available to clients of memcached, but with the use case you describe it should be possible to put both records into the same item stored in memcached. Since that item will always be consistent, you can be sure no two clients will write at the same time.
You may also look into the CAS operations which are part of memcached. With CAS, memcached allows one to implement some lock-free algorithms which can ensure, for instance, that a client will know that no other client has updated an item since that client last fetched it. It's not the same, but locking has overhead and you can accomplish a lot of things lock-free with CAS. It could fit your case, depending on what the relationship between those two items is.
Beyond that, there are some other distributed lock managers which one could use alongside memcached, but you're going further and further away from the common memcached deployments if we start talking about DLM.
Hope that helps, - Matt
