Skip to content

Conversation

@miklcct
Copy link
Contributor

@miklcct miklcct commented Nov 26, 2024

PR Instructions

Summary

Currently, after clearing TimetableSnapshot, if it is committed directly empty, nothing is passed to TransitLayerUpdater. As a result, previously added trip patterns remain in the TransitLayer for routing purpose, resulting in stale timetables returned in itinerary results which no longer exist in the actual, published timetable snapshot.

Issue

Fixes #6197

Unit tests

Added

Documentation

Bug fix only, not needed

Changelog

@miklcct miklcct force-pushed the fix-update-stale-service branch from 5a4a351 to d931077 Compare November 27, 2024 11:52
@miklcct miklcct marked this pull request as ready for review November 27, 2024 11:54
@miklcct miklcct requested a review from a team as a code owner November 27, 2024 11:54
@codecov
Copy link

codecov bot commented Nov 27, 2024

Codecov Report

❌ Patch coverage is 88.46154% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.14%. Comparing base (87cf700) to head (85f356b).
⚠️ Report is 1 commits behind head on dev-2.x.

Files with missing lines Patch % Lines
...main/java/org/opentripplanner/model/Timetable.java 33.33% 1 Missing and 1 partial ⚠️
...a/org/opentripplanner/model/TimetableSnapshot.java 95.65% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             dev-2.x    #6280   +/-   ##
==========================================
  Coverage      72.14%   72.14%           
- Complexity     19673    19678    +5     
==========================================
  Files           2127     2127           
  Lines          79562    79587   +25     
  Branches        8041     8043    +2     
==========================================
+ Hits           57397    57419   +22     
- Misses         19331    19333    +2     
- Partials        2834     2835    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@leonardehrenfried leonardehrenfried changed the title Pass empty timetable to TransitLayerUpdater for cleared added trip patterns Pass empty timetable to TransitLayerUpdater in order to clear added trip patterns Nov 29, 2024
@t2gran t2gran requested a review from vpaturet November 29, 2024 10:36
@miklcct
Copy link
Contributor Author

miklcct commented Nov 30, 2024

Sorry it seems that the bug still appears on the live server, so I need to mark this as draft for now.

@miklcct miklcct marked this pull request as draft November 30, 2024 08:47
@miklcct
Copy link
Contributor Author

miklcct commented Nov 30, 2024

The solution will not work if a timetable is cleared multiple times between commits. Also on my live server log there are a lot of "WARN could not fetch timetable for pattern" which may be related to this problem as well. I'll need to further fix it.

@miklcct
Copy link
Contributor Author

miklcct commented Nov 30, 2024

What does this line actually mean:

My server log is flooded with this.

@miklcct miklcct marked this pull request as ready for review December 2, 2024 17:59
@vpaturet
Copy link
Contributor

vpaturet commented Dec 9, 2024

Would it work and would it be simpler if:

  1. We set a flag in the TransitLayerUpdater each time we call TimetableSnapshot.clear():
public clear(String feedId) {
...
if(transitLayerUpdater != null) {
transitLayerUpdater.setCleared(feedId);
}
}
  1. The TransitLayerUpdater checks the flag and clears all data belonging to this feed before applying the updates:

public void update(
    Collection<Timetable> updatedTimetables,
    Map<TripPattern, SortedSet<Timetable>> timetables
  ) {
if(isCleared(feedId)) {
realtimeTransitLayer.clear(feedId);
setCleared(feedId, false);
}
// apply updates
}

@miklcct
Copy link
Contributor Author

miklcct commented Dec 9, 2024

Would it work and would it be simpler if:

  1. We set a flag in the TransitLayerUpdater each time we call TimetableSnapshot.clear():
public clear(String feedId) {
...
if(transitLayerUpdater != null) {
transitLayerUpdater.setCleared(feedId);
}
}
  1. The TransitLayerUpdater checks the flag and clears all data belonging to this feed before applying the updates:

public void update(
    Collection<Timetable> updatedTimetables,
    Map<TripPattern, SortedSet<Timetable>> timetables
  ) {
if(isCleared(feedId)) {
realtimeTransitLayer.clear(feedId);
setCleared(feedId, false);
}
// apply updates
}

I think it will be better and I will work on this.

@miklcct
Copy link
Contributor Author

miklcct commented Dec 12, 2024

Unfortunately TransitLayerUpdater is not feed aware and it doesn't really have a state, so it is not possible for me to do that without adding complexity into the system. There is no concept of a "feed" and the "original" in the TransitLayer.

only do the actual restoration when committing if it isn't subsequently made dirty
@miklcct
Copy link
Contributor Author

miklcct commented Dec 17, 2024

I have updated my approach as the original contained a mistake which broke the cancelled trip fetching.

I have now deferred the actual restoration of the timetable to the time of commit. When clear() is called, the pattern / service date pairs cleared are stored as a separate field, and during commit, the scheduled timetables of these pairs are added to the dirty set such that they are passed to the updater.

@optionsome optionsome marked this pull request as draft December 19, 2024 14:34
@t2gran t2gran added this to the 2.7 (next release) milestone Jan 29, 2025
# Conflicts:
#	application/src/main/java/org/opentripplanner/model/TimetableSnapshot.java
@t2gran t2gran modified the milestones: 2.7, 2.8 (next release) Mar 12, 2025
@miklcct miklcct force-pushed the fix-update-stale-service branch from 74914c5 to 6352234 Compare June 19, 2025 14:52
@miklcct miklcct force-pushed the fix-update-stale-service branch from 6352234 to d315867 Compare June 20, 2025 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stale services are used for journey planning

4 participants