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

RUST-1306 Move Compression enum behind compression feature flags #1055

Merged
merged 3 commits into from
Mar 27, 2024

Conversation

isabelatkinson
Copy link
Contributor

No description provided.

@@ -872,15 +871,38 @@ tasks:
TOPOLOGY: sharded_cluster
- func: "run driver test suite"

- name: test-compression
- name: test-zstd-compression
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's not a ton of value in testing all of the compressors together IMO, and because the compressors list in the client options is considered in priority-order, separating these into different variants makes it easier to get full coverage of each compressor when running the test suite.

#[cfg(feature = "zlib-compression")]
use std::convert::TryInto;

pub(crate) mod compress;
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 broke this up into modules to minimize the amount of conditional compilation going on. Also removed a lot of the utility enums -- probably just personal preference but I found them to be more noisy than helpful. The actual (de)compression logic is the same.

#[allow(unused_mut)]
let mut compressors = vec![];

if *SNAPPY_COMPRESSION_ENABLED {
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 vars were removed from the config during the refactor (oops) so I don't think we were actually getting the compression test coverage we intended to. I'd like to move away from using environment variables in our test code to avoid situations like these where possible, so I just changed the logic to turn on compression unconditionally when a feature flag is set.

// compression behavior is tested by running the driver test suite with a compressor configured;
// this test just makes sure our setup is correct.
#[tokio::test]
async fn test_compression_enabled() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just adding a little bit of safeguarding to avoid accidentally not running tests with compression enabled in the future 🙂 I removed all of the other compression-related tests because they were either a) testing the functionality of our compression dependencies rather than our own code or b) just doing a round-trip.

@isabelatkinson isabelatkinson marked this pull request as ready for review March 26, 2024 16:28
@isabelatkinson isabelatkinson requested a review from abr-egn March 26, 2024 22:21
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! No re-review needed if you decide to update with a compression feature.

@@ -315,8 +320,11 @@ pub(crate) struct Handshaker {
/// given the same pool options, so it can be created at the time the Handshaker is created.
command: Command,

// This field is not read without a compression feature flag turned on.
#[allow(dead_code)]
#[cfg(any(
Copy link
Contributor

Choose a reason for hiding this comment

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

We could avoid having to repeat this list everywhere (and update it everywhere if we add a new compressor) by making the *-compression features enable a compression feature. Up to you if you think that's worthwhile.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the repetition is annoying. I think it's manageable enough for now that it doesn't feel worth adding a technically-public feature flag, but I would definitely consider that if we do more compression-related work in the future.

It'd be really nice if we could define some kind of #[compression] attribute that expanded to this conditional compilation expression, but I don't think that's possible after cursory investigation of proc macro capabilities.

@isabelatkinson isabelatkinson merged commit 4102f4a into mongodb:main Mar 27, 2024
7 of 9 checks passed
@isabelatkinson isabelatkinson deleted the compression-updates branch April 3, 2024 16:32
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.

2 participants