-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Make all polling updaters wait for graph update finish #6262
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
Changes from 1 commit
12b4995
5edfd73
ed778da
c74c9e5
0944921
4df65a1
d8a34dd
69ac485
0037b5a
2ce1a6d
c0f7a3f
74241bd
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(); | ||||||||||||||||
|
||||||||||||||||
| saveResultOnGraph | |
| .execute(context -> updateHandler.update(feed, context.gtfsRealtimeFuzzyTripMatcher())) | |
| .get(); | |
| var f = saveResultOnGraph.execute(context -> updateHandler.update(feed, context.gtfsRealtimeFuzzyTripMatcher())); | |
| if(OTPFeature.WaitOnPullingUpdatersBeforeResheduling.isOn()) { | |
| f.get(); | |
| } |
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 will add a method to the updater and a unit test to do that, such that the behaviour is testable.
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.
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.
In the alternative I suggested, this could be accomplished by an additional condition
if (OTPFeature.AwaitPollingUpdaterCompletion.isOff() || status == null || status.isDone()) {
status = runPolling();
}
Though I think safety measures (and maybe even the OTPOption) are less necessary in an implementation where there are no blocking calls.
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.
(@t2gran sorry, I accidentally edited your comment instead of hitting "quote reply". I think I restored your comment to its original form.)
Uh oh!
There was an error while loading. Please reload this page.
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.