-
Notifications
You must be signed in to change notification settings - Fork 248
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
Design proposal for snapshot feature #837
Merged
emersonknapp
merged 2 commits into
ros2:master
from
camm73:cameron/snapshot-design-proposal
Aug 5, 2021
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Adding a Snapshot Service for rosbag2 | ||
|
||
## Context | ||
In [ros2/rosbag2#663](https://github.com/ros2/rosbag2/issues/663), it was recommended that a "snapshot" feature be added to rosbag2. | ||
|
||
## Motivation | ||
The goal of this feature is to provide the user with a mechanism to maintain a transient cache of the recent messages sent on specified topics that is only written to permanent storage upon a user-invoked trigger. | ||
|
||
|
||
For example, if a rare, anomalous behavior occurs, this feature will allow the user to record the most recent ROS topic messages when the behavior is observed, instead of having to record the entire execution. | ||
|
||
## Example Usage | ||
|
||
Starting `rosbag2` in snapshot mode with a specified cache size: | ||
``` | ||
$ ros2 bag record --max-cache-size 100000 --snapshot-mode [topics [topics ...]] | ||
``` | ||
|
||
Triggering a snapshot: | ||
emersonknapp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
$ ros2 service call /rosbag2_recorder/take_snapshot rosbag2_interfaces/TakeSnapshot | ||
``` | ||
|
||
|
||
## Implementation Proposal | ||
|
||
* Add a `--snapshot-mode` flag to the `record` verb in `ros2bag` that will be passed via `StorageOptions`. | ||
|
||
* Create a new class `CircularBufferMessageCache` which maintains two circular buffers sized according to the existing `—max-cache-size` parameter. During snapshot mode, this class will keep adding messages to the same circular buffer until triggered to switch to the secondary buffer by the `Recorder` class. | ||
|
||
* Create a service `/rosbag2_recorder/take_snapshot` in the `rosbag2_recorder` node that will listen for snapshot requests. Upon receiving a service call, it will trigger a buffer flip in `CircularBufferMessageCache` and call the new `take_snapeshot` function in `SequentialWriter` (detailed below) to write the snapshot messages to storage. | ||
|
||
* Modify `SequentialWriter` to use `CircularBufferMessageCache` when snapshot mode is enabled instead of `MessageCache` and `CacheConsumer`. | ||
|
||
* Add a new `take_snapshot` function to `SequentialWriter` that will be invoked by the `rosbag2_recorder` node's snapshot service to write the snapshot data to the rosbag, close the rosbag, and open a new rosbag for a future snapshot. | ||
|
||
* Implement the `/rosbag2_recorder/take_snapshot` service interface as `TakeSnapshot.srv` in `rosbag2_interfaces`. It won’t require any arguments (similar to `Resume.srv`). | ||
|
||
|
||
## Implementation Breakdown | ||
The snapshot feature implementation could be broken down into the following PRs: | ||
|
||
* Implement `CircularBufferMessageCache` and add corresponding tests. | ||
* Integrate `CircularBufferMessageCache` into `SequentialWriter` and update its tests. | ||
* Create the `rosbag2_recorder/take_snapshot` service in the `Recorder` class, add corresponding tests, and create the `TakeSnapshot.srv` service interface. | ||
* Add `--snapshot-mode` to the `record` verb and update `StorageOptions` |
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.
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.
Next to
--max-cache-size 100000
,--max-cache-duration 30
would be nice.Omitting one would mean no limit.