-
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
Use topic_id instead of topic_name in inner rosbag2 buffers and data structures #1553
Comments
I finally found time to put it all together in one feature request. |
Why not keep |
@arneboe This is a good question and proposal. I will try to make it within the scope of the #1538 |
Maybe my understanding of how rosbag works internally is lacking. I don't understand why a hash table is needed. In any case that is a micro optimization compared to getting rid of the strings :) |
@arneboe As regards:
It would be possible if we could be sure that the SQLite3 engine will assign indexes sequentially and will not go into the negative part. Although as far as I am aware there is no guarantee for that. Also, please keep in mind that we have the |
after all, i think that is okay to have
|
I don't think that this will have a huge impact on performance (know, this is my guts speaking, only test will show). On the other side, I can see positive aspects, as multiple publishes per topic would move the rosbag play nearer to the real system behavior. |
This issue has been mentioned on ROS Discourse. There might be relevant details there: https://discourse.ros.org/t/ros-2-meeting-minutes-2024-02-15/36221/1 |
Description
Motivation:
topic_id
represented as integer type instead of fulltopic_name
represented as a string for each message.This is very meaningful when using the snapshot feature and recording on the host HW with limited resources.
topic_id
instead of thetopic_name
in internal data structures and buffers is the ability to differentiate different publishers with the same topic name. It might be a situation for instance when multiple publishers exist on the same topic but have different QoS settings. Another use case could be when multiple publishers exist on the same topic but with different versions of the type definitions.Currently, we don't support these use cases in the rosbag2. However, if we will differentiate topics by topic id in inner rosbag2 representation on all layers we would be able to add support for the aforementioned use cases in the future.
Related Issues
#1531
Completion Criteria
topic_id
in integer representation instead oftopic_name
for each message stored in inner buffers during recording.topic_id
in integer representation instead oftopic_name
for each message stored in inner buffers during playback or bag rewrite.Implementation Notes / Suggestions
To achieve the completion criteria we would need to make the following structural changes:
Will need to store
topic_id
instead of thetopic_name
in therosbag2/rosbag2_storage/include/rosbag2_storage/serialized_bag_message.hpp
Lines 27 to 32 in bbbb217
and store map with
topic_id
totopic_name
and vice versa where it is needed on the rosbag2_cpp and rosbag2_transport layers.To be able to operate with unique
topic_id
on rosbag2_transport and rosbag2_cpp layers, especially in the cache buffers need to somehow generate thistopic_id
or get it from somewhere.It turns out that
sqlite3
andmcap
already operate with unique topic id on the storage layer and generate unique topic_id at the moment of creation of a new topic. It will be reasonable to keep current behavior and let storage plugins assign unique topic id during topic creation. We just need to somehow get it from storage on the recording and playback.currently, we have the following
create_topic
interfacerosbag2/rosbag2_storage/include/rosbag2_storage/storage_interfaces/base_write_interface.hpp
Lines 44 to 46 in bbbb217
One of the options would be to change this API to return the topic id instead of the void as a result of this method. The another option would be to remove const qualifier from the
TopicMetadata & topic
parameter and addtopic_id
to theTopicMetadata
data structure. To be able to store topic_id to theSerializedBagMessage
during recording it might be enough a first option when returningtopic_id
from thecreate_topic(..)
API. However, to be able to operate with topic_id during playback and bag rewrite we anyway will need to add topic_id to theTopicMetadata
.Therefore the second option is more preferable. One more point toward the second option with removing the const qualifier from the
TopicMetadata
parameter is less invasive API changes. Perhaps these changes wouldn't require significant changes on the downstream dependencies. In contrast, if would need to change the return parameter for thecreate_topic(..)
we would need to go to the full cycle of the deprecation of the old API and create a newcreate_topic(..)
API at the same time. Which is less preferable.After adding
topic_id
to theTopicMetadata
data structure to be able to operate withtopic_id
during playback and map it to thetopic_name
will need to change implementations of theget_all_topics_and_types()
API.rosbag2/rosbag2_storage/include/rosbag2_storage/storage_interfaces/base_read_interface.hpp
Line 75 in bbbb217
In all storage plugins to read out from storage and populate this newly added
topic_id
field.Size of the type of the newly adding
topic_id
field.In MCAP specification we reserved 16 bit for the topic_id. This is the
ChannelId
the MCAP inner type which corresponds to theuint16_t
. When we were creating the MCAP format we decided that the ability to differentiate a maximum65535
topics would be enough in the vast majority of cases. However, in theSQLite3
storage plugin we are usingtopic_id
as an index to map records from themessages
DB table to the correspondingtopics
table. According to theSQLite3
specification, the index is theint64_t
data type and can't be changed.Therefore the type of the newly adding
topic_id
filed shall be no less thanint64_t
and shall be with the sign.Testing Notes / Suggestions
The main functionality is expected to be already covered by the existent unit tests, however, a few new tests might be needed.
The text was updated successfully, but these errors were encountered: