From 9e4b1151872af24c5071a4f4f6aa4032550aba20 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Sat, 22 Jun 2024 20:20:19 -0700 Subject: [PATCH] [iron] Propagate "custom_data" and "ros_distro" in to the metadata.yaml file during re-indexing (backport #1700) (#1711) * Propagate "custom_data" and "ros_distro" in to the metadata.yaml file during re-indexing (#1700) * propagate custom data and ros_distro during reindexing Signed-off-by: Cole Tucker Signed-off-by: coalman321 * fix ament uncrustify issue Signed-off-by: coalman321 * only update metadata if size is nonzero Signed-off-by: coalman321 * fix uncrustify issue and switch to empty Signed-off-by: coalman321 * update reindexer test to verify custom data and ros_distro changes Signed-off-by: coalman321 * Convert to use exact clock type for windows CI Signed-off-by: coalman321 --------- Signed-off-by: coalman321 (cherry picked from commit 804432c94da166a79ae4a08bca69d6a3a9915f59) * Remove "metadata.ros_distro" update since we don't have in on Iron Signed-off-by: Michael Orlov * Skip check for `custom_metadata` in test for mcap storage plugin. - Rationale: Mcap storage doesn't store serialized metadata in bag directly on Iron and Humble. Backporting of the relevant #1423 is not possible without updating mcap vendor package to the v1.1.0 because we have dependencies from the mcap_reader_->metadataIndexes(); API which became available only in the https://github.com/foxglove/mcap/pull/902 Signed-off-by: Michael Orlov --------- Signed-off-by: Michael Orlov Co-authored-by: Cole Tucker Co-authored-by: Michael Orlov --- rosbag2_cpp/src/rosbag2_cpp/reindexer.cpp | 10 ++++++++++ rosbag2_tests/test/rosbag2_tests/test_reindexer.cpp | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/rosbag2_cpp/src/rosbag2_cpp/reindexer.cpp b/rosbag2_cpp/src/rosbag2_cpp/reindexer.cpp index 5ae804074e..5bf6b65f62 100644 --- a/rosbag2_cpp/src/rosbag2_cpp/reindexer.cpp +++ b/rosbag2_cpp/src/rosbag2_cpp/reindexer.cpp @@ -165,6 +165,8 @@ void Reindexer::aggregate_metadata( const rosbag2_storage::StorageOptions & storage_options) { std::map temp_topic_info; + std::chrono::time_point latest_log_start = + std::chrono::time_point::min(); // In order to most accurately reconstruct the metadata, we need to // visit each of the contained relative files files in the bag, @@ -191,6 +193,14 @@ void Reindexer::aggregate_metadata( auto temp_metadata = bag_reader->get_metadata(); metadata_.storage_identifier = temp_metadata.storage_identifier; + // try to find the last log for the most complete custom data section + if (latest_log_start < temp_metadata.starting_time) { + latest_log_start = temp_metadata.starting_time; + if (!temp_metadata.custom_data.empty()) { + metadata_.custom_data = temp_metadata.custom_data; + } + } + if (temp_metadata.starting_time < metadata_.starting_time) { metadata_.starting_time = temp_metadata.starting_time; } diff --git a/rosbag2_tests/test/rosbag2_tests/test_reindexer.cpp b/rosbag2_tests/test/rosbag2_tests/test_reindexer.cpp index 4bbc3b9d3d..2aa7a84edb 100644 --- a/rosbag2_tests/test/rosbag2_tests/test_reindexer.cpp +++ b/rosbag2_tests/test/rosbag2_tests/test_reindexer.cpp @@ -80,6 +80,7 @@ class ReindexTestFixture : public ParametrizedTemporaryDirectoryFixture rosbag2_storage::StorageOptions storage_options; storage_options.storage_id = GetParam(); storage_options.uri = root_bag_path_.string(); + storage_options.custom_data["name"] = "value"; writer.open(storage_options); rosbag2_storage::TopicMetadata topic; topic.name = "/test_topic"; @@ -132,6 +133,15 @@ TEST_P(ReindexTestFixture, test_multiple_files) { EXPECT_EQ(generated_metadata.storage_identifier, GetParam()); EXPECT_EQ(generated_metadata.version, target_metadata.version); + if (GetParam() != "mcap") { + // Skip check for mcap storage since it doesn't store serialized metadata in bag directly on + // Iron and Humble. Backporting of the relevant #1423 is not possible without updating + // mcap vendor package to the v1.1.0 because we have dependencies from the + // mcap_reader_->metadataIndexes(); API which became available only in the + // https://github.com/foxglove/mcap/pull/902 + EXPECT_EQ(generated_metadata.custom_data, target_metadata.custom_data); + } + for (const auto & gen_rel_path : generated_metadata.relative_file_paths) { EXPECT_TRUE( std::find(