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

[test] reindexer core OSX fix #691

Closed
wants to merge 48 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
afd835a
Copy over relevant work to start
Feb 12, 2021
b6c02a7
Remove sequential_reindexer
Feb 12, 2021
9a87171
Switching to reader for metadata queries.
Feb 12, 2021
1e3db0d
Properly construct reader.
Feb 12, 2021
35cc9b6
Add test bags for unit testing
Feb 12, 2021
fdf57ce
Starting framework for unit test.
Feb 12, 2021
134127a
Ignore temp database files
Feb 12, 2021
42a3f00
Debugging reindexing not reading multiple files
Feb 12, 2021
03fb790
Fix metadata writer
Feb 12, 2021
361237a
Begin moving metadata target files over
Feb 12, 2021
719e791
Add other two target files
Feb 12, 2021
ce009af
First working version of unit tests
Feb 12, 2021
e305fc4
Convert to rcutils directory iterator
Feb 12, 2021
b9eac0f
Remove debug code
Feb 12, 2021
4eb96d2
Linting fix
Feb 12, 2021
e8b4389
Clean comments, switch to exceptions
Feb 12, 2021
6ceb61e
Re-add Mutex
Feb 12, 2021
d1005e0
Remove nested namespace
Feb 12, 2021
d47a604
Remove converter, commenting changes
Feb 12, 2021
f39095d
Use map in creating topic metadata section
Feb 12, 2021
1bd59f5
Remove unneeded database files
Feb 12, 2021
5445b5a
Trim unneeded functions and members
Feb 12, 2021
1c0c0f5
Re-add mutex, take 2
Feb 12, 2021
fc1111c
Missed a rename and remove
Feb 12, 2021
9d0483c
Re add missing functions
Feb 12, 2021
ee30918
Documentation changes
Feb 15, 2021
fe638f8
Improve error messages, and put them in proper level
Feb 15, 2021
6881ad6
Remove dead function
Feb 15, 2021
6fe4984
Convert regex pattern to member variable
Feb 15, 2021
01fd6e9
Extend documentation
Feb 15, 2021
bb6b221
Properly capture bag size
Feb 15, 2021
ef0ae0a
Allow rosbag2 storage to return expected file extension
Feb 15, 2021
5816137
[WIP] [DOES NOT COMPILE]
Feb 15, 2021
29f99c6
Revert storage extension attempt.
Feb 19, 2021
d609f30
Remove unused function from header
Feb 19, 2021
c6df120
Remove unneeded comments
Feb 19, 2021
a1b1175
Fixed comment typo
Feb 19, 2021
4157197
Remove API for get_storage_extension
Feb 23, 2021
133e779
Comment improvements
Feb 23, 2021
1ce69f5
Use default destructor
Feb 23, 2021
19530f8
Bring documentation comments in-line with
Feb 23, 2021
cd193d7
Try to fix undeclared identifier in Windows build
Feb 26, 2021
8c13eba
Fix error being logged to debug
Mar 2, 2021
6a73558
Move testing code to its new home in rosbag2_tests
Mar 3, 2021
b2d0fd4
Revert stream logging change
Mar 12, 2021
8e69f23
Make sure variable is initialized before displaying
Mar 15, 2021
ee876cd
Add in possibly-missing dependency
Mar 15, 2021
fb8c4a5
Fix test by creating a new bagfile - it seems like it was corrupted i…
emersonknapp Mar 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ build/
venv/
**/.pytest_cache/
__pycache__/
*.db3-*
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class MockStorage : public rosbag2_storage::storage_interfaces::ReadWriteInterfa
MOCK_CONST_METHOD0(get_bagfile_size, uint64_t());
MOCK_CONST_METHOD0(get_relative_file_path, std::string());
MOCK_CONST_METHOD0(get_storage_identifier, std::string());
MOCK_CONST_METHOD0(get_storage_extension, std::string());
MOCK_CONST_METHOD0(get_minimum_split_file_size, uint64_t());
};

Expand Down
7 changes: 6 additions & 1 deletion rosbag2_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 3.5)
project(rosbag2_cpp)

add_definitions(-D_SRC_REINDEX_DIR_PATH="${CMAKE_CURRENT_SOURCE_DIR}/test/rosbag2_cpp/reindex_test_bags")

# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
Expand Down Expand Up @@ -60,9 +62,11 @@ add_library(${PROJECT_NAME} SHARED
src/rosbag2_cpp/typesupport_helpers.cpp
src/rosbag2_cpp/types/introspection_message.cpp
src/rosbag2_cpp/writer.cpp
src/rosbag2_cpp/writers/sequential_writer.cpp)
src/rosbag2_cpp/writers/sequential_writer.cpp
src/rosbag2_cpp/reindexer.cpp)

