Named locks across a cluster?


#1

My assumption is that named locks don’t work across a cluster, or am I wrong?

The ability to lock execution across a cluster seems powerful. Would it be a good feature to add? Is it possible? Are there existing patterns/solutions out there that do this?


#2

You are correct, named locks are specific to a JVM/Lucee instance. You’d need to use a file system or DB based approach to have a shared locking mechanism. The common issue there is how do you handle if a process “dies” while holding the lock and the other servers just wait forever.


#3

Could there a good argument for baking this into Lucee? Would it be hard to do? Or is this something that devs are happier doing themselves?

I have a cluster that is using memcached for sessions, which I could also use for locking. But I don’t want to have to implement a locking strategy… seems a bit low level.


#4

You could take a look at this library from Ryan Guill: cfml-redlock. It is for Redis, not Memcached, but it is an example of a distributed locking system.


#5

Seems to me that this could be a good feature request… maybe some discussion is needed on how it would be implemented. Perhaps you could specify the storage system where named locks would be set in application.cfc:

this.lockCluster = true;
this.lockStorage = "mylockstore"

#6

I was working on a Lucee extension for this exact thing. It is actually very similar to the cfml-redlock library. I had it working pretty good but there were a few minor bugs to work out. Hopefully my schedule will free up soon so I can finish it.


#7

@Yamaha32088, awesome… would it work with memcached?


#8

The extension I am writing is using Redisson so it wouldn’t be compatible with Memcached. I could however make it flexible enough to allow database, Redis and Memcached distributed locking but the primary focus would be Redis in the first version.


#9

Cool… the reason I ask is because I already have memcached running. I think your extension would be an excellent contribution to the community. Post back when you get it running and I’ll give it a try.