Re: Reviewing a script to demo memcache get-set race conditions problems if it is used for distributed locking.

2016-06-06 Thread Nishant Varma
One more enhancement! I am also reviewing it in http://codereview.stackexchange.com/questions/131239/function-to-lock-a-file-using-memcache def addToCart(filename): ableToLock = memcache.add(filename, username) if ableToLock: if os.file.ispath(filename) # I have a loc

Re: Reviewing a script to demo memcache get-set race conditions problems if it is used for distributed locking.

2016-06-06 Thread Nishant Varma
Enhanced it a bit to to check if the file is really present as well before I proceed ... Btw this has to be done after obtaining the lock otherwise again race condition i.e not fileExists and ableToLock ableToLock and fileExists is the order. def addToCart(filename): ableToLock = memca

Re: Reviewing a script to demo memcache get-set race conditions problems if it is used for distributed locking.

2016-06-06 Thread Nishant Varma
> > key = filename > item = memcli:get(key) > if (! defined item) { > if (memcli:add(key . "_lock", lock_timeout_time, my_admin_username)) { > [etc] > } else { > # lost the race, handle how you want > } > } else if (item.value == my_admin_username) { > # good to go for t