News for hackers. Stuff that matters.
Re:Is Redlock Safe? Reply to Redlock Analysis by tptacek on Tuesday February 09, 2016 @11:21AM (#11066329)
Can you further explain your "check" and "set" storage example? I feel like you might be begging the question. "check" and "set" seem like they describe another lock. How does that lock time out?
Re:Is Redlock Safe? Reply to Redlock Analysis by antirez on Tuesday February 09, 2016 @11:25AM (#11066360)
Whatever you can mount with a random token is always simpler than checking if Token_ID_A < Token_ID_B which needs a linearizable store. But basically this is how it works:

You want to modify locked resource X. You set X.currlock = token. Then you read, do whatever you want, and when you write, you "write-if-currlock == token". If another client did X.currlock = somethingelse, the transaction fails.

Edit: note that I noticed some confusion about this. Any other client is free to replace X.currlock even if set to a past value.

Re:Is Redlock Safe? Reply to Redlock Analysis by kapitalx on Tuesday February 09, 2016 @12:13PM (#11066844)
The problem with this solution is that if A writes Token_A to resource, and then A dies, then the resource can never be written to again. How do you avoid not needing to time out the 'curr_lock'
Re:Is Redlock Safe? Reply to Redlock Analysis by SomeCallMeTim on Tuesday February 09, 2016 @02:21PM (#11067926)
No, when you acquire a lock, you are allowed to write to currlock immediately. It's AFTER you've done whatever processing you need to do that you do a compare-and-set transactional write that verifies no one else has written to currlock between your acquisition and the completion of your task.
Re:Is Redlock Safe? Reply to Redlock Analysis by bogdando on Wednesday February 10, 2016 @02:23AM (#11071226)
This pseudo code for random fence tokens should work as well safe as Martin's scenario with incremental IDs in the original article:

try

  token=lock.aquire

  val=raw(shared, key, token)

  do_things

  awar(shared, key, val, token)
except

  fail("Can't do!")
finally

  lock.release
Where a shared object has: 1) a key to store a value being changed in the critical section; 2) a currlock to store a random fence token associated with a lock. The raw reads the shared key's value after the currlock was written to the shared object. The awar does an atomic write of the value to the key, only if the currlock has an expected token (i.e. is unchanged).

When things go wrong, the do_things may be executed more than once, in parallel, but the key is safe and guaranteed to have no lost updates to its value.

Re:Is Redlock Safe? Reply to Redlock Analysis by viraptor on Tuesday February 09, 2016 @05:08PM (#11069190)
But your "write" action is separate from the "X.currlock" operations, right?

Doesn't it mean that this can happen?

    A: X.currlock = Token_ID_A
    A: resource read
    A: is X.currlock still Token_ID_A? yes
    B: X.currlock = Token_ID_B
    B: resource read
    B: is X.currlock still Token_ID_B? yes
    B: resource write
    A: resource write
Is there anything that makes the "write-if-currlock == token" operation atomic?
Re:Is Redlock Safe? Reply to Redlock Analysis by tptacek on Tuesday February 09, 2016 @05:20PM (#11069279)
Yes: it turns out, he's stipulating a single server, in which case this is a trivial feature to build. The problem then is, if you're willing to have that single point of failure, you don't need a lock service at all.
Re:Is Redlock Safe? Reply to Redlock Analysis by w8rbt on Tuesday February 09, 2016 @03:21PM (#11068454)
Perhaps he means test and set?

    https://en.wikipedia.org/wiki/Test-and-set
Or the more efficient test and test and set?

    https://en.wikipedia.org/wiki/Test_and_test-and-set