Skip to content

Commit

Permalink
Fix incorrect zero size for sqlite storage (#1759) (#1761)
Browse files Browse the repository at this point in the history
* Fix incorrect zero size for sqlite storage

Signed-off-by: Roman Sokolkov <[email protected]>

* Adjust unit test to precisely verify the returned file size

Signed-off-by: Michael Orlov <[email protected]>

---------

Signed-off-by: Roman Sokolkov <[email protected]>
Signed-off-by: Michael Orlov <[email protected]>
Co-authored-by: Michael Orlov <[email protected]>
(cherry picked from commit 86f681d)

Co-authored-by: Roman <[email protected]>
  • Loading branch information
mergify[bot] and r7vme authored Jul 26, 2024
1 parent cf268d8 commit c86a562
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,15 @@ void SqliteStorage::open(
throw std::runtime_error("Failed to setup storage. Error: " + std::string(e.what()));
}

db_page_size_ = get_page_size();
db_file_size_ = 0;
page_count_statement_ = database_->prepare_statement("PRAGMA page_count;");
db_page_size_ = get_page_size();
db_file_size_ = db_page_size_ * read_total_page_count_locked();

// initialize only for READ_WRITE since the DB is already initialized if in APPEND.
if (is_read_write(io_flag)) {
db_schema_version_ = kDBSchemaVersion_;
std::lock_guard<std::mutex> db_lock(db_read_write_mutex_);
initialize();
db_file_size_ = db_page_size_ * read_total_page_count_locked();
} else {
db_schema_version_ = read_db_schema_version();
read_metadata();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@ TEST_F(StorageTestFixture, string_messages_are_written_and_read_to_and_from_sqli
}
}

TEST_F(StorageTestFixture, check_get_bagfile_size_in_read_only_mode) {
std::vector<std::tuple<std::string, int64_t, std::string, std::string, std::string>>
string_messages =
{std::make_tuple("first message", 1, "topic1", "type1", ""),
std::make_tuple("second message", 2, "topic2", "type2", "")};

write_messages_to_sqlite(string_messages);
std::unique_ptr<rosbag2_storage::storage_interfaces::ReadOnlyInterface> readable_storage =
std::make_unique<rosbag2_storage_plugins::SqliteStorage>();

const auto bag_path = std::filesystem::path(temporary_dir_path_) / "rosbag.db3";
auto db_filename = bag_path.generic_string();
readable_storage->open({db_filename, kPluginID});

EXPECT_EQ(readable_storage->get_bagfile_size(), std::filesystem::file_size(bag_path));
}

TEST_F(StorageTestFixture, has_next_return_false_if_there_are_no_more_messages) {
std::vector<std::tuple<std::string, int64_t, std::string, std::string, std::string>>
string_messages =
Expand Down

0 comments on commit c86a562

Please sign in to comment.