-
Notifications
You must be signed in to change notification settings - Fork 292
Persist Transient Local topics in snapshot mode #2279
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
base: rolling
Are you sure you want to change the base?
Persist Transient Local topics in snapshot mode #2279
Conversation
Signed-off-by: Tony Najjar <[email protected]>
| message_lost = !message_cache_->push(converted_msg); | ||
| // Check if this topic uses transient_local durability | ||
| if (transient_local_topics_.find(message->topic_name) != transient_local_topics_.end()) { | ||
| message_cache_->push_transient_local(converted_msg); |
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.
TODO: handling of lost messages?
| std::lock_guard<std::mutex> cache_lock(transient_local_buffer_mutex_); | ||
| // Store/update the latest message for this topic | ||
| // This ensures we always have the most recent state for transient local topics | ||
| transient_local_messages_[msg->topic_name] = std::move(msg); |
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.
TODO: store more than just the last msg?
| // Use the front message timestamp as the snapshot start time for transient local messages. | ||
| // This may not be the absolute earliest timestamp in the buffer (messages can arrive | ||
| // out of order), but it's close enough - typically within 1-2ms of the true minimum. | ||
| // This avoids the overhead of searching through all messages for the exact minimum. | ||
| if (!consumer_data.empty()) { | ||
| snapshot_start_time = consumer_data.front()->recv_timestamp; | ||
| } |
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.
TODO: is this acceptable?
| updated_msg->recv_timestamp = snapshot_start_time; | ||
| updated_msg->send_timestamp = snapshot_start_time; |
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.
TODO: not sure if they should have the same timestamp
Description
Summary
This PR implements preservation of topics with
TRANSIENT_LOCALQoS durability in snapshot mode recording. Previously, transient local topics (like/tf_static, parameter events, or latched topics) could be lost when the circular buffer rolled over, even though they contain critical state information. This feature ensures these messages are always included in snapshots.Problem
In snapshot mode, rosbag2 uses a circular buffer to maintain a rolling window of messages. When a snapshot is triggered, the buffer contents are dumped to disk. However, topics with
TRANSIENT_LOCALdurability semantics—which should persist their latest message for late-joining subscribers—were not treated specially and could be overwritten before snapshot capture.Solution
The implementation adds a separate storage mechanism for transient local messages:
1. Cache Layer (
CircularMessageCache)transient_local_messages_map to store latest message per transient local topicpush_transient_local()method for separate message routingswap_buffers()to merge transient local messages into snapshots with adjusted timestamps2. Writer Layer (
SequentialWriter,Writer)mark_topic_as_transient_local()API to register topicswrite()to route transient local messages to protected storagetransient_local_topics_set to track registered topics3. Recorder Integration
TransientLocalQoS durability during subscription4. Interface Updates
push_transient_local()toMessageCacheInterfacewith default fallbackmark_topic_as_transient_local()toBaseWriterInterfaceFixes #1886
Is this user-facing behavior change?
No
Did you use Generative AI?
Clause Sonnet 4.5
Additional Information