Live data from Hacker News

A proposal for more reliable locks using Redis

antirez.com

11–20 of 27 posts

Re: A proposal for more reliable locks using Redis

#11
> Step 2) It tries to acquire the lock in all the N instances sequentially, using the same key name and random value in all the instances.

> so ideally the client should try to send the SET commands to the N instances at the same time using multiplexing.

I am confused. Are the locks requested sequentially, or at the same time? It seem like if they are requested sequentially, the the random backoff time would need to be a large multiple of the combined latency.

Re: A proposal for more reliable locks using Redis

#12
I finish reading after first paragraph... When do people will learn that using locks, shared memory does not work? It is just wrong. Things should be immutable, you should share nothing. And by nothing i mean nothing at all. It is just WRONG.

Re: A proposal for more reliable locks using Redis

#13

> Step 2) It tries to acquire the lock in all the N instances sequentially, using the same key name and random value in all the instances. > so ideally the client should try to send the SET commands to the N instances at the same time using multiplexing. I am confused. Are the locks requested sequentially, or at the same time? It seem like if they are requested sequentially, the the random backoff time would need to…

> I am confused. Are the locks requested sequentially, or at the same time? It seem like if they are requested sequentially, the the random backoff time would need to be a large multiple of the combined latency.

As stated in the post, it is ideal if using multiplexing we send the SET to all the instances at the same time, but this does not change a lot the difference between the chosen lock validity and the latency to set the lock, since with 5 instances it is still requires something in the "a few" millisecond range in the average to set the lock, with not very optimized clients, so 1 second is already three order of magnitude more.

Re: A proposal for more reliable locks using Redis

#14
post #10
post #5

Earlier quoted context omitted.

The proposed algorithm provides a safety guarantee which is time bound: once the lock is acquired it has a specified validity time, after this time, it is possible for another client to reacquire it. In practical terms this forces you to have the protected code path to be "real time", which is, guaranteed to terminate (or to abort) without the specified time.

>In practical terms this forces you to have the protected code path to be "real time", which is, guaranteed to terminate (or to abort) without the specified time. You could keep re-acquiring the lock when it gets close to expiring, and stop your process if the lock becomes un-acquirable.

Yes, this is a good strategy. We are even guaranteed to be able to re-acquire the log if we send the reacquire request in time, and there are no new partitions, because in order to reacquire the lock it is possible to send a script that checks if the value matches, and if so, we can extend the expire of the keys. Basically it is possible for the lock holder to reacquire by extending the duration of the previous lock before it expires.

Re: A proposal for more reliable locks using Redis

#15
post #12

I finish reading after first paragraph... When do people will learn that using locks, shared memory does not work? It is just wrong. Things should be immutable, you should share nothing. And by nothing i mean nothing at all. It is just WRONG.

I don't think you can simplify things that far. Shared-nothing is certainly a good architectural goal, and there are many types of distributed systems where it is both highly desirable and achievable. On the other hand, there are many distributed systems (and parallel systems) where coordination is strictly necessary.

Think about implementing something like the TPC-C load on a distributed database. Many parts of that load can be done sharded, with a shared-nothing model. Other parts need some level of coordination, and some need true serializability (which requires significant coordination). The pieces that can be built on shared-nothing primitives should be built on shared-nothing primitives. However, it's not useful to pretend that the pieces that require coordination simply don't exist.

Similarly, immutability is a good goal. An append-only log of immutable data items is often a very good mental model, and frequently a good implementation model, for distributed databases. It isn't universally applicable, though, and may put constraints on the possible supportable operations that add complexity to other parts of the system.

Re: A proposal for more reliable locks using Redis

#16
The classic "Leases: an efficient fault-tolerant mechanism for distributed file cache consistency" (http://portal.acm.org/citation.cfm?id=74870) dating back to 1989 is a good read about these kinds of systems. It makes some interesting observations about the approach, and introduces the need for bounded drift.

I think antirez is saying "skew" here when "drift" would be more appropriate. The safety property appears to refer to the different in rates between clocks, rather than the difference in absolute values. That's a much more reasonable assumption, and is likely to be true even with very bad clock hardware over short periods of time.

Obviously the bounded drift assumption,

Re: A proposal for more reliable locks using Redis

#17
post #16

The classic "Leases: an efficient fault-tolerant mechanism for distributed file cache consistency" ( http://portal.acm.org/citation.cfm?id=74870 ) dating back to 1989 is a good read about these kinds of systems. It makes some interesting observations about the approach, and introduces the need for bounded drift. I think antirez is saying "skew" here when "drift" would be more appropriate. The safety property appears…

> The safety property appears to refer to the different in rates between clocks, rather than the difference in absolute values.

Exactly that, thanks for the correction, indeed the word I used is wrong, even if probably from the context it was understandable I was referring to drift I'm going to replace the term.

Re: A proposal for more reliable locks using Redis

#18
post #13

> Step 2) It tries to acquire the lock in all the N instances sequentially, using the same key name and random value in all the instances. > so ideally the client should try to send the SET commands to the N instances at the same time using multiplexing. I am confused. Are the locks requested sequentially, or at the same time? It seem like if they are requested sequentially, the the random backoff time would need to…

> I am confused. Are the locks requested sequentially, or at the same time? It seem like if they are requested sequentially, the the random backoff time would need to be a large multiple of the combined latency. As stated in the post, it is ideal if using multiplexing we send the SET to all the instances at the same time, but this does not change a lot the difference between the chosen lock validity and the latency t…

Thanks, I understand. The sequential locking isn't a requirement per-se, and the assumption is that the N-masters are in the same region. It seems like with clever multiplexing, you could relax the requirement the N-masters are in the same region.

Re: A proposal for more reliable locks using Redis

#19
post #13

Earlier quoted context omitted.

> I am confused. Are the locks requested sequentially, or at the same time? It seem like if they are requested sequentially, the the random backoff time would need to be a large multiple of the combined latency. As stated in the post, it is ideal if using multiplexing we send the SET to all the instances at the same time, but this does not change a lot the difference between the chosen lock validity and the latency t…

Thanks, I understand. The sequential locking isn't a requirement per-se, and the assumption is that the N-masters are in the same region. It seems like with clever multiplexing, you could relax the requirement the N-masters are in the same region.

Definitely, even without proper multiplexing, if the connections are not blocking, it is possible to just lower the latency to MAX(latencies) sending the commands in a loop to all the instances, and later reading them.

Redis clients should be capable to do that, by allowing to separate (on demand) the command delivering from the reply reading moments.

Re: A proposal for more reliable locks using Redis

#20
post #6
post #5

Earlier quoted context omitted.

The proposed algorithm provides a safety guarantee which is time bound: once the lock is acquired it has a specified validity time, after this time, it is possible for another client to reacquire it. In practical terms this forces you to have the protected code path to be "real time", which is, guaranteed to terminate (or to abort) without the specified time.

It seems like a timeout is less reliable/safe than some broadcast/ping mechanism that can check availability perpetually and if a node has disappeared the validity of the lock changes. Trying to remember which distributed system model it is that sort of does this. Ring? Mesh?

That could increase throughput if you have a lot of crashing nodes but how does it improve safety or reliability?
Post reply on HN