-
Couldn't load subscription status.
- Fork 2.5k
Performance improvement for partitions with a large number of steps #716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -178,14 +178,28 @@ JobExecution createJobExecution(String jobName, JobParameters jobParameters) | |
| */ | ||
| void updateExecutionContext(JobExecution jobExecution); | ||
|
|
||
| /** | ||
| * @return all step executions, from all job executions, for the given job instance. | ||
| */ | ||
| Collection<StepExecution> getStepExecutions(JobInstance jobInstance); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can use Java 8 "default method in interface" for backward compatibility here. For example: default Collection<StepExecution> getStepExecutions(JobInstance jobInstance) {
throw new UnsupportedOperationException();
} |
||
|
|
||
| /** | ||
| * @param jobInstance {@link JobInstance} instance containing the step executions. | ||
| * @param stepName the name of the step execution that might have run. | ||
| * @return the last execution of step for the given job instance. | ||
| * @return the last execution of step for the given job instance, null otherwise. | ||
| */ | ||
| @Nullable | ||
| StepExecution getLastStepExecution(JobInstance jobInstance, String stepName); | ||
|
|
||
| /** | ||
| * | ||
| * @param stepExecutions all step executions to filter through | ||
| * @param stepName the name of the step execution that might have run. | ||
| * @return the last execution of step inside the list, null otherwise. | ||
| */ | ||
| @Nullable | ||
| StepExecution getLastStepExecution(Collection<StepExecution> stepExecutions, String stepName); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Filtering a collection of objects by name is not the job of Here is how I would do it in @Nullable
protected StepExecution getLastStepExecution(Collection<StepExecution> stepExecutions, String stepName) {
return stepExecutions.stream()
.filter(stepExecution -> stepExecution.getStepName().equals(stepName))
.min(new StepExecutionComparator())
.orElse(null);
}The code of the comparator is what is done here: https://github.com/spring-projects/spring-batch/blob/master/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java#L236-L246 |
||
|
|
||
| /** | ||
| * @param jobInstance {@link JobInstance} instance containing the step executions. | ||
| * @param stepName the name of the step execution that might have run. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,6 +65,11 @@ public StepExecution getLastStepExecution(JobInstance jobInstance, String stepNa | |
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public StepExecution getLastStepExecution(Collection<StepExecution> stepExecutions, String stepName) { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public int getStepExecutionCount(JobInstance jobInstance, String stepName) { | ||
| return 0; | ||
|
|
@@ -91,6 +96,11 @@ public void updateExecutionContext(StepExecution stepExecution) { | |
| public void updateExecutionContext(JobExecution jobExecution) { | ||
| } | ||
|
|
||
| @Override | ||
| public Collection<StepExecution> getStepExecutions(JobInstance jobInstance) { | ||
| return null; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method can be removed since we will use the default method in interface. |
||
| } | ||
|
|
||
| @Override | ||
| public void addAll(Collection<StepExecution> stepExecutions) { | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,11 @@ public StepExecution getLastStepExecution(JobInstance jobInstance, String stepNa | |
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public StepExecution getLastStepExecution(Collection<StepExecution> stepExecutions, String stepName) { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public int getStepExecutionCount(JobInstance jobInstance, String stepName) { | ||
| return 0; | ||
|
|
@@ -99,6 +104,11 @@ public JobExecution getLastJobExecution(String jobName, JobParameters jobParamet | |
| public void updateExecutionContext(JobExecution jobExecution) { | ||
| } | ||
|
|
||
| @Override | ||
| public Collection<StepExecution> getStepExecutions(JobInstance jobInstance) { | ||
| return null; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should return an empty collection. |
||
| } | ||
|
|
||
| @Override | ||
| public void addAll(Collection<StepExecution> stepExecutions) { | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -510,6 +510,11 @@ public StepExecution getLastStepExecution(JobInstance jobInstance, String stepNa | |
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public StepExecution getLastStepExecution(Collection<StepExecution> stepExecutions, String stepName) { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public int getStepExecutionCount(JobInstance jobInstance, String stepName) { | ||
| return 0; | ||
|
|
@@ -557,6 +562,11 @@ public JobExecution getLastJobExecution(String jobName, JobParameters jobParamet | |
| public void updateExecutionContext(JobExecution jobExecution) { | ||
| } | ||
|
|
||
| @Override | ||
| public Collection<StepExecution> getStepExecutions(JobInstance jobInstance) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method can be removed since we will use the default method in interface. |
||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public void addAll(Collection<StepExecution> stepExecutions) { | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,11 @@ public StepExecution getLastStepExecution(JobInstance jobInstance, String stepNa | |
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public StepExecution getLastStepExecution(Collection<StepExecution> stepExecutions, String stepName) { | ||
| return null; | ||
| } | ||
|
|
||
| /* (non-Javadoc) | ||
| * @see org.springframework.batch.core.repository.JobRepository#getStepExecutionCount(org.springframework.batch.core.JobInstance, org.springframework.batch.core.Step) | ||
| */ | ||
|
|
@@ -75,6 +80,11 @@ public void updateExecutionContext(StepExecution stepExecution) { | |
| public void updateExecutionContext(JobExecution jobExecution) { | ||
| } | ||
|
|
||
| @Override | ||
| public Collection<StepExecution> getStepExecutions(JobInstance jobInstance) { | ||
| return null; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method can be removed since we will use the default method in interface. |
||
| } | ||
|
|
||
| public void add(StepExecution stepExecution) { | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isStartablerequires the current step execution as well as the latest one with the same name. So there is no need to pass the entire collection of step executions here. You can get the last one with the protected utility methodgetLastStepExecutionand pass it toisStartable.