Skip to content

Commit 0111a20

Browse files
Move OD pairs limit check into RegionalTask
1 parent 5f1f80c commit 0111a20

File tree

4 files changed

+22
-38
lines changed

4 files changed

+22
-38
lines changed

src/main/java/com/conveyal/analysis/controllers/RegionalAnalysisController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ private RegionalAnalysis createRegionalAnalysis (Request req, Response res) thro
450450
task.destinationPointSets = new PointSet[] {
451451
PointSetCache.readFreeFormFromFileStore(task.destinationPointSetKeys[0])
452452
};
453-
MultiOriginAssembler.ensureOdPairsUnderLimit(task, task.destinationPointSets[0]);
453+
task.checkIsUnderOdPairLimit(task.destinationPointSets[0]);
454454
}
455455
if (task.recordTimes) {
456456
checkArgument(

src/main/java/com/conveyal/analysis/results/MultiOriginAssembler.java

-24
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package com.conveyal.analysis.results;
22

3-
import com.conveyal.analysis.AnalysisServerException;
43
import com.conveyal.analysis.components.broker.Job;
54
import com.conveyal.file.FileStorageKey;
6-
import com.conveyal.r5.analyst.PointSet;
7-
import com.conveyal.r5.analyst.cluster.RegionalTask;
85
import com.conveyal.r5.analyst.cluster.RegionalWorkResult;
96
import org.slf4j.Logger;
107
import org.slf4j.LoggerFactory;
@@ -24,10 +21,6 @@ public class MultiOriginAssembler {
2421

2522
public static final Logger LOG = LoggerFactory.getLogger(MultiOriginAssembler.class);
2623

27-
private static final int MAX_FREEFORM_OD_PAIRS = 16_000_000;
28-
29-
private static final int MAX_FREEFORM_DESTINATIONS = 4_000_000;
30-
3124
/**
3225
* The object representing the progress of the regional analysis as tracked by the broker.
3326
* It may appear job.templateTask has all the information needed, making the regionalAnalysis field
@@ -67,23 +60,6 @@ public MultiOriginAssembler (Job job, List<RegionalResultWriter> resultWriters)
6760
this.originsReceived = new BitSet(job.nTasksTotal);
6861
}
6962

70-
/**
71-
* Check that origin and destination sets are not too big for generating CSV files.
72-
*/
73-
public static void ensureOdPairsUnderLimit(RegionalTask task, PointSet destinationPointSet) {
74-
// This requires us to have already loaded this destination pointset instance into the transient field.
75-
if ((task.recordTimes || task.includePathResults) && !task.oneToOne) {
76-
if (task.getTasksTotal() * destinationPointSet.featureCount() > MAX_FREEFORM_OD_PAIRS ||
77-
destinationPointSet.featureCount() > MAX_FREEFORM_DESTINATIONS
78-
) {
79-
throw new AnalysisServerException(String.format(
80-
"Freeform requests limited to %d destinations and %d origin-destination pairs.",
81-
MAX_FREEFORM_DESTINATIONS, MAX_FREEFORM_OD_PAIRS
82-
));
83-
}
84-
}
85-
}
86-
8763
/**
8864
* There is a bit of logic in this method that wouldn't strictly need to be synchronized (the dimension checks) but
8965
* those should take a trivial amount of time. For safety and simplicity we synchronize the whole method. The

src/main/java/com/conveyal/file/FileUtils.java

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
package com.conveyal.file;
22

3-
import java.io.BufferedInputStream;
4-
import java.io.BufferedOutputStream;
5-
import java.io.File;
6-
import java.io.FileInputStream;
7-
import java.io.FileNotFoundException;
8-
import java.io.FileOutputStream;
9-
import java.io.IOException;
10-
import java.io.InputStream;
11-
import java.io.OutputStream;
12-
import java.io.RandomAccessFile;
3+
import java.io.*;
134
import java.nio.file.Files;
145
import java.util.zip.GZIPInputStream;
156
import java.util.zip.GZIPOutputStream;
@@ -92,9 +83,8 @@ public static void transferFromFileTo(File file, OutputStream os) {
9283
*/
9384
public static File gzipFile(File file) {
9485
try {
95-
var gzippedFile = createScratchFile();
96-
var gzippedOs = new GZIPOutputStream(getOutputStream(gzippedFile));
97-
transferFromFileTo(file, gzippedOs);
86+
File gzippedFile = createScratchFile();
87+
transferFromFileTo(file, new GZIPOutputStream(getOutputStream(gzippedFile)));
9888
return gzippedFile;
9989
} catch (IOException e) {
10090
throw new RuntimeException(e);

src/main/java/com/conveyal/r5/analyst/cluster/RegionalTask.java

+18
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
*/
1111
public class RegionalTask extends AnalysisWorkerTask implements Cloneable {
1212

13+
public static final int MAX_FREEFORM_OD_PAIRS = 16_000_000;
14+
public static final int MAX_FREEFORM_DESTINATIONS = 4_000_000;
1315
/**
1416
* The storage key for the pointset we will compute access to (e.g. regionId/datasetId.grid).
1517
* This is named grid instead of destinationPointSetId for backward compatibility, namely the ability to start
@@ -122,4 +124,20 @@ public int getTasksTotal() {
122124
}
123125
}
124126

127+
/**
128+
* Check that origin and destination sets are not too big for generating CSV files.
129+
*/
130+
public void checkIsUnderOdPairLimit(PointSet destinationPointSet) {
131+
// This requires us to have already loaded this destination pointset instance into the transient field.
132+
if ((recordTimes || includePathResults) && !oneToOne) {
133+
if (getTasksTotal() * destinationPointSet.featureCount() > MAX_FREEFORM_OD_PAIRS ||
134+
destinationPointSet.featureCount() > MAX_FREEFORM_DESTINATIONS
135+
) {
136+
throw new RuntimeException(String.format(
137+
"Freeform requests limited to %d destinations and %d origin-destination pairs.",
138+
MAX_FREEFORM_DESTINATIONS, MAX_FREEFORM_OD_PAIRS
139+
));
140+
}
141+
}
142+
}
125143
}

0 commit comments

Comments
 (0)