Class ClusterAwarePartitionHandler

java.lang.Object
io.github.jchejarla.springbatch.clustering.partition.ClusterAwarePartitionHandler
All Implemented Interfaces:
org.springframework.batch.core.partition.PartitionHandler

public class ClusterAwarePartitionHandler extends Object implements org.springframework.batch.core.partition.PartitionHandler
A custom PartitionHandler that coordinates partition execution across a dynamic cluster of Spring Batch nodes using a shared relational database for metadata synchronization.

This handler assumes the master role for any job it launches, persisting partition metadata and monitoring execution progress. It enables decentralized task assignment, fault tolerance, and task reassignment in case of node failures.

Example usage:


 @Autowired
 ClusterAwarePartitionHandler partitionHandler;

 @Bean
 public Step multiNodeExecutionStep(JobRepository jobRepository, PlatformTransactionManager txnManager) {
     return new StepBuilder("multiNodeExecStep.manager", jobRepository)
             .partitioner("multiNodeExecStep", partitioner)
             .partitionHandler(partitionHandler)
             .step(multiNodeWorkerStep(jobRepository, txnManager))
             .build();
 }
 

Also see ClusterAwarePartitioner for implementing a custom partitioner compatible with this handler.

Since:
1.0
Author:
Janardhan Chejarla
  • Constructor Details

    • ClusterAwarePartitionHandler

      public ClusterAwarePartitionHandler()
  • Method Details

    • handle

      public Collection<org.springframework.batch.core.step.StepExecution> handle(org.springframework.batch.core.partition.StepExecutionSplitter stepSplitter, org.springframework.batch.core.step.StepExecution managerStepExecution) throws Exception
      Handles the splitting and coordination of partitioned steps across the cluster.

      This method registers the current node as the job master, persists partition metadata, and monitors execution until all tasks are complete. It ensures partition execution is coordinated and fault-tolerant across available nodes.

      Specified by:
      handle in interface org.springframework.batch.core.partition.PartitionHandler
      Parameters:
      stepSplitter - the splitter that creates individual partition steps
      managerStepExecution - the master step execution initiating the partitioning
      Returns:
      a collection of completed StepExecution instances
      Throws:
      Exception - if coordination or execution monitoring fails
    • areAllTasksCompleted

      protected boolean areAllTasksCompleted(long masterStepExecutionId) throws org.springframework.batch.core.job.JobExecutionException
      Throws:
      org.springframework.batch.core.job.JobExecutionException
    • pollForOrphanedTasksAndReArrange

      protected void pollForOrphanedTasksAndReArrange(long masterStepExecutionId) throws org.springframework.batch.core.job.JobExecutionException
      Throws:
      org.springframework.batch.core.job.JobExecutionException