rosbag2
rosbag2 copied to clipboard
Max bag file size not conformed to with SequentialWriter in snapshot mode
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++;
}
}
}
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?