[kilted] Fix for multibag replay stagnation (backport #2158) #2169
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.
Description
This PR fixes a problem for slow playback when one reader has a lower frequency topic than others
Added cache for the last element from each reader and taking messages from cache in a chronological order instead of the round-robin order.
To mitigate "spaggetish" code after the fix, this PR also introduces the
ReadersWrapperclass, which will encapsulate readers with their options and message cache.The
ReadersWrapperclass manages multiplerosbag2_cpp::Readerinstances, allowing for chronological reading of messages across all readers. It maintains a cache of the next message from each reader and provides methods to retrieve the next message in chronological order, seek to a specific timestamp across all readers, and apply filters to all readers. It also provides access to the earliest and latest timestamps across all readers.Fixes When using multibag replay, the frequency of the messages on topics is reduced and inconsistent over the time #2156
Depends on the Bugfix for incorrect MCAPStorage::seek(timestamp) when timestamp is current #2157
Is this user-facing behavior change?
Fixed a bug where playback of the higher frequency topics can slow down when present slow frequency topics in another playing bag.
Did you use Generative AI?
Yes. I am using GitHub Copilot, GPT-4.1, in my workflow. in particular to help with unit tests and documentation.
Additional Information
This PR can be backported to the other distros.
This is an automatic backport of pull request #2158 done by [Mergify](https://mergify.com).