Skip to content

Commit 327160a

Browse files
committed
Change metrics type from int to long in StepExecution
This change prevents integer overflows in steps operating on a large number of items. Resolves #3650
1 parent 78ddf44 commit 327160a

File tree

17 files changed

+96
-87
lines changed

17 files changed

+96
-87
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/StepContribution.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2019 the original author or authors.
2+
* Copyright 2006-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,19 +28,19 @@
2828
@SuppressWarnings("serial")
2929
public class StepContribution implements Serializable {
3030

31-
private volatile int readCount = 0;
31+
private volatile long readCount = 0;
3232

33-
private volatile int writeCount = 0;
33+
private volatile long writeCount = 0;
3434

35-
private volatile int filterCount = 0;
35+
private volatile long filterCount = 0;
3636

37-
private final int parentSkipCount;
37+
private final long parentSkipCount;
3838

39-
private volatile int readSkipCount;
39+
private volatile long readSkipCount;
4040

41-
private volatile int writeSkipCount;
41+
private volatile long writeSkipCount;
4242

43-
private volatile int processSkipCount;
43+
private volatile long processSkipCount;
4444

4545
private ExitStatus exitStatus = ExitStatus.EXECUTING;
4646

@@ -76,9 +76,9 @@ public ExitStatus getExitStatus() {
7676
/**
7777
* Increment the counter for the number of items processed.
7878
*
79-
* @param count int amount to increment by.
79+
* @param count long amount to increment by.
8080
*/
81-
public void incrementFilterCount(int count) {
81+
public void incrementFilterCount(long count) {
8282
filterCount += count;
8383
}
8484

@@ -92,9 +92,9 @@ public void incrementReadCount() {
9292
/**
9393
* Increment the counter for the number of items written.
9494
*
95-
* @param count int amount to increment by.
95+
* @param count long amount to increment by.
9696
*/
97-
public void incrementWriteCount(int count) {
97+
public void incrementWriteCount(long count) {
9898
writeCount += count;
9999
}
100100

@@ -103,7 +103,7 @@ public void incrementWriteCount(int count) {
103103
*
104104
* @return the item counter.
105105
*/
106-
public int getReadCount() {
106+
public long getReadCount() {
107107
return readCount;
108108
}
109109

@@ -112,7 +112,7 @@ public int getReadCount() {
112112
*
113113
* @return the item counter.
114114
*/
115-
public int getWriteCount() {
115+
public long getWriteCount() {
116116
return writeCount;
117117
}
118118

@@ -121,15 +121,15 @@ public int getWriteCount() {
121121
*
122122
* @return the filter counter
123123
*/
124-
public int getFilterCount() {
124+
public long getFilterCount() {
125125
return filterCount;
126126
}
127127

128128
/**
129129
* @return the sum of skips accumulated in the parent {@link StepExecution}
130130
* and this <code>StepContribution</code>.
131131
*/
132-
public int getStepSkipCount() {
132+
public long getStepSkipCount() {
133133
return readSkipCount + writeSkipCount + processSkipCount + parentSkipCount;
134134
}
135135

@@ -138,7 +138,7 @@ public int getStepSkipCount() {
138138
* <code>StepContribution</code> (not including skips accumulated in the
139139
* parent {@link StepExecution}).
140140
*/
141-
public int getSkipCount() {
141+
public long getSkipCount() {
142142
return readSkipCount + writeSkipCount + processSkipCount;
143143
}
144144

@@ -152,9 +152,9 @@ public void incrementReadSkipCount() {
152152
/**
153153
* Increment the read skip count for this contribution
154154
*
155-
* @param count int amount to increment by.
155+
* @param count long amount to increment by.
156156
*/
157-
public void incrementReadSkipCount(int count) {
157+
public void incrementReadSkipCount(long count) {
158158
readSkipCount += count;
159159
}
160160

@@ -175,14 +175,14 @@ public void incrementProcessSkipCount() {
175175
/**
176176
* @return the read skip count
177177
*/
178-
public int getReadSkipCount() {
178+
public long getReadSkipCount() {
179179
return readSkipCount;
180180
}
181181

182182
/**
183183
* @return the write skip count
184184
*/
185-
public int getWriteSkipCount() {
185+
public long getWriteSkipCount() {
186186
return writeSkipCount;
187187
}
188188

@@ -191,7 +191,7 @@ public int getWriteSkipCount() {
191191
*
192192
* @return the process skip count
193193
*/
194-
public int getProcessSkipCount() {
194+
public long getProcessSkipCount() {
195195
return processSkipCount;
196196
}
197197

spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2013 the original author or authors.
2+
* Copyright 2006-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,6 +33,7 @@
3333
*
3434
* @author Lucas Ward
3535
* @author Dave Syer
36+
* @author Mahmoud Ben Hassine
3637
*
3738
*/
3839
@SuppressWarnings("serial")
@@ -44,19 +45,19 @@ public class StepExecution extends Entity {
4445

4546
private volatile BatchStatus status = BatchStatus.STARTING;
4647

47-
private volatile int readCount = 0;
48+
private volatile long readCount = 0;
4849

49-
private volatile int writeCount = 0;
50+
private volatile long writeCount = 0;
5051

51-
private volatile int commitCount = 0;
52+
private volatile long commitCount = 0;
5253

53-
private volatile int rollbackCount = 0;
54+
private volatile long rollbackCount = 0;
5455

55-
private volatile int readSkipCount = 0;
56+
private volatile long readSkipCount = 0;
5657

57-
private volatile int processSkipCount = 0;
58+
private volatile long processSkipCount = 0;
5859

59-
private volatile int writeSkipCount = 0;
60+
private volatile long writeSkipCount = 0;
6061

6162
private volatile Date startTime = new Date(System.currentTimeMillis());
6263

@@ -70,7 +71,7 @@ public class StepExecution extends Entity {
7071

7172
private volatile boolean terminateOnly;
7273

73-
private volatile int filterCount;
74+
private volatile long filterCount;
7475

7576
private transient volatile List<Throwable> failureExceptions = new CopyOnWriteArrayList<>();
7677

@@ -140,7 +141,7 @@ public void setExecutionContext(ExecutionContext executionContext) {
140141
*
141142
* @return the current number of commits
142143
*/
143-
public int getCommitCount() {
144+
public long getCommitCount() {
144145
return commitCount;
145146
}
146147

@@ -149,7 +150,7 @@ public int getCommitCount() {
149150
*
150151
* @param commitCount the current number of commits
151152
*/
152-
public void setCommitCount(int commitCount) {
153+
public void setCommitCount(long commitCount) {
153154
this.commitCount = commitCount;
154155
}
155156

@@ -176,7 +177,7 @@ public void setEndTime(Date endTime) {
176177
*
177178
* @return the current number of items read for this execution
178179
*/
179-
public int getReadCount() {
180+
public long getReadCount() {
180181
return readCount;
181182
}
182183

@@ -185,7 +186,7 @@ public int getReadCount() {
185186
*
186187
* @param readCount the current number of read items for this execution
187188
*/
188-
public void setReadCount(int readCount) {
189+
public void setReadCount(long readCount) {
189190
this.readCount = readCount;
190191
}
191192

@@ -194,7 +195,7 @@ public void setReadCount(int readCount) {
194195
*
195196
* @return the current number of items written for this execution
196197
*/
197-
public int getWriteCount() {
198+
public long getWriteCount() {
198199
return writeCount;
199200
}
200201

@@ -203,7 +204,7 @@ public int getWriteCount() {
203204
*
204205
* @param writeCount the current number of written items for this execution
205206
*/
206-
public void setWriteCount(int writeCount) {
207+
public void setWriteCount(long writeCount) {
207208
this.writeCount = writeCount;
208209
}
209210

@@ -212,7 +213,7 @@ public void setWriteCount(int writeCount) {
212213
*
213214
* @return the current number of rollbacks for this execution
214215
*/
215-
public int getRollbackCount() {
216+
public long getRollbackCount() {
216217
return rollbackCount;
217218
}
218219

@@ -221,7 +222,7 @@ public int getRollbackCount() {
221222
*
222223
* @return the current number of items filtered out of this execution
223224
*/
224-
public int getFilterCount() {
225+
public long getFilterCount() {
225226
return filterCount;
226227
}
227228

@@ -230,15 +231,15 @@ public int getFilterCount() {
230231
* @param filterCount the number of items filtered out of this execution to
231232
* set
232233
*/
233-
public void setFilterCount(int filterCount) {
234+
public void setFilterCount(long filterCount) {
234235
this.filterCount = filterCount;
235236
}
236237

237238
/**
238239
* Setter for number of rollbacks for this execution
239-
* @param rollbackCount int the number of rollbacks.
240+
* @param rollbackCount long the number of rollbacks.
240241
*/
241-
public void setRollbackCount(int rollbackCount) {
242+
public void setRollbackCount(long rollbackCount) {
242243
this.rollbackCount = rollbackCount;
243244
}
244245

@@ -383,7 +384,7 @@ public void setTerminateOnly() {
383384
/**
384385
* @return the total number of items skipped.
385386
*/
386-
public int getSkipCount() {
387+
public long getSkipCount() {
387388
return readSkipCount + processSkipCount + writeSkipCount;
388389
}
389390

@@ -410,48 +411,48 @@ public JobParameters getJobParameters() {
410411
/**
411412
* @return the number of records skipped on read
412413
*/
413-
public int getReadSkipCount() {
414+
public long getReadSkipCount() {
414415
return readSkipCount;
415416
}
416417

417418
/**
418419
* @return the number of records skipped on write
419420
*/
420-
public int getWriteSkipCount() {
421+
public long getWriteSkipCount() {
421422
return writeSkipCount;
422423
}
423424

424425
/**
425426
* Set the number of records skipped on read
426427
*
427-
* @param readSkipCount int containing read skip count to be used for the step execution.
428+
* @param readSkipCount long containing read skip count to be used for the step execution.
428429
*/
429-
public void setReadSkipCount(int readSkipCount) {
430+
public void setReadSkipCount(long readSkipCount) {
430431
this.readSkipCount = readSkipCount;
431432
}
432433

433434
/**
434435
* Set the number of records skipped on write
435436
*
436-
* @param writeSkipCount int containing write skip count to be used for the step execution.
437+
* @param writeSkipCount long containing write skip count to be used for the step execution.
437438
*/
438-
public void setWriteSkipCount(int writeSkipCount) {
439+
public void setWriteSkipCount(long writeSkipCount) {
439440
this.writeSkipCount = writeSkipCount;
440441
}
441442

442443
/**
443444
* @return the number of records skipped during processing
444445
*/
445-
public int getProcessSkipCount() {
446+
public long getProcessSkipCount() {
446447
return processSkipCount;
447448
}
448449

449450
/**
450451
* Set the number of records skipped during processing.
451452
*
452-
* @param processSkipCount int containing process skip count to be used for the step execution.
453+
* @param processSkipCount long containing process skip count to be used for the step execution.
453454
*/
454-
public void setProcessSkipCount(int processSkipCount) {
455+
public void setProcessSkipCount(long processSkipCount) {
455456
this.processSkipCount = processSkipCount;
456457
}
457458

spring-batch-core/src/main/java/org/springframework/batch/core/jsr/step/item/JsrFaultTolerantChunkProcessor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013 the original author or authors.
2+
* Copyright 2013-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,6 +48,7 @@
4848
*
4949
* @author Michael Minella
5050
* @author Chris Schaefer
51+
* @author Mahmoud Ben Hassine
5152
*
5253
* @param <I> input type for the step
5354
* @param <O> output type for the step
@@ -193,7 +194,7 @@ public I recover(RetryContext context) throws Exception {
193194
* @param e the cause of the skip
194195
* @param skipCount the current skip count
195196
*/
196-
private boolean shouldSkip(SkipPolicy policy, Throwable e, int skipCount) {
197+
private boolean shouldSkip(SkipPolicy policy, Throwable e, long skipCount) {
197198
try {
198199
return policy.shouldSkip(e, skipCount);
199200
}

spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,9 @@ private List<Object[]> buildStepExecutionParameters(StepExecution stepExecution)
227227
stepExecution.getWriteSkipCount(), stepExecution.getProcessSkipCount(),
228228
stepExecution.getRollbackCount(), stepExecution.getLastUpdated() };
229229
Integer[] parameterTypes = new Integer[] { Types.BIGINT, Types.INTEGER, Types.VARCHAR, Types.BIGINT,
230-
Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER,
231-
Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER,
232-
Types.INTEGER, Types.TIMESTAMP };
230+
Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.BIGINT, Types.BIGINT, Types.BIGINT,
231+
Types.BIGINT, Types.VARCHAR, Types.VARCHAR, Types.BIGINT, Types.BIGINT, Types.BIGINT,
232+
Types.BIGINT, Types.TIMESTAMP };
233233
parameters.add(0, Arrays.copyOf(parameterValues,parameterValues.length));
234234
parameters.add(1, Arrays.copyOf(parameterTypes,parameterTypes.length));
235235
return parameters;

spring-batch-core/src/main/java/org/springframework/batch/core/step/item/FaultTolerantChunkProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ private void callProcessSkipListener(I item, Throwable e) {
509509
* @param e the cause of the skip
510510
* @param skipCount the current skip count
511511
*/
512-
private boolean shouldSkip(SkipPolicy policy, Throwable e, int skipCount) {
512+
private boolean shouldSkip(SkipPolicy policy, Throwable e, long skipCount) {
513513
try {
514514
return policy.shouldSkip(e, skipCount);
515515
}

0 commit comments

Comments
 (0)