rosbag2 icon indicating copy to clipboard operation
rosbag2 copied to clipboard

Max bag file size not conformed to with SequentialWriter in snapshot mode

Open Gregory119 opened this issue 3 years ago • 1 comments

The check to create a separate bag file when reaching the bag file size limit is only done after writing the entire cache to disk. So for example, if there are 5000 bytes of cached messages, the max bag file size is 3000 bytes and the current bag on disk is 0 bytes. Then if a snapshot request is made the entire cache will be written to the bag file file making it 5000 bytes (over the 3000 limit). Looking at the code the following SequentialWriter::write_messages function should likely include this limit check in some form.

void SequentialWriter::write_messages(
  const std::vector<std::shared_ptr<const rosbag2_storage::SerializedBagMessage>> & messages)
{
  if (messages.empty()) {
    return;
  }
  storage_->write(messages);
  std::lock_guard<std::mutex> lock(topics_info_mutex_);
  for (const auto & msg : messages) {
    if (topics_names_to_info_.find(msg->topic_name) != topics_names_to_info_.end()) {
      topics_names_to_info_[msg->topic_name].message_count++;
    }
  }
}

Gregory119 avatar Mar 23 '22 14:03 Gregory119

Good catch - this is definitely a bug in the interaction between these two features.

And, it looks like sufficiently large buffer size also can violate the bagfile size, without snapshot mode?

emersonknapp avatar Mar 28 '22 22:03 emersonknapp