Invalidate the fastest lap cache when laps of a session change - #490
Merged
Conversation
The per session fastest lap cache calculated an entry only once and kept it until the process ended, so a running session reported the fastest lap of the moment its entry was calculated. The cache now offers InvalidateSession and RemoveSession, and the lap processing drops the affected entry whenever a lap is completed, refreshed, inserted or removed, and when a session is deleted. A change counter per session makes sure a calculation that was invalidated while it was running does not store its outdated result.
…ssor The new invalidation calls were not covered by tests, so the quality gate rejected the coverage of the changed lines. Two tests now drive a session history packet that inserts a lap and one that refreshes an already stored lap, and verify that the reported fastest lap of the session follows. The session removal keeps the id of the runtime session instead of a local copy, so the untested method does not add further uncovered lines.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
FastestLapPerSessionCachecalculated the entry of a session only once and kept it for the rest of the process lifetime — a session entry was recomputed only when the key was missing. For running sessions new laps were stored but the cached fastest lap was never updated, so the API kept returning the state of the moment the entry was calculated.The cache now exposes
InvalidateSession(sessionId), which drops the cached entry so the next request recalculates it, andRemoveSession(sessionId), which additionally removes the calculation gate of a deleted session. A change counter per session id is incremented on every invalidation; a calculation that started before an invalidation compares the counter before storing its result and discards it when the session changed in the meantime.The invalidation is triggered wherever completed laps of a session are written or removed:
ParticipantRuntimeData.CompleteLap— a completed lap can be the new fastest lapSessionHistoryProcessor.UpdateFinishedLap/RefreshStoredLap/InsertLap— history packets change or add completed lapsFinalClassificationProcessor— invalid laps of the session are deletedSessionProcessor.ClearPreviousSessionData— laps of a reused session id are deletedPacketProcessor.RemoveInvalidSessionFromDatabaseandSessionsControllersession deletion — the whole session is goneFastestLapPerSessionCachehad to becomepublicso the packet processing inF1Server.Servicecan signal the change.Linked issues
Closes #199
Review notes
ParticipantRuntimeData.AddLap/RemoveLap) do not trigger an invalidation. Those rows are stored withIsCompleted = falseand are excluded by theDbIsCompleted == 1filter of the calculation, so they can never influence the fastest lap of a session.RemoveSessionremoves theSemaphoreSlimof the session without disposing it, so a calculation that is still holding it is not hit by anObjectDisposedException.FastestLapPerSessionCacheTestscover the new behaviour; the existing test setup was refactored to share anAddSessionhelper.