Skip to content

Conversation

@mergify
Copy link

@mergify mergify bot commented Sep 12, 2025

Description

This PR fixes a problem for slow playback when one reader has a lower frequency topic than others

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).

* Add "high_freq_topics_does_not_starve_in_multibag_playback" test

Signed-off-by: Michael Orlov <morlovmr@gmail.com>

* Quick fix for slow playback when one reader has lower freq topic

- Add cache for the last element from each reader and taking messages
 from cache in a chronological order.
- Also use "rcpputils::unique_lock" consistently for the reader_mutex_

Signed-off-by: Michael Orlov <morlovmr@gmail.com>

* Add ReadersWrapper class that encapsulates readers and messages cache

- The ReadersWrapper class manages multiple rosbag2_cpp::Reader
 instances, 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.

Signed-off-by: Michael Orlov <morlovmr@gmail.com>

* Add unit tests for ReadersWrapper class

Signed-off-by: Michael Orlov <morlovmr@gmail.com>

* Delete default ctor and copy/move operators for ReadersWrapper class

Signed-off-by: Michael Orlov <morlovmr@gmail.com>

* Rename ReadersWrapper class to the ReadersManager

Signed-off-by: Michael Orlov <michael.orlov@apex.ai>

* Rename get_next_chronological_message_from_cache

- Reasoning: Not mentioning cache in the name because this is some
 implementation details and could be changed in the future. However,
 the API needs to be stable and clear.
- Also added a comment about reasoning for usage pre-cache inside
 implementation file.

Signed-off-by: Michael Orlov <michael.orlov@apex.ai>

* Rename "no_messages_in_cache" to the "has_next()"

Signed-off-by: Michael Orlov <michael.orlov@apex.ai>

* Renames for mutex and condition_variable

- Rename "skip_message_in_main_play_loop_mutex_" to the
 "main_play_loop_mutex_" and "playback_finished_cv_" into the
 "is_in_playback_cv_".

Signed-off-by: Michael Orlov <michael.orlov@apex.ai>

* Fix for messages_queue access race in seek(time)

- Stop storage loading thread before doing seek to avoid race condition
- Return from seek at the beginning if player is not in playback mode.
  Reasoning: We will seek to the beginning of the bag when will start
  play() anyway.

Signed-off-by: Michael Orlov <michael.orlov@apex.ai>

* Speedup "load_storage_content()" interruption

- Check "load_storage_content_" inside "enqueue_up_to_boundary()"

Signed-off-by: Michael Orlov <michael.orlov@apex.ai>

* Fix for play_fails_gracefully_if_needed_coverter_plugin_does_not_exist

Add missing converter options when open readers

Signed-off-by: Michael Orlov <michael.orlov@apex.ai>

---------

Signed-off-by: Michael Orlov <morlovmr@gmail.com>
Signed-off-by: Michael Orlov <michael.orlov@apex.ai>
(cherry picked from commit bfce7ac)
@MichaelOrlov MichaelOrlov changed the title Fix for multibag replay stagnation (backport #2158) [kilted] Fix for multibag replay stagnation (backport #2158) Sep 12, 2025
@MichaelOrlov
Copy link
Contributor

Pulls: #2169
Gist: https://gist.githubusercontent.com/MichaelOrlov/a43598ce1c90efaa4f63bbae91511c4f/raw/608d3f9d4275cea7da28c6c0a8a39dfeee2c17f2/ros2.repos
BUILD args: --packages-above-and-dependencies rosbag2_transport rosbag2_tests
TEST args: --packages-above rosbag2_transport rosbag2_tests
ROS Distro: kilted
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/16941

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@MichaelOrlov MichaelOrlov merged commit 18d5a25 into kilted Sep 13, 2025
12 checks passed
@MichaelOrlov MichaelOrlov deleted the mergify/bp/kilted/pr-2158 branch September 13, 2025 07:12
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.

2 participants