0

My application uses a custom key-value store as data persistence layer. This key-value store is developed in-house and has some APIs to work with, however, it does not provide anything around transaction management or locking (especially distributed locking).

Now, we as the user of this key-value store need to develop such a locking/transaction management system. Could someone help showing how such a distributed locking can be implemented? Is Apache Zookeeper is worth looking at?

We use Java 7.

Thanks, NN

Niranjan
  • 2,601
  • 8
  • 43
  • 54
  • So you're going to... layer Zookeeper on top of your custom, transactionless storage engine? I'm not sure what to say, other than this appears to be opinion based and not suitable for SO. – markspace Sep 03 '14 at 05:46
  • 1
    @markspace as you said this is very opinion based, many people don't like to lock/whatever on the DB level as DB is supposed to be fast and there's a trend to do it in a higher layer. Also he's not asking if it's a good idea but what can be used/how can it be done. – Mateusz Dymczyk Sep 03 '14 at 05:49
  • @MateuszDymczyk: that's actually interesting. I didn't flag the OP btw, I was just pointing out that his question might not be suitable. Personally I wish SO was more lenient towards opinion based questions and answers. – markspace Sep 03 '14 at 06:02

1 Answers1

1

Plenty of options out there, many of them will even tell you how to do it:

Anything that's distributed and in-memory could be a good candidate (and it actually works) is a good candidate. Personally at work we are using ZK (to be more precise Curator to make it even easier) and it works well. Some of the libraries we are using do it with Hazelcast and it doesn't seem to be any worse

Mateusz Dymczyk
  • 14,969
  • 10
  • 59
  • 94
  • Thanks for this reply; one quick question: to implement distributed lock using any of these would require a cluster running these...is my understanding correct? If I start writing my own implementation of distributed lock (by just taking ideas from these), it will take more time and I have to handle a lot of internal things. Isn't it? – Niranjan Sep 03 '14 at 22:50
  • @Niranjan well yes usually when you want to write something by yourself it will take more time than using an existing library :-)) But I don't fully understand - if you want a distributed lock that means you already have some kind of a distributed environment, right? You just use the above technologies in there and that's it. For instance you have your DB access layer in your app and before doing something on a table you check if anyone else is using it by acquiring a lock, that's it. – Mateusz Dymczyk Sep 04 '14 at 01:10
  • let me explain my scenario and plz give some guidance. Our data model is little complicated (e.g. we store 4 independent entities `Book`, `Author`, `BookAuthors` and `AuthorBooks` while creating a Book). Our WAR file is deployed on multiple independent JVMs (i.e. non-cluster mode) from where we call separate putObject() methods for those 4 entities. Now, if I want to use HazelCast, where should I implement my lock and manage transaction? – Niranjan Sep 04 '14 at 03:47
  • in the place where you are doing your database saves. It doesn't really matter that you deploy your app in different JVMs, HazelCast cluster doesn't care if it's a different JVM on the same machine or different machines, it will try to create a cluster over TCP/IP (or some other protocol, don't quote me on this). So when you do a save you first poke hazelcast and take the lock. Each JVM will have it's own HazelCast object instance but in the end they will all communicate with each other. – Mateusz Dymczyk Sep 04 '14 at 04:11