Skip to content
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

Provide BagMetadata to the Player and deserialize QoS profiles for la… #371

Closed
wants to merge 1 commit into from

Conversation

emersonknapp
Copy link
Collaborator

Part of #125

Reads and provides the BagMetadata to the Player, which stores it and deserializes the QoS profiles that it contains (if present). Does not change behavior, just makes the information available for use in the followup to this PR.

Signed-off-by: Emerson Knapp [email protected]

Copy link
Contributor

@piraka9011 piraka9011 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@thomas-moulard thomas-moulard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks OK. This requires some testing IMHO, or was it already covered somehow?

const rosbag2_storage::BagMetadata & metadata)
: reader_(std::move(reader)), rosbag2_transport_(rosbag2_transport), metadata_(metadata)
{
for (auto topic_information : metadata.topics_with_message_count) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const auto& to avoid the copy

const auto & loaded_profiles = YAML::Load(topic_metadata.offered_qos_profiles);
recorded_qos_profiles_[topic_metadata.name] = loaded_profiles.as<std::vector<Rosbag2QoS>>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the unhappy path? I.e. YAML is not correct. Did we test this? Are we printing out a reasonable error message?

I would also suggest to update the documentation to explicitly state what type of exception may get thrown from the ctor. Seems like we're moving from sonething that never could fail, to something that can "easily" fail (given bad input). It's worth checking the implication on the codebase.

Player player(reader_, transport_node);
rosbag2_storage::MetadataIo metadata_io{};
rosbag2_storage::BagMetadata metadata{};
if (metadata_io.metadata_file_exists(storage_options.uri)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really OK not to have metadata?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

legacy rosbags

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ROS1 bags loaded with rosbag2_bag_v2 do not have metadata

@Karsten1987
Copy link
Collaborator

I somewhat have a problem with that change here as I think we duplicate work here. The reader instance does open the storage and receives the metadata itself. I don't see the point - and maybe that's being more clear with the succeeding PR - why we would open the metadata in the reader and in the player. Why not providing a method on the reader interface to get the metadata?

I am a bit worried that in the end we not only duplicate work, but also that if at some point we implement a different behavior in reading the metadata we have to make sure there's no inconsistency between rosbag2_transport and rosbag2_cpp. I am having for example the legacy rosbags in mind, but also any other storage plugin.

@emersonknapp
Copy link
Collaborator Author

@Karsten1987 the reader does provide get_all_topics_and_types which returns a std::vector<rosbag2_storage::TopicMetadata>, which theoretically contains the offered_qos_profiles. However, the sqlite storage plugin reads this metadata from the database, not the yaml file. Essentially right now we have all metadata duplicated between the YAML file and the database.

My understanding from a previous conversation is that the YAML file should be the only place that we continue updating, and that the sqlite database version of the metadata is there for legacy reasons only. If this is true, then we should probably remove the portion of the writer that writes metadata to the database. In the PR where I added the offered_qos_profiles field, I did update the sqlite storage plugin to write the new field into the database metadata, but I did this because I didn't realize the situation that we're in.

What should be the one true source of metadata? If it's the YAML file, then I can change the base reader to read it from the YAML file, instead of having the SQLite storage plugin override it to read from the database?

@Karsten1987
Copy link
Collaborator

However, the sqlite storage plugin reads this metadata from the database, not the yaml file. Essentially right now we have all metadata duplicated between the YAML file and the database.

Looking here I don't think this is true. The sqlite3 plugin (in fact every plugin) reads from the metadataio the content from the .yaml file if present. And I think that should be a only real source to do so. That's why I was proposing the getter function.

The reason why we still have the get_metadata() function on the storage interface is motivated by the fact that not every plugin has this metadata.yaml file, i.e. the ros1 bag files.
As discussed in #213 I was initially advocating to remove that function all together. But that would have implications to legacy bag files.
To that extend, I think we could though provide a standalone tool which generates the metadata.yaml for legacy bag files in order to finally get rid of it. But that's content for another discussion.

@emersonknapp
Copy link
Collaborator Author

Looking here I don't think this is true. The sqlite3 plugin (in fact every plugin) reads from the metadataio the content from the .yaml file if present.

You're right that it reads the YAML file into the private variable metadata_ there, but from there it's not used via existing interfaces.

The BaseReaderInterface provides get_all_topics_and_types, but this calls into the storage, which implements this as a database read

Should I add an interface get_metadata to the BaseReaderInterface to return its correctly-loaded metadata? And, change the SequentialReader's implementation of get_all_topics_and_types to also use this metadata instead of asking the storage? This seems like a sensible solution, since the initial metadata loading had the opportunity to ask the storage, if the yaml file was not found.

@Karsten1987
Copy link
Collaborator

Should I add an interface get_metadata to the BaseReaderInterface to return its correctly-loaded metadata? And, change the SequentialReader's implementation of get_all_topics_and_types to also use this metadata instead of asking the storage? This seems like a sensible solution, since the initial metadata loading had the opportunity to ask the storage, if the yaml file was not found.

Yes! To all :) I think this makes a lot of sense. But as with the metadata itself, I think we can't easily remove that function get_all_topics_and_types that easily from the storage interface, again because of the legacy ros1 bags.

@emersonknapp
Copy link
Collaborator Author

Agreed that we can't remove the storage interface right now, but we can skip using it here. I'll go ahead and update the SequentialReader interfaces.

@emersonknapp
Copy link
Collaborator Author

Closing in favor of exposing this data through the Reader - starting here #372

@Karsten1987
Copy link
Collaborator

@emersonknapp do you want to keep this branch alive or can it be deleted?

@emersonknapp emersonknapp deleted the emersonknapp/player-metadata branch April 14, 2020 01:49
@emersonknapp
Copy link
Collaborator Author

Deleted

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.

5 participants