-
Notifications
You must be signed in to change notification settings - Fork 1.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
Update indexes in timetable snapshot #6007
Update indexes in timetable snapshot #6007
Conversation
4894c6e
to
25f6ef3
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev-2.x #6007 +/- ##
=============================================
+ Coverage 69.76% 69.78% +0.02%
- Complexity 17327 17356 +29
=============================================
Files 1961 1962 +1
Lines 74267 74359 +92
Branches 7603 7624 +21
=============================================
+ Hits 51811 51895 +84
- Misses 19814 19820 +6
- Partials 2642 2644 +2 ☔ View full report in Codecov by Sentry. |
25f6ef3
to
70c817b
Compare
70c817b
to
5b71ff1
Compare
src/main/java/org/opentripplanner/transit/service/DefaultTransitService.java
Show resolved
Hide resolved
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 great improvement IMO.
Some of my comments are probably out of the scope of this PR and can be done as part of future work.
pattern = | ||
tripPatternCache.getOrCreateTripPattern(tripUpdate.stopPattern(), trip, serviceDate); |
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.
It's pretty difficult to follow the logic with the different trip patterns being created/fetched depending on if it's an added trip or modified trip. Also this tripPatternCache seems to have a very similar responsibility to the indexes in the snapshot.
But it looks like you are keeping the behaviour the same as previously. So I'm ok with this and we can do any further improvements in a future PR.
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 agree, this is quite convoluted and should be addressed in a follow-up PR.
if (realTimeTripUpdate.routeCreation()) { | ||
realtimeAddedRoutes.put(route.getId(), route); | ||
} | ||
if (realTimeTripUpdate.tripCreation()) { | ||
FeedScopedId tripId = trip.getId(); | ||
realTimeAddedTrips.put(tripId, trip); | ||
realTimeAddedPatternForTrip.put(trip, pattern); | ||
realTimeAddedPatternForRoute.put(route, pattern); | ||
TripOnServiceDate tripOnServiceDate = realTimeTripUpdate.addedTripOnServiceDate(); | ||
if (tripOnServiceDate != null) { | ||
realTimeAddedTripOnServiceDateById.put(tripOnServiceDate.getId(), tripOnServiceDate); | ||
realTimeAddedTripOnServiceDateForTripAndDay.put( | ||
new TripIdAndServiceDate(tripId, serviceDate), | ||
tripOnServiceDate | ||
); | ||
} |
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.
It would be nice with some tests of this functionality. As far as I could see there isn't any
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 have added unit tests and fixed some regressions in the process: the TransitService.getAllXXX()
methods should also return a combination of scheduled and real-time data.
There is an inconsistency in the existing code with the method TransitService.getAllTripPatterns()
: it returns only scheduled trip patterns, not including the ones created in real-time. I keep the existing behavior for now and annotate the method with a TODO.
realTimeAddedPatternForTrip.put(trip, pattern); | ||
realTimeAddedPatternForRoute.put(route, pattern); |
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.
A RealTimeTripUpdate could have a new TripPattern even if it doesn't create a new trip right? As it currently stands these changed patterns won't be added to the index. This is the same as the previous behaviour, so It's not a regression. But we will have to fix this in a follow-up PR if we don't do it now.
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.
True, this should be addressed in a follow-up PR.
79b8ba0
to
1a5c1d5
Compare
I see some missing null-checks in |
Fixed a regression caused by the use of immutable maps in TimetableSnapshot:
This is fixed in 9baf38b |
@@ -74,6 +74,9 @@ public interface TransitService { | |||
|
|||
Collection<Notice> getNoticesByEntity(AbstractTransitEntity<?, ?> entity); | |||
|
|||
/** | |||
* Return a trip pattern by id, not including patterns created by real-time updates. | |||
*/ | |||
TripPattern getTripPatternForId(FeedScopedId id); |
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.
Did you figure out if it is intended that some of these methods that don't include realtime data?
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.
No, the analysis is quite complex. In this PR I will only document the current behavior.
public Route getRealtimeAddedRoute(FeedScopedId id) { | ||
return realtimeAddedRoutes.get(id); | ||
return getByNullableKey(id, realtimeAddedRoutes); | ||
} |
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 usually prefer to crash when called with an illegal argument, because being lenient in allowing bad input data can make bugs really difficult to find. And i think it's bad practice for callers to assume that downstream code will handle their nulls for them.
But I understand you don't want to go through all the call sites of these methods as part of this PR, so let's leave it for now.
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.
Yes, I try to preserve backward compatibility in this PR, the issue can be addressed in a follow-up PR. The root cause is insufficient data validation in the GraphQL API.
Merging |
I really like where these PRs are going, namely by introducing some well-needed structure into the storage of the real-time data. |
} | ||
return map.get(key); | ||
} | ||
|
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 method can probably be put in the CollectionUtils
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.
Done
I don't think I have been formally assigned the reviewer. Should I review or is it @habrahamsson-skanetrafiken ? |
# Conflicts: # src/ext-test/java/org/opentripplanner/ext/siri/SiriTimetableSnapshotSourceTest.java
Summary
As detailed in #5965, updating the transit model indexes directly from the updaters causes data inconsistencies when these indexes are queried concurrently from the API.
This PR refactors the real time updaters so that the updating logic is moved from the updaters to the
TimetableSnapshot
:TimetableSnapShot
.TimetableSnapshot
manages the indexes on these entities and updates them in a thread-safe way (copy-on-write).DefaultTransitService
queries both the indexes inTimetableSnapshot
(real-time data) and theTransitModelIndex
(planned data) to provide a unified view of the transit data.Notes:
TimetableSnapshot
.Issue
Close #5965
Close #5665 - The refactoring of the RT code is intended to fix this (this PR and earlier PRs). This is hard to reproduce, reopen if found again.
Unit tests
Updated unit tests.
Documentation
No