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

SequentialWriter::open failing to create a bag file #448

Closed
Marwan99 opened this issue Jun 28, 2020 · 2 comments
Closed

SequentialWriter::open failing to create a bag file #448

Marwan99 opened this issue Jun 28, 2020 · 2 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@Marwan99
Copy link
Contributor

Description

I am trying to use the API to save a message to a bag.
I am using rosbag2_cpp::writers::SequentialWriter to open a bag (which does not exist yet, expecting the API to create it) then write to it.

Expected Behavior

Creation of a bag file in the URI specified on the use of SequentialWriter::open.

Actual Behavior

No bag file is being created. I am getting the error messages below and the code stops.

[rosbag2_storage]: Could not open 'my_bag/my_bag_0' with 'sqlite3'. Error: Failed to setup storage. Error: Could not read-write open database. SQLite error (14): unable to open database file
[ERROR] [1593304125.490127311] [rosbag2_storage]: Could not load/open plugin with storage id 'sqlite3'.
unknown file: Failure C++ exception with description "No storage could be initialized. Abort"

To Reproduce

That's part of the code I am using, bag->open(...) is what cause all the error messages:

rosbag2_cpp::StorageOptions storage_options = rosbag2_cpp::StorageOptions{};
storage_options.uri = "my_bag";
storage_options.storage_id = "sqlite3";

auto bag = std::make_unique<rosbag2_cpp::writers::SequentialWriter>();
bag->open(storage_options, {"rmw_format", "rmw_format"});

System

  • OS: Ubuntu 18.04
  • ROS 2 Distro: Rolling
  • Version: master a4d49db

Additional context

I have dug a bit into the code, it seems to me that SqliteWrapper::SqliteWrapper is the method that is supposed to create a db3 file in whatever URI passed to. I did some tests and this function can only create db3 files in existing directories and will fail to create a db if the directory doesn't exist.

int rc = sqlite3_open_v2(
uri.c_str(), &db_ptr,
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_NOMUTEX, nullptr);

I couldn't see a place where non-existent URIs get created(maybe I am missing something). I think the resolution for this problem could be checking the existence of the URI and creating it if it doesn't exist, this can maybe be performed in this function:

std::string format_storage_uri(const std::string & base_folder, uint64_t storage_count)

Apologies if my problem analysis is wrong (likely :-)), Please let me know if I need to provide any extra info.
Thanks in advance!

@Marwan99 Marwan99 added the bug Something isn't working label Jun 28, 2020
@Karsten1987
Copy link
Collaborator

You've analyzed the problem absolutely correctly. It's currently the ros2bag command line interface which is responsible for creating the directory: https://github.com/ros2/rosbag2/blob/master/ros2bag/ros2bag/verb/record.py#L111

I guess by now we have enough functionality in rcutils/rcpputils to integrate that work into rosbag2_cpp. So thanks a lot for opening the discussion here.

@Karsten1987
Copy link
Collaborator

closed via #450

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants