spring-cloud / spring-cloud-commons

Common classes used in different Spring Cloud implementations
Apache License 2.0
708 stars 704 forks source link

Proposal : Out of the box support for distributed locks #173

Open daniellavoie opened 7 years ago

daniellavoie commented 7 years ago

I'll admit this might not be the best place to open the discussion but I couldn't find anywhere else.

Once upon a time we had Spring Cloud Cluster supporting Lock Registry which was deprecated into Spring Integration. Tell me if I am wrong but even if I add dependencies from Spring Integration it doesn't feel to me that it just works out of the box with the COC so dear to the Spring Boot phylosophy. We need to do a couple of plumbing to have something working out.

Distributed Locks for internal batches or croned services is a recurrent topic in my opinion in a distributed system. I would like to contribute to a starter module inspired by your sample Lock Server Demo. We have a starter server for Eureka and the Config Server. Why not treating locks as a first class citizen among the problems eased by Spring Cloud with a starter server project and a starter client.

I'll work on my own embeddable server and client but it feels to me that such feature would make sense to be part of the project.

spencergibb commented 7 years ago

What is 'COC'?

works out of the box with the COC so dear to the Spring Boot

See https://github.com/spring-cloud/spring-cloud-zookeeper/issues/93 for a similar request for leader election.

daniellavoie commented 7 years ago

Convention Over Configuration ;)

spencergibb commented 7 years ago

OK. I wouldn't call auto-configuration, convention over configuration though, but that's neither here nor there.

daniellavoie commented 7 years ago

Yeah sure, word abuse is easy.

I've been giving Spring Cloud training for a while and the same question keeps coming over and over : "What about croned tasks".

I wish I had a simple answer as easy as a config server or service discovery. As stated by the issue you sent me, SI is message oriented. I am also dreaming of a solution wider than Zookeeper. The sample lock server is interresting in that matter. I'm interested in gathering opinions.

Edit 2017/02/01 : So here is a first draft of a LockServer. It is more than freely inspired by the Config Server and Dave's locksdemo exemples (copy/pasted would be a better term).

https://github.com/daniellavoie/spring-cloud-lock

For what it's worth, it provides an @EnableLockServer annotation. Next step, I'll implement an auto-configurable client.

daniellavoie commented 7 years ago

I'll continue my work trying to implement a @LeaderOnly kind of annotation for the client. I really like that proposal from spring-cloud/spring-cloud-zookeeper#93.