Disclaimer: I already asked this question, but without the
deployment requirement. I got an
answer that got 3 upvotes, and when I
edited the question to include the deployment requirement the answer then
became irrelevant. The reason I’m
resubmitting is because SO considers
the original question ‘answered’, even
though I got no meaningful upvoted
answer. I opened a uservoice
submission about this problem.
The reason I reposted is so StackOverflow consider the original question answered, so it doesn’t show up on the ‘unanswered questions’ tab.
Which distributed lock service would you use?
Requirements are:
- A mutual exclusion (lock) that can be seen from different processes/machines
- lock…release semantics
- Automatic lock release after a certain timeout – if lock holder dies, it will automatically be freed after X seconds
- Java implementation
- Easy deployment – must not require complicated deployment beyond either Netapp, MySql or GigaSpaces. Must play well with those products (especially GigaSpaces – this is why TerraCotta was ruled out).
- Nice to have: .Net implementation
- If it’s free: Deadlock detection / mitigation
I’m not interested in answers like “it can be done over a database”, or “it can be done over JavaSpaces” – I know. Relevant answers should only contain a ready, out-of-the-box, proven implementation.
Here’s the outline of a GigaSpaces based answer that meets your criteria, depending on exactly what you mean in criteria 3. I work with GigaSpaces from .Net, not Java:
Create a locking class with a SpaceID+SpaceRouting property IDing what is locked and a DataMember bool property Unlocked:
You will use GigaSpaces’ lease time for lock release after a certain
timeout. This will cause GigaSpaces to remove IdLockTrans objects
from the space automatically after they have been idle for the timeout
period. The lack of an IdLockTrans for an ID means the ID is unlocked.
Your locker class will define and initialize these class members