Distributed lock management

59 views
Skip to first unread message

Simon Goldschmidt

unread,
Jan 13, 2016, 5:47:05 PM1/13/16
to Lucee
Since moving to a clustered environment, I noticed that <cflock scope="session"> is only aware of locks on the local node. Google turns up a solution using Redis, but I wondered if anyone had suggestions from their experience.

We use a datasource for session storage and include <cfset this.sessioncluster=true> in our Application.cfc.

If we're happy to throw an error in the case of a locking conflict, could we implement our own solution by declaring a session variable, checking to see if that variable exists before performing the code in the <cflock> block, then deleting the variable at the end of the block?

Thanks... Simon

Harry Klein

unread,
Jan 14, 2016, 3:24:52 AM1/14/16
to Lucee

Hi Simon,

 

so I guess you found this Github project from Ben Nadel https://github.com/bennadel/CFRedlock?

I can definitely recommend it, works great in our projects.

 

Cheers,

Harry

--
Love Lucee? Become a supporter and be part of the Lucee project today! - http://lucee.org/supporters/become-a-supporter.html
---
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/2c8dac65-0e26-430b-a5d2-562246423c76%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Simon Goldschmidt

unread,
Jan 16, 2016, 8:07:30 PM1/16/16
to Lucee
The alternative we're looking at is to use the database to manage the locking. We replace the <cflock> with the following:

<cftransaction>
<cfquery name="sessionlock" datasource="mydatasource">
  update customer set address=address where customer='#session.customerid#'
</cfquery>

block of locked code goes here

</cftransaction>

The update doesn't do anything but lock the rows of the database relevant to the session, so this has the same effect as <cflock scope="session">

Simon

Michael van Leest

unread,
Jan 17, 2016, 1:03:55 AM1/17/16
to lu...@googlegroups.com
@Simon: that example will work with a single server. If you have multiple servers, this is not thread safe. You might want to create a stored procedure and use a transaction in that procedure to make it thread safe for multiple webservers.

Hope that will work for you.

Mike

--
Love Lucee? Become a supporter and be part of the Lucee project today! - http://lucee.org/supporters/become-a-supporter.html
---
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Michael van Leest
Reply all
Reply to author
Forward
0 new messages