Its possible... but really... its a cache.  Thats what it is designed to do,
and that is what it is good for.  memcached is not optimized at all to be a
lock server, why exactly are you wanting to use memcached for this instead
of an actual lock server?

That being said, there are a number of issues when using memcached as a lock
server that would make it far less than ideal.

Also a default unlock after 5 minutes rather defeats the purpose of a lock
server...   I wouldn't recommend this at all.  Far better off with an actual
lock server that can defect if a client has disconnected.

Short answer:  No, do not use memcached as a lock server.

On Wed, Apr 8, 2009 at 9:44 PM, yatagarasu <igor.c...@gmail.com> wrote:

>
> Is it possible to implement distributed resource blocking using
> memcached ?
>
> Is it possible to implement them using following scheme (pseudocode)
>
> lock(a)
> 1. if (add( key=>a, expiration=>5min )) {
> 2.   if (cas( key=>a, expiration=>5min )) {
>            // resource locked by us
>      }
>      // Someone tried to lock resource the same time. Race condition
> in add.
>   }
>   // resource is already locked
>
> unlock(a)
> 1. delete(a)
>
> What do you think?
> Is race condition in add possible?
> Will such double check work?
> Or is there more simple way?
>
>
> PS. Expiration in 5min is used to auto unlock resource in case of
> client disconnection or other errors.




-- 
"Be excellent to each other"

Reply via email to