user2054927
user2054927

Reputation: 1011

Scheduler in clustered environment

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

Answers (4)

user2054927
user2054927

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

Koos Gadellaa
Koos Gadellaa

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

UserF40
UserF40

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

Gaurava Agarwal
Gaurava Agarwal

Reputation: 984

You will have code to handle that scheduled event in both clusters. There are two approaches.

  1. You can choose to run this event in any one cluster. Then you need to make sure when this cluster is down, You would switch scheduler in other cluster. And similar maintenance issues.
  2. You can choose to run such events in both clusters. Difference in implementation such a way that all clusters will poll and any one cluster will successfully run it. You can choose database or jms message for polling/locking.

I prefer second approach - write once.

Upvotes: 1

Related Questions