Reputation: 1011
Our (Spring) application contains several Schedulers
which become active during the night to change/update some data (from Database
) in Batch
.
This is all running fine, the problem is that our application will soon run in a clustered environment
.
What are the best options to prevent a scheduler
of instance A
and instance B
are doing the same work at the same time?
** UPDATE **
Clustered environment is setup as 'active-active'
.
Each node communicates with it's own database instance. Each database instance will replicate
data to the other instances.
DB-instances are not setup as 'master-slave'
but will run in a Galera cluster
where each instance executes insert-update-delete operations.
So each scheduler
should run only once on one instance. The other instances should not run the schedulers. So I need to find a way the a Scheduler of one instance runs, the same schedulers of the other instances should not run.
Upvotes: 6
Views: 4519
Reputation: 1011
Just for completeness: we ended up with persistent Quartz job scheduling
.
This post helped me a lot about persistent Quartz scheduling
with Spring
.
Upvotes: 5
Reputation: 1254
You're not saying what sort of Schedulers
you're using.
What you're looking for is persistant scheduling. JEE has support for this, and Quartz has too. Spring out of the box does not, although it integrates quiet nicely with Quartz if you want to.
With persistant schedulers, jobs are added to the database, and triggers are run in a "transaction"(not sure if it's an actual transaction), ensuring that only one scheduler can run the trigger.
It requires some database tables for management, however.
Upvotes: 1
Reputation: 3611
You should delegate different tasks to the nodes in your cluster. What work is happening to the database at night?
If the nodes are clustered correctly behind a load balancer, only one should receive the update to write to a database.
You can use Zookeeper
to manage nodes and set a primary to perform sole scheduling.
Upvotes: 1
Reputation: 984
You will have code to handle that scheduled event in both clusters. There are two approaches.
I prefer second approach - write once.
Upvotes: 1