ament_target_dependencies(${PROJECT_NAME}
PUBLIC
ament_index_cpp
pluginlib
rcpputils
Expand Down Expand Up @@ -175,6 +179,7 @@ if(BUILD_TESTING)
target_link_libraries(test_message_cache ${PROJECT_NAME})
endif()


# If compiling with gcc, run this test with sanitizers enabled
ament_add_gmock(test_ros2_message
test/rosbag2_cpp/types/test_ros2_message.cpp
Expand Down
127 changes: 127 additions & 0 deletions rosbag2_cpp/include/rosbag2_cpp/reindexer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// Copyright 2020 DCS Corporation, All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// DISTRIBUTION A. Approved for public release; distribution unlimited.
// OPSEC #4584.
//
// Delivered to the U.S. Government with Unlimited Rights, as defined in DFARS
// Part 252.227-7013 or 7014 (Feb 2014).
//
// This notice must appear in all copies of this file and its derivatives.

#ifndef ROSBAG2_CPP__REINDEXER_HPP_
#define ROSBAG2_CPP__REINDEXER_HPP_

#include <memory>
#include <regex>
#include <string>
#include <vector>

#include "rcpputils/filesystem_helper.hpp"

#include "rosbag2_cpp/converter.hpp"
#include "rosbag2_cpp/reader.hpp"
#include "rosbag2_cpp/serialization_format_converter_factory.hpp"
#include "rosbag2_cpp/serialization_format_converter_factory_interface.hpp"
#include "rosbag2_cpp/visibility_control.hpp"

#include "rosbag2_storage/metadata_io.hpp"
#include "rosbag2_storage/storage_factory.hpp"
#include "rosbag2_storage/storage_factory_interface.hpp"
#include "rosbag2_storage/storage_options.hpp"
#include "rosbag2_storage/storage_filter.hpp"
#include "rosbag2_storage/storage_interfaces/read_only_interface.hpp"

// This is necessary because of using stl types here. It is completely safe, because
// a) the member is not accessible from the outside
// b) there are no inline functions.
#ifdef _WIN32
# pragma warning(push)
# pragma warning(disable:4251)
#endif

namespace rosbag2_cpp
{

/**
* Tool to reconstruct bag metadata files in the event of loss or corruption
*
* Reindexing is an operation where a bag that is missing a metadata.yaml file can have a new
* file created through parsing of the metadata stored within the actual files of the bag.
* For instance: Imagine we are working with SQL databases (.db3). We can open the individual
* .db3 files within the bag and read their metadata (not the messages themselves) to replicate
* a usable metadata.yaml file, so that the bag can once again be read by the standard read
* command.
*
* Reindexing has some limitations - It cannot perfectly replicate the original metadata file,
* since some information known by the program from the start up command cannot be found
* within the metadata. But it should at least repair a bag to the point it can be read
* again.
*
*/
class ROSBAG2_CPP_PUBLIC Reindexer
{
public:
Reindexer(
std::unique_ptr<rosbag2_storage::StorageFactoryInterface> storage_factory =
std::make_unique<rosbag2_storage::StorageFactory>(),
std::unique_ptr<rosbag2_storage::MetadataIo> metadata_io =
std::make_unique<rosbag2_storage::MetadataIo>());

virtual ~Reindexer() = default;

/// Use the supplied storage options to reindex a bag defined by the storage options URI.
/*
* \param storage_options Provides best-guess parameters for the bag's original settings.
*/
void reindex(const rosbag2_storage::StorageOptions & storage_options);

protected:
std::unique_ptr<rosbag2_storage::StorageFactoryInterface> storage_factory_{};
std::unique_ptr<rosbag2_storage::MetadataIo> metadata_io_{};
rosbag2_storage::BagMetadata metadata_{};
std::vector<rosbag2_storage::TopicMetadata> topics_metadata_{};

private:
std::string regex_bag_pattern_;
rcpputils::fs::path base_folder_; // The folder that the bag files are in
std::shared_ptr<SerializationFormatConverterFactoryInterface> converter_factory_{};
void get_bag_files(
const rcpputils::fs::path & base_folder,
std::vector<rcpputils::fs::path> & output);

// Prepares the metadata by setting initial values.
void init_metadata(
const std::vector<rcpputils::fs::path> & files,
const rosbag2_storage::StorageOptions & storage_options);

// Attempts to harvest metadata from all bag files, and aggregates the result
void aggregate_metadata(
const std::vector<rcpputils::fs::path> & files,
const std::unique_ptr<rosbag2_cpp::readers::SequentialReader> & bag_reader,
const rosbag2_storage::StorageOptions & storage_options);

// Comparison function for std::sort with our filepath convention
bool compare_relative_file(
const rcpputils::fs::path & first_path,
const rcpputils::fs::path & second_path);
};

} // namespace rosbag2_cpp

#ifdef _WIN32
# pragma warning(pop)
#endif

#endif // ROSBAG2_CPP__REINDEXER_HPP_
Loading