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

errors: protocol error refactor #1080

Merged
merged 25 commits into from
Oct 4, 2024

Conversation

muzarski
Copy link
Contributor

@muzarski muzarski commented Sep 25, 2024

ref: #519

QueryError::ProtocolError

In this PR we do a refactor of the QueryError::ProtocolError variant, which was represented simply as &'static str. In this PR, we create a new type ProtocolError which will represent all posible kinds of protocol errors. We simply replace all occurrences of QueryError::ProtocolError with a corresponding ProtocolError variant.

QueryError::InvalidMessage

This variant is no longer use after the fixes. Previously, this variant was constructed for some protocol errors due to limitations of the QueryError::ProtocolError variant type (&'static str, when String was needed). After introducing ProtocolError type, this is no longer an issue. This variant can be safely removed.

Pre-review checklist

  • I have split my patch into logically separate commits.
  • All commit messages clearly explain what they change and why.
  • [ ] I added relevant tests for new features and bug fixes.
  • All commits compile, pass static checks and pass test.
  • PR description sums up the changes and reasons why they should be introduced.
  • I have provided docstrings for the public items that I want to introduce.
  • [ ] I have adjusted the documentation in ./docs/source/.
  • I added appropriate Fixes: annotations to PR description.

@muzarski muzarski marked this pull request as draft September 25, 2024 10:55
@muzarski muzarski self-assigned this Sep 25, 2024
Copy link

github-actions bot commented Sep 25, 2024

cargo semver-checks detected some API incompatibilities in this PR.
Checked commit: 204f911

See the following report for details:

cargo semver-checks output
./scripts/semver-checks.sh --baseline-rev ea7c464bf1a3d10fadc1d67827dd17e1ee191b7d
+ cargo semver-checks -p scylla -p scylla-cql --baseline-rev ea7c464bf1a3d10fadc1d67827dd17e1ee191b7d
     Cloning ea7c464bf1a3d10fadc1d67827dd17e1ee191b7d
     Parsing scylla v0.14.0 (current)
      Parsed [  22.762s] (current)
     Parsing scylla v0.14.0 (baseline)
      Parsed [  20.625s] (baseline)
    Checking scylla v0.14.0 -> v0.14.0 (no change)
     Checked [   0.108s] 89 checks: 88 pass, 1 fail, 0 warn, 0 skip

--- failure enum_variant_missing: pub enum variant removed or renamed ---

Description:
A publicly-visible enum has at least one variant that is no longer available under its prior name. It may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.35.0/src/lints/enum_variant_missing.ron

Failed in:
  variant QueryError::InvalidMessage, previously in file /home/runner/work/scylla-rust-driver/scylla-rust-driver/target/semver-checks/git-ea7c464bf1a3d10fadc1d67827dd17e1ee191b7d/e6f2e7f1733f2bdab932241d6890de3ef2b96662/scylla/src/transport/errors.rs:71
  variant NewSessionError::InvalidMessage, previously in file /home/runner/work/scylla-rust-driver/scylla-rust-driver/target/semver-checks/git-ea7c464bf1a3d10fadc1d67827dd17e1ee191b7d/e6f2e7f1733f2bdab932241d6890de3ef2b96662/scylla/src/transport/errors.rs:208

     Summary semver requires new major version: 1 major and 0 minor checks failed
    Finished [  43.554s] scylla
     Parsing scylla-cql v0.3.0 (current)
      Parsed [  10.518s] (current)
     Parsing scylla-cql v0.3.0 (baseline)
      Parsed [  10.331s] (baseline)
    Checking scylla-cql v0.3.0 -> v0.3.0 (no change)
     Checked [   0.101s] 89 checks: 89 pass, 0 skip
     Summary no semver update required
    Finished [  21.009s] scylla-cql
make: *** [Makefile:61: semver-rev] Error 1

@github-actions github-actions bot added the semver-checks-breaking cargo-semver-checks reports that this PR introduces breaking API changes label Sep 25, 2024
@muzarski muzarski marked this pull request as ready for review September 25, 2024 11:06
@muzarski muzarski force-pushed the protocol-error-refactor branch from 09bc8ce to d75ef64 Compare September 26, 2024 10:40
@muzarski
Copy link
Contributor Author

Rebased on main

scylla/src/transport/errors.rs Outdated Show resolved Hide resolved
scylla/src/transport/errors.rs Show resolved Hide resolved
scylla/src/transport/connection.rs Outdated Show resolved Hide resolved
scylla/src/transport/connection.rs Outdated Show resolved Hide resolved
scylla/src/transport/errors.rs Outdated Show resolved Hide resolved
scylla/src/transport/topology.rs Outdated Show resolved Hide resolved
scylla/src/transport/errors.rs Outdated Show resolved Hide resolved
scylla/src/transport/errors.rs Outdated Show resolved Hide resolved
scylla/src/statement/prepared_statement.rs Outdated Show resolved Hide resolved
scylla/src/transport/retry_policy.rs Outdated Show resolved Hide resolved
scylla/src/transport/connection.rs Outdated Show resolved Hide resolved
scylla/src/transport/errors.rs Outdated Show resolved Hide resolved
Comment on lines 264 to 267
/// A protocol error appeared during cluster metadata fetch.
#[error("Cluster metadata fetch protocol error: {0}")]
Metadata(#[from] MetadataProtocolError),

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why this variant gets #[from] but others dont?

Copy link
Contributor Author

@muzarski muzarski Oct 3, 2024

Choose a reason for hiding this comment

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

Since I think it makes sense to do it for this variant. However, IMO it's not true for variants such as UnexpectedResponse(CqlResponseKind) - here, CqlResponseKind is not an error type itself, it's there only to provide more context. The error is that we received an unexpected response - I don't think From<CqlResponseKind> impl makes sense here.

scylla/src/transport/topology.rs Show resolved Hide resolved
scylla/src/transport/errors.rs Outdated Show resolved Hide resolved
scylla/src/transport/errors.rs Outdated Show resolved Hide resolved
scylla/src/transport/topology.rs Outdated Show resolved Hide resolved
@muzarski muzarski force-pushed the protocol-error-refactor branch 2 times, most recently from 92311fc to f2f43d9 Compare October 2, 2024 11:47
@muzarski
Copy link
Contributor Author

muzarski commented Oct 3, 2024

v2: addressed review comments

Most important change is that I removed Protocol infix from errors related to metadata (e.g. MetadataProtocolError -> MetadataError). I also moved MetadaError out of ProtocolError, directly under [Query/NS]Error.

wprzytula
wprzytula previously approved these changes Oct 3, 2024
scylla/src/transport/connection.rs Outdated Show resolved Hide resolved
scylla/src/transport/connection.rs Outdated Show resolved Hide resolved
scylla/src/transport/session.rs Outdated Show resolved Hide resolved
scylla/src/transport/session.rs Outdated Show resolved Hide resolved
scylla/src/transport/errors.rs Outdated Show resolved Hide resolved
In the following commits, we will be replacing
`QueryError::ProtocolError` variants usages with
QueryError::ProtocolErrorTyped. Once every usage of
QueryError::ProtocolError is replaced, we will remove this variant
and rename ProtocolErrorTyped to ProtocolError. ProtocolErrorTyped
is a temporary variant name.
Instead of converting keyspace strings to lowercase
(which implies an allocation), we can make use of a comparator
that does not allocate additional memory.
Added new error type: UseKeyspaceProtocolError and
a corresponding variant to ProtocolError.
Wrapped `SingleRowTypedError` returned during schema version
fetch. Previously, we would simply drop this error and provide
some custom error messages - which, in my opinion were not
really insightful.
Added a variant for nonfinished paging state in response
to unpaged query.
Previously, this would be a ProtocolError.
However, an empty plan received from LBP does not really
represent a protocol violation.
Added an error variant that corresponds to pk extraction
error. It indicates that prepared statement's metadata provided by
the server is invalid.
@muzarski muzarski force-pushed the protocol-error-refactor branch from f2f43d9 to 1c11070 Compare October 4, 2024 10:37
@muzarski
Copy link
Contributor Author

muzarski commented Oct 4, 2024

v2.1: addressed @Lorak-mmk comments

Replaced last QueryError::ProtocolError variant usages
with QueryError::ProtocolErrorTyped (via From impl).
This type represents an error that occurred
during cluster metadata fetch (peers and keyspaces).
From now on, the driver will only expect 'class' and
replication factor per dc options for NetworkTopologyStrategy.

If some other option is detected, an error is returned.
We removed last usages of this variant in previous commit.
We can finally get rid of yet another variant that stringified
errors.
@muzarski muzarski force-pushed the protocol-error-refactor branch from 1c11070 to 204f911 Compare October 4, 2024 10:44
@wprzytula wprzytula merged commit 2ac20a9 into scylladb:main Oct 4, 2024
11 checks passed
@wprzytula wprzytula mentioned this pull request Nov 14, 2024
@muzarski muzarski deleted the protocol-error-refactor branch December 19, 2024 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-checks-breaking cargo-semver-checks reports that this PR introduces breaking API changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants