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

fix sequential reader rollover-to-next-file #839

Merged
merged 1 commit into from
Aug 5, 2021

Conversation

lihui815
Copy link
Contributor

@lihui815 lihui815 commented Aug 5, 2021

  • has_next() - calls recursively until next message OR no next file found
  • read_next() - calls has_next() to ensure necessary rollovers are made if necessary

Signed-off-by: Sonia Jin diegothemuich@gmail.com

- has_next() - calls recursively until next message OR no next file found

- read_next() - calls has_next() to ensure necessary rollovers are made

Signed-off-by: Sonia Jin <diegothemuich@gmail.com>
@lihui815 lihui815 requested a review from a team as a code owner August 5, 2021 20:20
@lihui815 lihui815 requested review from zmichaels11 and jhdcs and removed request for a team August 5, 2021 20:20
@lihui815 lihui815 changed the title fix sequential reader rollover-to-next-file strategy fix sequential reader rollover-to-next-file Aug 5, 2021
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.

Nice fix

@emersonknapp
Copy link
Collaborator

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@lihui815 lihui815 merged commit 7407cd7 into ros2:master Aug 5, 2021
@lihui815 lihui815 deleted the sonia-next branch August 5, 2021 21:12
camm73 pushed a commit to camm73/rosbag2 that referenced this pull request Aug 6, 2021
- has_next() - calls recursively until next message OR no next file found

- read_next() - calls has_next() to ensure necessary rollovers are made

Signed-off-by: Sonia Jin <diegothemuich@gmail.com>
Signed-off-by: Cameron Miller <cammlle@amazon.com>
@MichaelOrlov
Copy link
Contributor

@emersonknapp @lihui815 I am sorry for my late response to this closed issue, but IMO it was not a real issue it was working as designed. We just didn't have Doxygen documentation for these API.
I believe it was designed this way on purpose for the sake of performance to avoid calling has_next() twice.
We are calling has_next() and read_next() always sequentially in
Player::enqueue_up_to_boundary(uint64_t boundary)

void Player::enqueue_up_to_boundary(uint64_t boundary)
{
  rosbag2_storage::SerializedBagMessageSharedPtr message;
  for (size_t i = message_queue_.size_approx(); i < boundary; i++) {
    if (!reader_->has_next()) {
      break;
    }
    message = reader_->read_next();
    message_queue_.enqueue(message);
  }
}

and this is only one place where we are calling it.

I would suggest to revert this PR and add relevant Doxygen comment to the read_next() API that if it would be called without checking that has_next() returning true it will be undefined behavior.

@MichaelOrlov
Copy link
Contributor

After some detailed consideration I will step back. Sorry for disturbing.
We actually will need this extra call for has_next() inside read_next() to make sure that seek timestamp will be applied correctly and calling one more time for the reader->has_next() will translates to the one more call to the storage->has_next() call which is going to check that iterator doesn't point to the end and it will not affect performance.

WJaworskiRobotec pushed a commit to RobotecAI/rosbag2 that referenced this pull request Sep 12, 2021
- has_next() - calls recursively until next message OR no next file found

- read_next() - calls has_next() to ensure necessary rollovers are made

Signed-off-by: Sonia Jin <diegothemuich@gmail.com>
Signed-off-by: Wojciech Jaworski <wojciech.jaworski@robotec.ai>
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.

None yet

3 participants