Skip to content

RUST-54 Support for OP_COMPRESSED #476

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

Merged
merged 40 commits into from
Oct 7, 2021

Conversation

awitten1
Copy link
Contributor

@awitten1 awitten1 commented Sep 29, 2021

Provides support for reading and writing OP_COMPRESSED as specified here. Includes support for snappy, zstd, and zlib.

The following is a snippet of the server logs when running cargo test compression::test::ping_server_with_zlib_compression, which connects to the default server (see get_default_server in src/test/mod.rs) and sends a ping (see src/compression/test.rs). I have highlighted the most relevant parts. (The exact output will depend on the server version).

Screen Shot 2021-09-29 at 10 31 04 AM

The following is a snippet of the server logs where the server has been given the flag --networkMessageCompressors=snappy,zstd (prohibiting usage of zlib) and running cargo test compression::test::ping_server_with_all_compressor, which lists all compressors as usable on the client side. The client compresses with snappy, as it should, because snappy is preferred over zstd, and zlib is not usable.

Screen Shot 2021-10-01 at 10 45 23 AM

@awitten1
Copy link
Contributor Author

awitten1 commented Sep 29, 2021

Not sure what went wrong with evergreen. For now I submitted a patch here.. Seems to be working now.

Copy link
Contributor

@patrickfreed patrickfreed left a comment

Choose a reason for hiding this comment

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

Overall looks really good! I have some API suggestions but otherwise mostly minor comments.

Err(Error::new(
ErrorKind::InvalidResponse {
message: format!(
"Invalid op code, expected {} or {} and got {}",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this could cause a confusing error message if the server sends a compressed message but the client doesn't have the feature flags enabled ("Invalid op code, expected <Message> or <Compressed> and got <Compressed>").

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. It is confusing because if none of the feature flags are enabled then the client is not expecting OpCode::Compressed, so we shouldn't say that it is expecting OpCode::Compressed. Although the server will never send compressed messages if none of the feature flags are enabled (because the server only sends compressed messages if we tell it we can parse them).

/// For compressors that take a level, use None to indicate the default level.
/// Requires one of zstd-compression, zlib-compression, or snappy-compression
/// feature flags.
pub enum Compressor {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think a lot of the feature flag annotations could be simplified by including Noop in this enum and unconditionally including the machinery elsewhere, relying on there being only a single enum value when none are enabled.

Alternatively, the entire compression module could be put behind a

#[cfg(any(
    feature = "zstd-compression",
    feature = "zlib-compression",
    feature = "snappy-compression"
))]

clause in src/lib.rs.

Copy link
Contributor

@abr-egn abr-egn left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@isabelatkinson isabelatkinson left a comment

Choose a reason for hiding this comment

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

looks good, just a few more comments!

@@ -263,8 +288,9 @@ impl Connection {
command: Command,
request_id: impl Into<Option<i32>>,
) -> Result<RawCommandResponse> {
let to_compress: bool = command.should_compress();
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need a type annotation here?

],
"zlibCompressionLevel": 9
}
"options": {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why were these removed -- was there an update to the spec tests that we pulled in here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason is that we only store compressors that are valid and enabled (via its corresponding feature flag). When these tests are run none of the feature flags are set, so none of these compressors get stored. As a result, when ClientOptions is deserialized, all these fields are empty. We probably want to also run these tests with the feature flags set.

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'll just disable these tests if not all of the feature flags are set. I didn't realize that we don't manually edit these.

@@ -0,0 +1,127 @@
// Tests OP_COMPRESSED. To actually test compression you need to look at
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the tests in this module actually being run in CI? I believe we'd need to update our evergreen config to enable the compression feature flags, from looking at the evergreen logs it doesn't look like these ones show up in the test output.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No they aren't being run right now. They only run if the feature flags are set. I was going to update the evergreen configs in a separate PR.

Copy link
Contributor

@patrickfreed patrickfreed left a comment

Choose a reason for hiding this comment

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

Looks really good! I only have a few more minor comments.

Copy link
Contributor

@patrickfreed patrickfreed left a comment

Choose a reason for hiding this comment

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

Code changes look good to me, but it looks like this branch needs to be rebased off of the latest changes from master.

@awitten1 awitten1 force-pushed the RUST-54_OP-COMPRESSED branch from b19f3d3 to de04ddb Compare October 7, 2021 15:02
@awitten1 awitten1 requested a review from patrickfreed October 7, 2021 15:03
Copy link
Contributor

@patrickfreed patrickfreed left a comment

Choose a reason for hiding this comment

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

LGTM, awesome job with this! 🎉

Copy link
Contributor

@abr-egn abr-egn left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@isabelatkinson isabelatkinson left a comment

Choose a reason for hiding this comment

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

lgtm, nice work!

@awitten1 awitten1 merged commit 5a0192c into mongodb:master Oct 7, 2021
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.

4 participants