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

rosbag2_cpp: sequential reader specifies no order #1162

Closed

Conversation

james-rms
Copy link
Contributor

@james-rms james-rms commented Nov 17, 2022

Right now SequentialReader chooses a default read order (by default constructing ReadOrder) and calls set_read_order() on the underlying storage plugin. However, the underlying storage plugin may not support that read order. If the user hasn't specified the read order they want, the plugin should just decide for them.

It doesn't really make sense for SequentialReader to always specify the read order, unless the user has actually called set_read_order on SequentialReader. With that in mind this PR removes that constraint.

Fixes ros-tooling/rosbag2_storage_mcap#61

@james-rms james-rms requested a review from a team as a code owner November 17, 2022 03:42
@james-rms james-rms requested review from gbiggs and jhdcs and removed request for a team November 17, 2022 03:42
Signed-off-by: James Smith <james@foxglove.dev>
@james-rms james-rms force-pushed the jrms/sequential-reader-no-order branch from cf5a3f2 to 246c9e0 Compare November 17, 2022 03:43
@james-rms
Copy link
Contributor Author

@emersonknapp are you able to review? (I don't have permission to specifically assign you)

@emersonknapp emersonknapp self-assigned this Nov 17, 2022
@emersonknapp
Copy link
Collaborator

I think that this approach makes sense - there's no particular reason for the SequentialReader to have an opinion unless the user explicitly asks for it. The plugin can have its own default read order.

@emersonknapp
Copy link
Collaborator

Does SequentialReader::set_read_order need any update? Or does the = operator work ok for optional. It's not something I've used much yet

@emersonknapp emersonknapp self-requested a review November 17, 2022 23:39
Copy link
Collaborator

@emersonknapp emersonknapp left a comment

Choose a reason for hiding this comment

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

LGTM with green CI

Signed-off-by: James Smith <james@foxglove.dev>
Copy link
Contributor

@MichaelOrlov MichaelOrlov left a comment

Choose a reason for hiding this comment

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

I have a concern about this PR.
I agree that storage plugin could have some default read order.
However in SequantialReader we have some logic which is rely on read order and falling back to some assumption what default read order would be for the plugin without explicitly reading it out also incorrect behavior!
For instance in changes from this PR made implicit assumption for SequantialReader that default read order for storage plugin is not reverse which might not be necessary the case.

I also opposed to use optional.
While it looks handy and and fancy new C++ feature - it's actually an "evil" for many corner cases and introduce more uncertainty in design and also require more boiler plate dummy checks for nullopt which is very easy to miss or incorrectly mixup with other existent logic.

The right solution if we really want to respect default read order from storage plugin would be to bring in a new API aka rosbag2_storage::ReadOrder rosbag2_storage::get_read_order() and use it in constructor for initialization of the private read_roder variable in SequantialReader.

I am honestly very doubt that this is a big deal or even a meaningful issue that we are falling back to some predefined read order in SequantialReader and enforcing it for underlying storage plugin if it was not set explicitly.
Thea are not too many storage plugins to be worry about this default value.
IMO current behavior is a WAD (worked as designed) and ok to be as is.
Storage plugin shall raise exception if it doesn't support read order settling up from SequantialReader.

@jhdcs
Copy link
Contributor

jhdcs commented Nov 21, 2022

I am curious why optional is "evil". Isn't is supposed to be used to prevent issues with checking for null? How is that evil?

@james-rms
Copy link
Contributor Author

Going with a different approach.

@james-rms james-rms closed this Nov 21, 2022
@MichaelOrlov
Copy link
Contributor

@jhdcs

I am curious why optional is "evil". Isn't is supposed to be used to prevent issues with checking for null? How is that evil?

Here is the real life example while it is "Evil" ros-tooling/topic_tools#48
C++ optional introduces undefined behavior or at least in some cases trying to handle this undefined behavior.
Usually using optional means that present "sub-optimal" design with undefined behavior. In general need to avoid such solutions and designs as much as possible.
C++ optional is intend to be used when there are not possible to change design to avoid such undefined behavior - in all other cases usage of the optional as handy snippet to handle logic shall be avoided as much as possible.

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.

ros2 bag convert cannot read the input file if the input MCAP is not indexed
4 participants