Skip to content

Commit

Permalink
Only reload if modified when put an existing graph.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentg committed Apr 2, 2015
1 parent c3654ee commit 6a4c1ba
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
9 changes: 5 additions & 4 deletions src/main/java/org/opentripplanner/api/resource/Routers.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,10 @@ private RouterInfo getRouterInfo(String routerId) {
*/
@RolesAllowed({ "ROUTERS" })
@PUT @Produces({ MediaType.APPLICATION_JSON })
public Response reloadGraphs(@QueryParam("path") String path,
@QueryParam("preEvict") @DefaultValue("true") boolean preEvict) {
otpServer.getGraphService().reloadGraphs(preEvict);
public Response reloadGraphs(@QueryParam("path") String path,
@QueryParam("preEvict") @DefaultValue("true") boolean preEvict,
@QueryParam("force") @DefaultValue("true") boolean force) {
otpServer.getGraphService().reloadGraphs(preEvict, force);
return Response.status(Status.OK).build();
}

Expand All @@ -178,7 +179,7 @@ public Response putGraphId(@PathParam("routerId") String routerId,
LOG.debug("Attempting to load graph '{}' from server's local filesystem.", routerId);
GraphService graphService = otpServer.getGraphService();
if (graphService.getRouterIds().contains(routerId)) {
boolean success = graphService.reloadGraph(routerId, preEvict);
boolean success = graphService.reloadGraph(routerId, preEvict, false);
if (success)
return Response.status(201).entity("graph already registered, reloaded.\n").build();
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ public Router getRouter(String routerId) throws GraphNotFoundException {
* Reload all registered graphs from wherever they came from. See reloadGraph().
* @return whether the operation completed successfully (all reloads are successful).
*/
public boolean reloadGraphs(boolean preEvict) {
public boolean reloadGraphs(boolean preEvict, boolean force) {
boolean allSucceeded = true;
synchronized (graphSources) {
Collection<String> routerIds = getRouterIds();
for (String routerId : routerIds) {
allSucceeded &= reloadGraph(routerId, preEvict);
allSucceeded &= reloadGraph(routerId, preEvict, force);
}
}
return allSucceeded;
Expand All @@ -155,15 +155,17 @@ public boolean reloadGraphs(boolean preEvict) {
* @param preEvict When true, release the existing graph (if any) before loading. This will
* halve the amount of memory needed for the operation, but routing will be unavailable
* for that graph during the load process
* @param force When true, force a reload. If false, only check if the source has been modified,
* and reload if so.
* @return True if the reload is successful, false otherwise.
*/
public boolean reloadGraph(String routerId, boolean preEvict) {
public boolean reloadGraph(String routerId, boolean preEvict, boolean force) {
synchronized (graphSources) {
GraphSource graphSource = graphSources.get(routerId);
if (graphSource == null) {
return false;
}
boolean success = graphSource.reload(true, preEvict);
boolean success = graphSource.reload(force, preEvict);
if (!success) {
evictRouter(routerId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public final void testGraphServiceFile() throws IOException {
graphSourceFactory.save("A", new ByteArrayInputStream(smallGraphData));

// Force a reload, get again the graph
graphService.reloadGraphs(false);
graphService.reloadGraphs(false, true);
graph = graphService.getRouter("A").graph;

// Check if loaded graph is the one modified
Expand All @@ -175,7 +175,7 @@ public final void testGraphServiceFile() throws IOException {
boolean deleted = new File(new File(basePath, "A"), InputStreamGraphSource.GRAPH_FILENAME)
.delete();
assertTrue(deleted);
graphService.reloadGraphs(false);
graphService.reloadGraphs(false, true);

// Check that the graph have been evicted
assertEquals(0, graphService.getRouterIds().size());
Expand Down

0 comments on commit 6a4c1ba

Please sign in to comment.