-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make all polling updaters wait for graph update finish #6262
base: dev-2.x
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,6 +2,7 @@ | |||||||||||||||
|
||||||||||||||||
import com.google.transit.realtime.GtfsRealtime.FeedMessage; | ||||||||||||||||
import java.net.URI; | ||||||||||||||||
import java.util.concurrent.ExecutionException; | ||||||||||||||||
import org.opentripplanner.framework.io.OtpHttpClient; | ||||||||||||||||
import org.opentripplanner.framework.io.OtpHttpClientFactory; | ||||||||||||||||
import org.opentripplanner.routing.impl.TransitAlertServiceImpl; | ||||||||||||||||
|
@@ -63,32 +64,28 @@ public String toString() { | |||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
@Override | ||||||||||||||||
protected void runPolling() { | ||||||||||||||||
try { | ||||||||||||||||
final FeedMessage feed = otpHttpClient.getAndMap( | ||||||||||||||||
URI.create(url), | ||||||||||||||||
this.headers.asMap(), | ||||||||||||||||
FeedMessage.PARSER::parseFrom | ||||||||||||||||
); | ||||||||||||||||
protected void runPolling() throws InterruptedException, ExecutionException { | ||||||||||||||||
final FeedMessage feed = otpHttpClient.getAndMap( | ||||||||||||||||
URI.create(url), | ||||||||||||||||
this.headers.asMap(), | ||||||||||||||||
FeedMessage.PARSER::parseFrom | ||||||||||||||||
); | ||||||||||||||||
|
||||||||||||||||
long feedTimestamp = feed.getHeader().getTimestamp(); | ||||||||||||||||
if (feedTimestamp == lastTimestamp) { | ||||||||||||||||
LOG.debug("Ignoring feed with a timestamp that has not been updated from {}", url); | ||||||||||||||||
return; | ||||||||||||||||
} | ||||||||||||||||
if (feedTimestamp < lastTimestamp) { | ||||||||||||||||
LOG.info("Ignoring feed with older than previous timestamp from {}", url); | ||||||||||||||||
return; | ||||||||||||||||
} | ||||||||||||||||
long feedTimestamp = feed.getHeader().getTimestamp(); | ||||||||||||||||
if (feedTimestamp == lastTimestamp) { | ||||||||||||||||
LOG.debug("Ignoring feed with a timestamp that has not been updated from {}", url); | ||||||||||||||||
return; | ||||||||||||||||
} | ||||||||||||||||
if (feedTimestamp < lastTimestamp) { | ||||||||||||||||
LOG.info("Ignoring feed with older than previous timestamp from {}", url); | ||||||||||||||||
return; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
// Handle update in graph writer runnable | ||||||||||||||||
saveResultOnGraph.execute(context -> | ||||||||||||||||
updateHandler.update(feed, context.gtfsRealtimeFuzzyTripMatcher()) | ||||||||||||||||
); | ||||||||||||||||
// Handle update in graph writer runnable | ||||||||||||||||
saveResultOnGraph | ||||||||||||||||
.execute(context -> updateHandler.update(feed, context.gtfsRealtimeFuzzyTripMatcher())) | ||||||||||||||||
.get(); | ||||||||||||||||
Comment on lines
+85
to
+87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good change, but we need to be able to turn this off in case it have some side-effects we have missed. This is critical code, and it is possible that we have not understood all implications. So, it would be nice to introduce a
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will add a method to the updater and a unit test to do that, such that the behaviour is testable. |
||||||||||||||||
|
||||||||||||||||
lastTimestamp = feedTimestamp; | ||||||||||||||||
} catch (Exception e) { | ||||||||||||||||
LOG.error("Error reading gtfs-realtime feed from " + url, e); | ||||||||||||||||
} | ||||||||||||||||
lastTimestamp = feedTimestamp; | ||||||||||||||||
} | ||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should have a timeout here - what happens if a task take too much time or does not return ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The task is to write the update into the graph. I am not sure what will happen if the task to update the graph is forcibly terminated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't want to use the asynchronicity of the Future, why do we even need a Future at all? I think in such a case the method could just return void.
In any case, we need to discuss this in the dev meeting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After further discussion I finally realized what's going on here. In fact @leonardehrenfried, this is using the Future to delay completion of the polling graph updater until the subtask it enqueues on a different ExecutorService completes. I will comment further on the main discussion thread.