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

[Compression - 6] Add Zstd file decompression implementation #230

Merged
merged 13 commits into from
Jan 3, 2020

Conversation

piraka9011
Copy link
Contributor

@piraka9011 piraka9011 commented Dec 10, 2019

Changes

  • Add zstd_decompressor header and source
  • Add a new unit test for decompression
    • Compress a file then decompresses it using the same format. Make sure original size is the same.

Dependencies

@zmichaels11 zmichaels11 force-pushed the compression/zstd-decompressor branch 3 times, most recently from 95f6c4e to 04698fb Compare December 13, 2019 17:18
@zmichaels11
Copy link
Contributor

@ros2/aws-oncall - please run this CI job
Gist: https://gist.githubusercontent.com/zmichaels11/8caa09c53ea15fc9b854eafe8eccc589/raw/f8650ffdf23ddc9842120ed4479a0c8462cf9749/ros2.repos
BUILD args: --packages-up-to rosbag2_compression
TEST args: --packages-select rosbag2_compression
Job: ci_launcher

@piraka9011
Copy link
Contributor Author

piraka9011 commented Dec 16, 2019

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

Anas Abou Allaban and others added 4 commits December 18, 2019 07:58
Signed-off-by: Anas Abou Allaban <allabana@amazon.com>
Signed-off-by: Zachary Michaels <zmichaels11@gmail.com>
Signed-off-by: Zachary Michaels <zmichaels11@gmail.com>
Signed-off-by: Zachary Michaels <zmichaels11@gmail.com>
@zmichaels11
Copy link
Contributor

@Karsten1987 this PR is ready for review

Signed-off-by: Zachary Michaels <zmichaels11@gmail.com>
Signed-off-by: Zachary Michaels <zmichaels11@gmail.com>
…fy it fails with bad input.

Signed-off-by: Zachary Michaels <zmichaels11@gmail.com>
Signed-off-by: Zachary Michaels <zmichaels11@gmail.com>
Signed-off-by: Zachary Michaels <zmichaels11@gmail.com>
* Add comments on why uniform initialization cannot be used

Signed-off-by: Zachary Michaels <zmichaels11@gmail.com>
Signed-off-by: Zachary Michaels <zmichaels11@gmail.com>
Signed-off-by: Zachary Michaels <zmichaels11@gmail.com>
Signed-off-by: Zachary Michaels <zmichaels11@gmail.com>
@zmichaels11
Copy link
Contributor

@Karsten1987 friendly ping requesting review

@zmichaels11 zmichaels11 merged commit 9e18969 into ros2:master Jan 3, 2020
Copy link
Collaborator

@Karsten1987 Karsten1987 left a comment

Choose a reason for hiding this comment

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

With compression and decompression being available with this, I would like to see a test which checks the validity of the compression. That is, a file being compressed and decompressed is byte equivalent with the initial file content.

Comment on lines +65 to +72
// Read in buffer, handling accordingly
const auto file_pointer = open_file(uri.c_str(), "rb");
if (file_pointer == nullptr) {
std::stringstream errmsg;
errmsg << "Failed to open file: \"" << uri << "\" for binary reading!";

throw std::runtime_error{errmsg.str()};
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could this check be done before getting the size of the uri?

std::vector<uint8_t> get_input_buffer(const std::string & uri)
{
// Get the file size
const auto compressed_buffer_length = rosbag2_storage::FilesystemHelper::get_file_size(uri);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should react here in case the returned filesize is 0 (aka the file is non-existing)

// the initializer list constructor instead.
std::vector<uint8_t> compressed_buffer(compressed_buffer_length);

const auto nRead = fread(
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: generally we don't have camelcase variable names in ROS2.

ROSBAG2_COMPRESSION_LOG_ERROR_STREAM("Bytes read !(" <<
nRead << ") != compressed_buffer_length (" << compressed_buffer_length <<
")!");
// An error indicator is set by fread, so the following check will throw.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment actually refers to line 90, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, the error log message on L84 exists to provide further information on an error from fread.

The comment on L87 is indicating that the code should throw at this state and that the check on L90 does the actual throw since fread may have set the error indicator for other reasons besides nRead != compressed_buffer_length.

}

const auto nWrite = fwrite(
output_buffer.data(), sizeof(uint8_t),
Copy link
Collaborator

Choose a reason for hiding this comment

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

what if output buffer is empty?

/**
* Checks if the frame content is valid.
*/
void check_frame_content(const size_t frame_content)
Copy link
Collaborator

Choose a reason for hiding this comment

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

given that we have throw_on_zstd_error I think this function could be renamed accordingly as it really does only throwing on error.

@zmichaels11 zmichaels11 deleted the compression/zstd-decompressor branch January 3, 2020 17:41
@zmichaels11
Copy link
Contributor

With compression and decompression being available with this, I would like to see a test which checks the validity of the compression. That is, a file being compressed and decompressed is byte equivalent with the initial file content.

There's a unit test for this:

TEST_F(CompressionHelperFixture, zstd_decompress_file_contents)

@zmichaels11
Copy link
Contributor

@Karsten1987 I'm opening a PR to address your comments: #245

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants