-
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
Introduce RealtimeUpdateContext #6029
Introduce RealtimeUpdateContext #6029
Conversation
a248d23
to
b5afac1
Compare
11a0967
to
03c9c23
Compare
03c9c23
to
e693e50
Compare
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.
Thanks for the very clear PR description and Javadoc on the interface. This looks like a good step in the right direction.
If I am seeing correctly, the same DefaultRealTimeUpdateContext instance is used for all successive updates, across all successive snapshots (a new instance is not made for each snapshot). This instance is in some sense the outer unifying layer of the persistent buffer from which we take snapshots. The lifecycle (specifically the long duration) of these instances might be worth mentioning in the Javadoc of the implementation classes.
For future reference: As discussed in a recent meeting, it's not clear that in the long term we actually want the updaters to consult changes introduced by previously applied update messages, including changes introduced within the same batch of updates between two snapshot publications. We may want updates to be idempotent and interpreted independent of one another, to the greatest extent possible. For example, the choice between creating a realtime-added trip or pattern and reusing an already created one could be encapsulated within a method exposed to the updaters by a deeper layer of the system, so the updaters don't need to know whether another update already created that trip or pattern. But the current system relies on updaters performing their own lookups to function, and these PRs serve to clean up that existing system in advance of any more extensive overhaul to the design. |
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.
Just one minor formatting of a comment...
src/main/java/org/opentripplanner/updater/trip/TimetableSnapshotSource.java
Outdated
Show resolved
Hide resolved
…otSource.java Co-authored-by: Thomas Gran <t2gran@gmail.com>
Summary
Real-time updaters use instances of
TransitService
to look up transit data. Currently these instances are created at construction time.This is problematic since
TransitService
instances maintain a reference to a frozen version of theTimetableSnapshot
that is not updated after construction.As of today this does not cause any issue, since the real-time updaters update directly the collections in
TransitModelIndex
, and theTransitService
looks up data inTransitModelIndex
.However #6007 changes this behavior by storing the real-time updates in indexes in
TimetableSnapshot
, making previous real-time updates invisible from the real-time updaters.Among other regressions, this prevents the
EntityResolver
from identifying already created extra journeys, and leads to the creation of duplicated trips.This PR refactors the real-time updaters so that they use
TransitService
instances that refer to theTimetableSnapshot
buffer, thus giving access to all applied real-time updates (including uncommitted ones).This PR is a prerequisite for #6007
This PR supersedes #6018
Note: the refactoring consists in:
GraphWriterRunnable
interface so that it accepts aRealTimeUpdateContext
as a parameter.RealTimeUpdateContext
gives access to a transit service that points to theTimetableSnapshot
buffer. Other entities exposed in this interface (EntityResolver
,SiriFuzzyTripMatcher
,GtfsRealtimeFuzzyTripMatcher
) are also aware of the latest applied real-time update.TransitService
,EntityResolver
,SiriFuzzyTripMatcher
,GtfsRealtimeFuzzyTripMatcher
provided by theRealTimeUpdateContext
, exclusively in the context of aGraphWriterRunnable
(where it is safe to do so).Note: the
SiriFuzzyTripMatcher
is now instantiated only once in theRealTimeUpdateContext
, making it possible to remove the static singleton logic that made it difficult to test.Note: The SIRI-SX and Alert updaters still make use of a TransitModel instance. In practice they just need access to the
StopModel
, which is (currently) immutable. These updaters could be refactored in a follow-up PR to use only theStopModel
instead of theTransitModel
, making the intent clearer.Issue
No
Unit tests
Added unit tests,
Updated unit tests.
Documentation
No