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

Change default cache size for sequential_writer to a non zero value #533

Merged
merged 5 commits into from
Oct 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 5 additions & 3 deletions ros2bag/ros2bag/verb/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ def add_arguments(self, parser, cli_name): # noqa: D102
'the bag will split at whichever threshold is reached first.'
)
parser.add_argument(
'--max-cache-size', type=int, default=0,
help='maximum amount of messages to hold in cache before writing to disk. '
'Default it is zero, writing every message directly to disk.'
'--max-cache-size', type=int, default=1024*1024,
help='maximum size (in bytes) of messages to hold in cache before writing to disk. '
'Default is 1 mebibyte, everytime the cache size equals or exceeds 1MB, '
'it will be written to disk. If the value specified is 0, then every message is'
'directly written to disk.'
)
parser.add_argument(
'--compression-mode', type=str, default='none',
Expand Down
2 changes: 1 addition & 1 deletion rosbag2_cpp/include/rosbag2_cpp/storage_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct StorageOptions

// The cache size indiciates how many messages can maximally be hold in cache
// before these being written to disk.
// Defaults to 0, and effectively disables the caching.
// A value of 0 disables caching and every write happens directly to disk.
uint64_t max_cache_size = 0;
};

Expand Down
2 changes: 0 additions & 2 deletions rosbag2_cpp/src/rosbag2_cpp/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ void Reader::open(const std::string & uri)
rosbag2_cpp::StorageOptions storage_options;
storage_options.uri = uri;
storage_options.storage_id = "sqlite3";
storage_options.max_bagfile_size = 0; // default
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this assignment in unnecessary and keeps the code clean and consistent

[Note: if we want to keep this then storage_options.max_bagfile_duration = 0, is something we should add to this.]

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - I think you are right. It might also make sense to move the "sqlite3" default value to the struct definition as well. No need to do that right now though

storage_options.max_cache_size = 0; // default

rosbag2_cpp::ConverterOptions converter_options{};
return open(storage_options, converter_options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ TEST_F(RecordFixture, record_end_to_end_test_with_zstd_file_compression) {
cmd << "ros2 bag record" <<
" --compression-mode file" <<
" --compression-format zstd" <<
" --max-cache-size 0" <<
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests assume the cache size to be 0 [disk write always] and therefore this flag is now required for them to pass.

" --output " << root_bag_path_.string() <<
" " << topic_name;

Expand Down Expand Up @@ -117,7 +118,7 @@ TEST_F(RecordFixture, record_end_to_end_test) {
wrong_message->string_value = "wrong_content";

auto process_handle = start_execution(
"ros2 bag record --output " + root_bag_path_.string() + " /test_topic");
"ros2 bag record --max-cache-size 0 --output " + root_bag_path_.string() + " /test_topic");
wait_for_db();

pub_man_.add_publisher("/test_topic", message, expected_test_messages);
Expand Down