Skip to content

Commit 85aa502

Browse files
committed
Prevent int overflow for large amounts of records
1 parent 5237fb1 commit 85aa502

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/main/java/org/radarcns/hdfs/RadarHdfsRestructure.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class RadarHdfsRestructure {
5858
private static final Logger logger = LoggerFactory.getLogger(RadarHdfsRestructure.class);
5959

6060
/** Number of offsets to process in a single task. */
61-
private static final int BATCH_SIZE = 500_000;
61+
private static final long BATCH_SIZE = 500_000;
6262

6363
private final int numThreads;
6464
private final Configuration conf;
@@ -174,8 +174,8 @@ private void processPaths(List<TopicFileList> topicPaths, Accountant accountant)
174174
String topic = paths.files.get(0).topic;
175175
logger.info("Processing {} records for topic {}", size, topic);
176176
executor.execute(() -> {
177-
int batchSize = (int)(BATCH_SIZE * ThreadLocalRandom.current().nextDouble(0.75, 1.25));
178-
int currentSize = 0;
177+
long batchSize = Math.round(BATCH_SIZE * ThreadLocalRandom.current().nextDouble(0.75, 1.25));
178+
long currentSize = 0;
179179
try (FileCacheStore cache = fileStoreFactory.newFileCacheStore(accountant)) {
180180
for (TopicFile file : paths.files) {
181181
try {
@@ -280,7 +280,7 @@ private static class TopicFileList {
280280
public TopicFileList(Stream<TopicFile> files) {
281281
this.files = files.collect(Collectors.toList());
282282
this.size = this.files.stream()
283-
.mapToInt(TopicFile::size)
283+
.mapToLong(TopicFile::size)
284284
.sum();
285285
}
286286

@@ -308,8 +308,8 @@ public String getTopic() {
308308
return topic;
309309
}
310310

311-
public int size() {
312-
return 1 + (int) (range.getOffsetTo() - range.getOffsetFrom());
311+
public long size() {
312+
return 1 + range.getOffsetTo() - range.getOffsetFrom();
313313
}
314314
}
315315
}

0 commit comments

Comments
 (0)