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

Add protocol validation, rename mod features to table_features #454

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

zachschuermann
Copy link
Collaborator

@zachschuermann zachschuermann commented Nov 5, 2024

What changes are proposed in this pull request?

  1. Add Protocol validation (as soon as a Protocol is constructed via our visitor, do the following validation:)
    a. Check that table min reader/writer version <= kernel reader/writer version
    b. Fail if V2Checkpoint reader feature is enabled (since we don't yet implement it)
    c. Check that reader features and writer features are present for reader version 3 and writer version 7, respectively
  2. Add new VacuumProtocolCheck reader/writer feature (but this is allowed as reader feature since it's a noop so we trivially support it)
  3. Rename features module to table_features (less confusing with cargo's notion of features)

This PR affects the following public APIs

New error classes for invalid protocol and unsupported features. Add VacuumProtocolCheck reader/writer feature. Fields in Protocol are now private.

How was this change tested?

new ut

@zachschuermann zachschuermann self-assigned this Nov 5, 2024
@github-actions github-actions bot added the breaking-change Change that will require a version bump label Nov 5, 2024
Copy link

codecov bot commented Nov 5, 2024

Codecov Report

Attention: Patch coverage is 89.28571% with 15 lines in your changes missing coverage. Please review.

Project coverage is 78.20%. Comparing base (bd2ea9f) to head (3b7e1ea).

Files with missing lines Patch % Lines
kernel/src/actions/mod.rs 91.17% 8 Missing and 1 partial ⚠️
kernel/src/error.rs 50.00% 3 Missing ⚠️
ffi/src/lib.rs 0.00% 2 Missing ⚠️
kernel/src/table_features/mod.rs 92.30% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #454      +/-   ##
==========================================
+ Coverage   78.08%   78.20%   +0.11%     
==========================================
  Files          55       55              
  Lines       11605    11730     +125     
  Branches    11605    11730     +125     
==========================================
+ Hits         9062     9173     +111     
- Misses       2043     2056      +13     
- Partials      500      501       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -481,4 +555,66 @@ mod tests {
)]));
assert_eq!(schema, expected);
}

#[test]
fn test_validate_protocol() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would like to see the feature subset check get exercised. Would also like to see the min_reader_version == 1 or 2 get checked as well.


/// Check if reading a table with this protocol is supported. That is: does the kernel support
/// the specified protocol reader version and all enabled reader features?
// TODO: should this return result so we can say _why_ it isn't supported?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like yes?

Some(reader_features) if self.min_reader_version == 3 => {
let parsed_features: Result<HashSet<_>, _> = reader_features
.iter()
.map(|s| s.parse::<ReaderFeatures>())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe this is cleaner?

Suggested change
.map(|s| s.parse::<ReaderFeatures>())
.map(ReaderFeatures::from_str)

match &self.reader_features {
// check that all reader features are subset of supported
Some(reader_features) if self.min_reader_version == 3 => {
let parsed_features: Result<HashSet<_>, _> = reader_features
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it really an arbitrary Result? Or would this work?

Suggested change
let parsed_features: Result<HashSet<_>, _> = reader_features
let parsed_features: DeltaResult<HashSet<_>> = reader_features

}

impl Protocol {
pub fn new(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
pub fn new(
pub fn try_new(

Comment on lines +588 to +596
assert!(matches!(
Protocol::new(
min_reader_version,
min_writer_version,
reader_features,
writer_features
),
Err(Error::InvalidProtocol(_)),
));
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you aren't worried about the specific error, can also do:

Protocol::try_new(...).expect_err("invalid protocol")

Comment on lines +605 to +606
Some(vec![ReaderFeatures::V2Checkpoint.to_string()]),
Some(vec![ReaderFeatures::V2Checkpoint.to_string()]),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we anyway have a method now, maybe consider having it take:

reader_features: Option<impl` IntoIterator<Item = impl Into<String>>>,
writer_features: Option<impl` IntoIterator<Item = impl Into<String>>>,

... and then this code here simplifies to:

Suggested change
Some(vec![ReaderFeatures::V2Checkpoint.to_string()]),
Some(vec![ReaderFeatures::V2Checkpoint.to_string()]),
Some([&ReaderFeatures::V2Checkpoint]),
Some([&ReaderFeatures::V2Checkpoint]),

(again below)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Change that will require a version bump
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants