Commit 1975ab4a authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

Bugfix: prevent OSM file lock exceptions due to multi-threading

- graph hopper needs a temp-folder with a file lock. The new setting
MOVEMENT_GRAPH_UNIQUE_FOLDERS can be used to force unique folders for
the temporary data. Remember to purge the osm folder manually every now
and then, as this will lead to large amounts of temp data in batched
runs.
parent 25ddde7e
......@@ -22,6 +22,7 @@ package de.tud.kom.p2psim.impl.topology.movement.local;
import java.util.HashMap;
import java.util.Locale;
import java.util.UUID;
import com.graphhopper.GHRequest;
import com.graphhopper.GHResponse;
......@@ -38,6 +39,8 @@ import de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation;
import de.tud.kom.p2psim.impl.util.Either;
import de.tud.kom.p2psim.impl.util.Left;
import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
/**
* This movement strategy uses the data from osm and navigates the nodes throught streets to the destination
......@@ -61,6 +64,7 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
private double latRight; //Values from -90 to 90
private double lonLeft; //Values from -180 to 180; Always smaller than lonRight
private double lonRight; //Values from -180 to 180
private boolean uniqueFolders;
/**
* Tolerance in meters (if the node reached a waypoint up to "tolerance"
......@@ -81,7 +85,16 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
hopper = new GraphHopper().forServer();
hopper.setOSMFile(osmFileLocation);
// where to store graphhopper files?
hopper.setGraphHopperLocation(graphFolderFiles+"/"+osmFileLocation.hashCode()+movementType);
if (uniqueFolders) {
Monitor.log(RealWorldStreetsMovement.class, Level.WARN,
"Using per-simulation unique folders for GraphHopper temporary data in %s. Remember to delete them to prevent your disk from filling up.",
graphFolderFiles);
hopper.setGraphHopperLocation(graphFolderFiles + "/"
+ UUID.randomUUID().toString());
} else {
hopper.setGraphHopperLocation(graphFolderFiles + "/"
+ osmFileLocation.hashCode() + movementType);
}
hopper.setEncodingManager(new EncodingManager(movementType));
hopper.importOrLoad();
init = true;
......@@ -190,4 +203,16 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
public void setWaypointTolerance(double tolerance) {
this.tolerance = tolerance;
}
/**
* For large batch simulations, we need to prevent same-time access to
* garphhopper temp data. Therefore, this flag creates unique folders for
* each run (which, obviously, wastes a lot of space and comp-resources and
* should not be used in standalone, single-threaded demo mode...)
*
* @param uniqueFolders
*/
public void setCreateUniqueFolders(boolean uniqueFolders) {
this.uniqueFolders = uniqueFolders;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment